<template>
  <div class="edit-add-detail">
    <div class="crumbs">
      <Breadcrumb
        :breadcrumbOpt="breadcrumbOpt"
        svg-name="#icon-vehicle"
        @breadcrumb-click="handleClose"
      />
    </div>
    <div class="form-content">
      <el-form
        ref="formInfo"
        :model="parameter.bizReceipt"
        label-width="auto"
        label-position="right"
        :rules="rules"
      >
        <div class="rows">
          <div class="rows-left">
            <div class="rows-hr"></div>
          </div>
          <div class="rows-title">
            <div class="text-overflow">基本信息</div>
          </div>
        </div>
        <el-row :gutter="24">
          <el-col :span="8">
            <el-form-item label="收货公司" prop="matCompanyName">
              <el-select
                v-model="parameter.bizReceipt.matCompanyName"
                filterable
                style="width: 100%"
                placeholder="请选择收货公司"
                @change="changeContract"
              >
                <el-option
                  v-for="item in companyList"
                  :key="item.matCompanyId"
                  :label="item.matCompanyName"
                  :value="item.matCompanyId"
                >
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="订单编号选择" prop="purchaseOrderCode">
              <el-input
                v-model="parameter.bizReceipt.purchaseOrderCode"
                @focus="openOrder"
                prefix-icon="el-icon-search"
                placeholder="请选择订单"
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="发货公司" prop="vendorName">
              <el-input
                clearable
                v-model="parameter.bizReceipt.vendorName"
                placeholder="请输入发货公司"
              ></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="24">
          <el-col :span="8">
            <el-form-item label="发货人" prop="vendorUserName">
              <el-input
                clearable
                v-model="parameter.bizReceipt.vendorUserName"
                placeholder="请输入发货人"
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="联系方式" prop="vendorPhone">
              <el-input
                clearable
                type="number"
                v-model="parameter.bizReceipt.vendorPhone"
                placeholder="请输入联系方式"
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="发货时间" prop="arrivalDate">
              <el-date-picker
                v-model="parameter.bizReceipt.arrivalDate"
                type="datetime"
                value-format="yyyy-MM-dd HH:mm:ss"
                placeholder="请选择发货时间"
                style="width: 100%"
              />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="24"> </el-row>
        <el-row :gutter="24">
          <el-col
            :span="8"
            v-if="this.breadcrumbOpt[1].breadcrumbName === '编辑'"
          >
            <el-form-item label="发货单号" prop="arrivalCode">
              <el-input
                :readonly="true"
                v-model="parameter.bizReceipt.arrivalCode"
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="货物金额" prop="amount">
              <el-input
                :readonly="true"
                clearable
                v-model="parameter.bizReceipt.amount"
                placeholder="请输入货物金额"
              ></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <div class="rows">
          <div class="rows-left">
            <div class="rows-hr"></div>
          </div>
          <div class="rows-title">
            <div class="text-overflow">物料信息</div>
          </div>
          <el-button
            type="primary"
            @click="handleOpen"
            style="margin-left: 15px"
            icon="el-icon-plus"
            size="mini"
            >添加订单明细</el-button
          >
        </div>
        <el-table
          ref="singleTable"
          :data="parameter.detailList"
          style="width: 100%"
          highlight-current-row
          border
          size="small"
          :cell-style="{'text-align': 'center'}"
          :header-cell-style="{'text-align': 'center'}"
        >
          <el-table-column fixed type="index" width="55" label="序号" />
          <el-table-column
            label="企业物料编号"
            min-width="100"
            show-overflow-tooltip
            prop="matCode"
          >
          </el-table-column>
          <el-table-column
            label="平台物料编号"
            min-width="100"
            show-overflow-tooltip
            prop="matPlatcode"
          >
          </el-table-column>
          <el-table-column
            label="物料名称"
            min-width="120"
            show-overflow-tooltip
            prop="matName"
          >
          </el-table-column>
          <el-table-column
            label="物料牌号"
            min-width="100"
            show-overflow-tooltip
            prop="matMaterial"
          >
          </el-table-column>
          <el-table-column
            label="规格型号"
            min-width="120"
            show-overflow-tooltip
            prop="matSpec"
          >
          </el-table-column>
          <el-table-column
            label="计划编号"
            min-width="100"
            show-overflow-tooltip
            prop="planCode"
          >
          </el-table-column>
          <el-table-column label="计量单位" min-width="100" prop="matUnit">
          </el-table-column>
          <el-table-column label="发货数量" min-width="130" prop="matNum">
            <template slot-scope="scope">
              <el-input
                v-model="scope.row.matNum"
                type="number"
                :min="1"
                placeholder="请输入发货数量"
                @input="changeNum(scope.row)"
              ></el-input>
            </template>
          </el-table-column>
          <el-table-column label="税率(%)" min-width="110" prop="taxRate">
          </el-table-column>
          <el-table-column
            label="含税单价(元)"
            min-width="130"
            prop="taxInprice"
          >
          </el-table-column>
          <el-table-column
            label="含税金额(元)"
            min-width="130"
            prop="taxInvalue"
          >
          </el-table-column>
          <el-table-column
            label="不含税单价(元)"
            min-width="130"
            prop="price"
          >
          </el-table-column>
          <el-table-column
            label="不含税金额(元)"
            min-width="130"
            prop="amount"
          >
          </el-table-column>
          <el-table-column
            label="基础扩展"
            min-width="100"
            show-overflow-tooltip
            prop="matBaseExt"
          >
          </el-table-column>
          <el-table-column
            label="其他扩展"
            min-width="100"
            show-overflow-tooltip
            prop="matOtherExt"
          >
          </el-table-column>
          <el-table-column
            label="挂账时间"
            min-width="100"
            show-overflow-tooltip
            prop="pendingTime"
          >
          </el-table-column>
          <el-table-column
            label="送货地址"
            min-width="100"
            show-overflow-tooltip
            prop="unloadAddress"
          >
          </el-table-column>
          <el-table-column
            label="企业补充说明"
            min-width="120"
            prop="purNote"
            show-overflow-tooltip
          >
          </el-table-column>
          <el-table-column
            label="供货方补充说明"
            min-width="120"
            prop="vendorNote"
            show-overflow-tooltip
          >
          </el-table-column>
          <el-table-column
            fixed="right"
            align="right"
            width="90px"
            label="操作"
            :index="999"
          >
            <template slot-scope="scope">
              <el-button
                size="mini"
                type="danger"
                circle
                icon="el-icon-close"
                @click="delTable(scope.$index, scope.row)"
              />
            </template>
          </el-table-column>
        </el-table>
      </el-form>
    </div>
    <div slot="footer" class="footer">
      <el-button @click="handleClose">{{ $t('domestic.cancel') }}</el-button>
      <el-button type="primary" :loading="loading" @click="handleSave">{{
        $t('domestic.save')
      }}</el-button>
    </div>
    <!-- 选择订单 -->
    <el-dialog
      title="订单选择"
      :visible.sync="dialogVisible"
      width="70%"
      :modal-append-to-body="false"
      :before-close="handleDialogClose"
    >
      <div class="dialog-table-search">
        <el-form
          ref="form"
          label-width="auto"
          label-position="right "
          :inline="true"
          type="flex"
          justify="left"
        >
          <el-form-item label="订单编号">
            <el-input
              size="small"
              v-model="queryParams[0].value"
              clearable
              placeholder="请输入订单编号"
            ></el-input>
          </el-form-item>
          <el-form-item label="采购方">
            <el-input
              size="small"
              v-model="queryParams[1].value"
              clearable
              placeholder="请输入采购方"
            ></el-input>
          </el-form-item>
          <el-form-item label="">
            <el-button
              size="small"
              icon="el-icon-search"
              type="danger"
              class="btn btn-plus"
              @click="handleSearch"
            >
              搜索
            </el-button>
            <el-button
              size="small"
              icon="el-icon-refresh-right"
              class="btn btn-plus"
              @click="clearSearchForm"
            >
              重置
            </el-button>
          </el-form-item>
        </el-form>
      </div>
      <div class="dialog-table-single">
        <el-table
          ref="dialogTable"
          :data="dialogTableData"
          style="width: 100%"
          border
          @selection-change="handleSelectionChange"
        >
          <el-table-column align="center" type="selection" width="55">
          </el-table-column>
          <el-table-column align="center" prop="orderCode" label="订单编号">
          </el-table-column>
          <el-table-column align="center" prop="contractName" label="合同名称">
          </el-table-column>
          <el-table-column align="center" prop="vendorName" label="供货方">
          </el-table-column>
          <el-table-column align="center" prop="matCompanyName" label="采购方">
          </el-table-column>
          <el-table-column
            align="center"
            prop="orderCreatedate"
            label="订单时间"
          >
          </el-table-column>
          <el-table-column
            align="center"
            prop=""
            label="操作"
          >
          <template slot-scope="scope">
            <div>
              <el-button size="mini" @click="openDetails(scope.row)" type="primary">查看明细</el-button>
            </div>
          </template>
          </el-table-column>
        </el-table>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible = false"> 取 消 </el-button>
        <el-button type="primary" @click="handleDialogTableSubmit">
          确定
        </el-button>
      </span>
    </el-dialog>
    <!-- 订单明细 -->
    <el-dialog
      title="物料选择"
      :visible.sync="dialogVisibleDetial"
      width="70%"
      :before-close="handleDialogCloseDetial"
    >
      <div class="dialog-table-search">
        <el-form
          ref="form"
          label-width="auto"
          label-position="right "
          :inline="true"
          type="flex"
          justify="left"
        >
          <el-form-item label="物料名称">
            <el-input
              size="small"
              v-model="queryParamsDetial[0].value"
              clearable
              placeholder="物料名称"
            ></el-input>
          </el-form-item>
          <el-form-item label="">
            <el-button
              size="small"
              icon="el-icon-search"
              type="danger"
              class="btn btn-plus"
              @click="handleSearchDetial"
            >
              搜索
            </el-button>
            <el-button
              size="small"
              icon="el-icon-refresh-right"
              class="btn btn-plus"
              @click="clearSearchFormDetial"
            >
              重置
            </el-button>
          </el-form-item>
        </el-form>
      </div>
      <div class="dialog-table">
        <el-table
          ref="dialogTableDetial"
          :data="dialogTableDataDetial"
          border
          row-key="id"
          style="width: 100%"
        >
          <el-table-column align="center" type="selection" width="55">
          </el-table-column>
          <el-table-column
            label="企业物料编号"
            min-width="100"
            show-overflow-tooltip
            prop="matCode"
          >
          </el-table-column>
          <el-table-column
            label="平台物料编号"
            min-width="100"
            show-overflow-tooltip
            prop="matPlatcode"
          >
          </el-table-column>
          <el-table-column
            label="物料名称"
            min-width="100"
            show-overflow-tooltip
            prop="matName"
          >
          </el-table-column>
          <el-table-column
            label="物料牌号"
            min-width="100"
            show-overflow-tooltip
            prop="matMaterial"
          >
          </el-table-column>
          <el-table-column
            label="规格型号"
            min-width="100"
            show-overflow-tooltip
            prop="matSpec"
          >
          </el-table-column>
          <el-table-column
            label="计划编号"
            min-width="100"
            show-overflow-tooltip
            prop="planCode"
          >
          </el-table-column>
          <el-table-column align="center" show-overflow-tooltip prop="matUnit" label="计量单位">
          </el-table-column>
          <el-table-column align="center" show-overflow-tooltip prop="matNum" label="数量">
          </el-table-column>
          <el-table-column
            align="center"
            min-width="110"
            show-overflow-tooltip
            prop="orderPrice"
            label="不含税单价"
          >
          </el-table-column>
          <el-table-column
            align="center"
            show-overflow-tooltip
            min-width="110"
            prop="orderAmount"
            label="不含税金额"
          >
          </el-table-column>
          <el-table-column align="center" show-overflow-tooltip min-width="100" prop="taxInprice" label="含税单价">
          </el-table-column>
          <el-table-column align="center" show-overflow-tooltip min-width="100" prop="taxInvalue" label="含税金额">
          </el-table-column>
          <el-table-column align="center" show-overflow-tooltip min-width="100" prop="taxRate" label="税率">
          </el-table-column>
          <el-table-column align="center" show-overflow-tooltip min-width="100" prop="taxValue" label="税额">
          </el-table-column>
        </el-table>
      </div>
      <!-- <div class="dialog-table-page">
        <el-pagination
          ref="paginationPanel"
          background
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :current-page="params.pageBean.page"
          :page-sizes="[20, 30, 40, 50]"
          :page-size="params.pageBean.pageSize"
          layout="total, sizes, prev, pager, next, jumper"
          :total="params.pageBean.total"
        >
        </el-pagination>
      </div> -->
      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogVisibleDetial = false"> 取 消 </el-button>
        <el-button type="primary" @click="handleDialogTableSubmitDetial">
          确 定
        </el-button>
      </span>
    </el-dialog>
    <!-- 订单明细 -->
    <detailsDialog ref="details"/>
  </div>
</template>

<script>
import Breadcrumb from '@/components/Breadcrumb/index.vue'
import salesOrder from '@/api/BasicDataManagement/salesOrder.js'
import detailsDialog from './detailsDialog.vue';
export default {
  name: 'shipmentsAddDialog',
  components: {Breadcrumb,detailsDialog},
  props: {
    editData: Object,
  },
  data() {
    return {
      centralizedData: [
        {name: '是', id: 1},
        {name: '否', id: 0},
      ],
      breadcrumbOpt: [{breadcrumbName: '采购发货'}, {breadcrumbName: '新增'}],
      rules: {
        matCompanyName: [
          {
            required: true,
            message: '请输入收货公司',
            trigger: 'blur',
          },
        ],
        contractName: [
          {
            required: true,
            message: '请输入合同名称',
            trigger: 'blur',
          },
        ],
        vendorName: [
          {
            required: true,
            message: '请输入发货公司',
            trigger: 'blur',
          },
        ],
        vendorUserName: [
          {
            required: true,
            message: '请输入发货人',
            trigger: 'blur',
          },
        ],
        vendorPhone: [
          {
            required: true,
            message: '请输入联系电话',
            trigger: 'blur',
          },
          {
            pattern: /^1[3456789]\d{9}$/,
            message: '手机号码格式不正确',
            trigger: 'blur',
          },
        ],
        arrivalDate: [
          {
            required: true,
            message: '请选择发货时间',
            trigger: 'blur',
          },
        ],
        purchaseOrderCode: [
          {
            required: true,
            message: '请选择订单',
            trigger: 'blur',
          },
        ],
      },
      parameter: {
        bizReceipt: {
          purchaseOrderId: '',
          vendorName: '',
          vendorId: '',
          vendorCode: '',
          purchaseOrderCode: '',
          matCompanyName: '',
          matCompanyId: '',
          matCompanyCode: '',
          amount: 0,
          arrivalDate:'',
          vendorUserName:'',
          vendorPhone:''
        },
        detailList: [],
      },
      dialogVisibleDetial: false,
      dialogVisible: false,
      loading: false,
      dialogTableDataDetial: [],
      dialogTableData: [],
      params: {
        pageBean: {
          page: 1,
          pageSize: 20,
          total: 0,
        },
      },
      queryParams: [
        {
          group: 'main',
          operation: 'LIKE',
          parentGroup: '',
          property: 'orderCode',
          relation: 'AND',
          value: '',
        },
        {
          group: 'main',
          operation: 'LIKE',
          parentGroup: '',
          property: 'matCompanyName',
          relation: 'AND',
          value: '',
        },
        {
          group: 'main',
          operation: 'EQUAL',
          parentGroup: '',
          property: 'matCompanyId',
          relation: 'AND',
          value: '',
        },
      ],
      queryParamsDetial: [
        {
          group: 'main',
          operation: 'LIKE',
          parentGroup: '',
          property: 'matName',
          relation: 'AND',
          value: '',
        },
      ],
      selectObj: {},
      oldDetailslist: [],
      orderList: [],
      vendorId: '',
      companyList: [],
    }
  },
  created() {
    this.addModifyBtn()
    let userDetail = JSON.parse(sessionStorage.getItem('currentUserDetail'))
    let {fullname, userId, mobile} = userDetail.user
    this.parameter.bizReceipt.vendorUserName = fullname
    this.parameter.bizReceipt.vendorUserId = userId
    this.parameter.bizReceipt.vendorPhone = mobile
    this.vendorId = userDetail.org[0].orgId
    this.parameter.bizReceipt.vendorName = userDetail.org[0].orgName
    this.parameter.bizReceipt.vendorCode = userDetail.org[0].orgCode
    this.parameter.bizReceipt.vendorId = userDetail.org[0].orgId
    let moment = require('moment')
    this.parameter.bizReceipt.arrivalDate = moment().format('YYYY-MM-DD HH:mm:ss')
    this.getTableData()
    this.getMatCompany()
  },
  watch: {
    'parameter.detailList': {
      handler: function (newUser, oldUser) {
        this.parameter.bizReceipt.amount = 0
        let amount = 0
        newUser.forEach((item) => {
          amount += Number(item.taxInvalue)
        })
        this.parameter.bizReceipt.amount = amount.toFixed(2)
      },
      deep: true,
    },
  },
  mounted() {},
  methods: {
    getMatCompany() {
      let params = {
        querys: [],
        pageBean: {
          page: -1,
          pageSize: -1,
        },
      }
      params.querys.push(
        {
          group: 'main',
          operation: 'EQUAL',
          parentGroup: '',
          property: 'status',
          relation: 'AND',
          value: 3,
        },
        {
          group: 'main',
          operation: 'EQUAL',
          parentGroup: '',
          property: 'vendorId',
          relation: 'AND',
          value: this.vendorId,
        }
      )
      this.$http
        .post('${portal}/bizPurchaseOrder/v1/pageMatCompanyGroup', params)
        .then((res) => {
          if (res.data.state) {
            this.companyList = res.data.value.rows
          }
        })
    },
    changeContract(res) {
      this.companyList.forEach((item) => {
        if (item.matCompanyId === res) {
          this.parameter.bizReceipt.matCompanyId = item.matCompanyId
          this.parameter.bizReceipt.matCompanyName = item.matCompanyName
          this.parameter.bizReceipt.matCompanyCode = item.matCompanyCode
        }
      })
      this.queryParams[2].value = res
    },
    selectOne(row) {
      this.$http.post('${portal}/arrival/v1/selectOne?id='+row.id).then(res=>{
        this.parameter = res.data.value
        if (!this.parameter.detailList) {
          this.parameter.detailList = []
        } else {
          this.oldDetailslist = JSON.parse(
            JSON.stringify(this.parameter.detailList)
          )
          this.parameter.detailList.forEach((item) => {
            item.TaxPrice = item.transactionPrice / item.num
          })
        }
      })
    },
    handleSelectionChange(val) {
      this.orderList = val
      console.log(val)
    },
    getTableData() {
      this.params.querys = [
        {
          group: 'main',
          operation: 'EQUAL',
          parentGroup: '',
          property: 'status',
          relation: 'AND',
          value: 3,
        },
        {
          group: 'main',
          operation: 'EQUAL',
          parentGroup: '',
          property: 'vendorId',
          relation: 'AND',
          value: this.vendorId,
        },
      ]
      this.params.sorter = []
      if (this.queryParams[0].value) {
        this.params.querys.push(this.queryParams[0])
      }
      if (this.queryParams[1].value) {
        this.params.querys.push(this.queryParams[1])
      }
      if (this.queryParams[2].value) {
        this.params.querys.push(this.queryParams[2])
      }
      salesOrder.querycCntractDetails(this.params).then((res) => {
        this.dialogTableData = res.data.value.rows
      })
    },
    getTableDataDetial() {
      let ids = this.orderList.map((item) => {
        return item.id
      })
      let params = {
        querys: [],
        pageBean: {
          page: -1,
          pageSize: -1,
        },
      }
      if (this.queryParamsDetial[0].value) {
        params.querys.push(this.queryParamsDetial[0])
      }
      params.querys.push({
        group: 'main',
        operation: 'IN',
        parentGroup: '',
        property: 'orderId',
        relation: 'AND',
        value: ids,
      })
      this.$http
        .post('${portal}/bizPurchaseOrderDetail/v1/page', params)
        .then((res) => {
          if (res.data.state) {
            this.dialogTableDataDetial = res.data.value.rows
            this.$nextTick(() => {
              if (this.parameter.detailList.length != 0) {
                this.dialogTableDataDetial.forEach((item) => {
                  this.parameter.detailList.forEach((val) => {
                    if (item.planCode == val.planCode) {
                      this.$refs.dialogTableDetial.toggleRowSelection(
                        item,
                        true
                      )
                    }
                  })
                })
              }
            })
          }
        })
    },
    clearable() {
      this.parameter.bizReceipt.purchaseOrderId = ''
    },
    handleSearch() {
      this.getTableData()
    },
    handleSearchDetial() {
      this.getTableDataDetial()
    },
    handleOpen() {
      if (this.parameter.bizReceipt.matCompanyName == '') {
        this.$message.error('请选择收货公司')
        return
      }
      if (this.parameter.bizReceipt.purchaseOrderId == '') {
        this.$message.error('请选择订单')
        return
      }
      this.dialogVisibleDetial = true

      console.log(this.parameter.detailList, '333333333333')
      this.getTableDataDetial()
    },
    clearSearchFormDetial() {
      this.queryParamsDetial[0].value = ''
      this.getTableDataDetial()
    },
    clearSearchForm() {
      this.queryParams[0].value = ''
      this.queryParams[1].value = ''
      this.queryParams[2].value = this.parameter.bizReceipt.vendorId
      this.getTableData()
    },
    handleDialogTableSubmit() {
      this.parameter.bizReceipt.purchaseOrderCode = this.orderList
        .map((item) => {
          return item.orderCode
        })
        .join(',')
      this.parameter.bizReceipt.purchaseOrderId = this.orderList
        .map((item) => {
          return item.id
        })
        .join(',')
      this.dialogVisible = false
      this.$nextTick(() => {
        this.$refs.formInfo.clearValidate('purchaseOrderCode')
      })
    },
    handleDialogTableSubmitDetial() {
      let selection = this.$refs.dialogTableDetial.selection
      if (selection) {
        selection.forEach((item) => {
          item.num = ''
          delete item['id']
        })
      }
      let taxsum = 0
      this.parameter.detailList = selection
      this.parameter.detailList.forEach((item) => {
        item.purchaseOrderDetailId = item.purchasingApplicationDetailId
        item.purchaseOrderId = item.orderId
        item.arrivalNum = item.matNum
        item.price = item.orderPrice
        item.amount = item.orderAmount
        item.taxRate = item.taxRate ? item.taxRate : 0
        item.TaxPrice = item.taxInprice ? item.taxInprice : 0
        item.transactionPrice = item.taxInvalue ? item.taxInvalue : 0
        item.transactionPrice = (item.matNum * item.TaxPrice).toFixed(2)
        if (item.transactionPrice != null) {
          taxsum = taxsum + Number(item.transactionPrice)
        }
        this.parameter.bizReceipt.amount = taxsum
      })
      this.dialogVisibleDetial = false
    },
    handleDialogClose(done) {
      done()
    },
    handleDialogCloseDetial(done) {
      done()
    },
    changeNum(data) {
      console.log(data)
      let taxsum = 0
      data.arrivalNum =data.matNum
      data.taxInvalue = (Number(data.matNum) * data.taxInprice).toFixed(2)
      data.amount = (Number(data.matNum) * data.price).toFixed(2)
      this.parameter.detailList.forEach((item) => {
        taxsum += Number(item.taxInvalue)
      })
      this.parameter.bizReceipt.amount = taxsum
      console.log(this.parameter)
    },
    openDetails(row){
      this.$refs.details.handleOpen(row)
    },
    //列表删除行
    addTable() {
      this.getTableDataDetial()
      this.dialogVisibleDetial = true
    },
    //列表删除行
    delTable(index, row) {
      this.parameter.detailList.splice(index, 1)
      let taxsum = 0
      this.parameter.detailList.forEach((item) => {
        taxsum += Number(item.taxInvalue)
      })
      console.log(this.parameter.detailList, 'this.parameter.detailList')
      this.$forceUpdate()
      // if (row.id) {
      //   this.parameter.deleteDetailsId.push(row.id)
      // }
    },
    //编辑
    addModifyBtn() {
      if (this.$route.query.editRows) {
        this.breadcrumbOpt[1].breadcrumbName = '编辑'
        this.modifychoData(this.$route.query.editRows)
      } else {
        this.breadcrumbOpt[1].breadcrumbName = '新增'
      }
    },
    //获取修改回显数据
    modifychoData(val) {
      this.$http.post('${portal}/arrival/v1/selectOne?id='+val.id).then(res=>{
        console.log(res)
        this.parameter.bizReceipt = res.data.value
        this.parameter.detailList = res.data.value.detailList
        delete this.parameter.bizReceipt.detailList
        if (!this.parameter.detailList) {
          this.parameter.detailList = []
        } else {
          this.parameter.detailList.forEach((item) => {
            item.matNum = item.arrivalNum
            item.TaxPrice = item.transactionPrice / item.num
          })
        }
        console.log(this.parameter.bizReceipt, 'this.parameter.bizReceipt')
      })
    },
    openOrder() {
      if(this.parameter.bizReceipt.matCompanyName==''){
        this.$message.error('请选择收货公司')
        return
      }else{
        this.dialogVisible = true
        this.getTableData()
      }
    },
    // 关闭//面包屑点击
    handleClose() {
      if (this.breadcrumbOpt[1].breadcrumbName === '编辑') {
        this.$router.push({
          name: 'shipmentsSales',
          params: {
            pageBean: this.$route.query.pageBean,
          },
        })
      } else {
        this.$router.push({
          name: 'shipmentsSales',
        })
      }
      this.parameter = {}
    },
    // 保存
    handleSave() {
      this.$refs.formInfo.validate((valid) => {
        if (valid) {
          this.loading = true
          let toDelete = []
          this.oldDetailslist.forEach((a) => {
            let found = false
            this.parameter.detailList.forEach((item) => {
              if (item.id && item.id == a.id) {
                found = true
              }
            })
            if (!found) {
              toDelete.push(a.id)
            }
          })
          toDelete = toDelete.join(',')
          let form = {}
          form = this.parameter.bizReceipt
          form.detailList = this.parameter.detailList
          this.$http.post('${portal}/arrival/v1/save',form).then(res=>{
            this.loading = false
            if (res.data.state) {
              this.$message.success('保存成功！')
              this.$router.go(-1)
            }
          })
        }
      })
    },
    handleCurrentChange(page) {
      this.params.pageBean = {...this.params.pageBean, page}
      this.getTableDataDetial()
    },
    handleSizeChange(pageSize) {
      this.params.pageBean = {...this.params.pageBean, pageSize}
      this.getTableDataDetial()
    },
  },
}
</script>

<style lang="scss" scoped>
// /deep/.el-row {
//   padding: 0 100px;
// }

.dialog-table-page {
  height: 50px;
  padding: 0 20px;
  margin: 10px 0 0 0;
  border-radius: 8px 8px 8px 8px;
  background-color: #fff;
  box-sizing: border-box;
  transition: height 0.3s linear;
  display: flex;
  justify-content: flex-end;
  align-items: center;
}
.rows {
  display: flex;
  align-items: center;
  border-bottom: 1px solid #ebebeb;
  margin-bottom: 16px;
  padding: 10px 0;
  .rows-left {
    margin-right: 10px;
    .rows-hr {
      width: 3px;
      height: 18px;
      background-color: #0e6eff;
      border-radius: 2px;
    }
  }
  .rows-title {
    .text-overflow {
      width: 100%;
      font-size: 16px;
    }
  }
}
</style>
