<template>
  <div>
    <zj-form-container ref="formRef" :form-data="formData" :form-rules="formRules">
      <zj-form-module title="调拨单" :form-data="formData" :form-items="formItems" label-width="100px" :column="3" />
      <zj-form-module title="调拨单明细" :form-items="detailData" label-width="0" :column="3" />
      <zj-form-module
        v-if="moduleType === 2"
        style="height: 100%;"
        title="物流费用"
        :form-items="formLogisticsData"
        label-width="0"
        :column="3"
      />
      <zj-form-module
        v-if="moduleType === 3"
        title="审核信息"
        :form-data="formData"
        :form-items="formExamine"
        label-width="100px"
        :column="3"
      />
    </zj-form-container>
    <el-dialog title="添加产品" :visible.sync="visible" width="60%" :append-to-body="true" @close="visible = false">
      <div style="height: 600px">
        <template-page
          ref="pageRef"
          style="height: 100%"
          :get-list="getList"
          :column-parsing="columnParsing"
          :table-attributes="tableAttributes"
          :table-events="tableEvents"
        />
      </div>
      <span slot="footer">
        <el-button type="primary" @click="handleAddData">提交</el-button>
      </span>
    </el-dialog>
    <!-- 新增 -->
    <div v-if="!comDisabled">
      <template v-if="moduleType === 1">
        <el-button type="primary" size="mini" @click="onSubmit('WAIT')">提交</el-button>
        <!-- <el-button size="mini" @click="onSubmit('SAVE')">保存</el-button> -->
      </template>
      <template v-else>
        <el-button type="primary" size="mini" @click="onSubmit">编辑</el-button>
      </template>
      <el-button size="mini" @click="onReset">重置</el-button>
    </div>
    <!-- 审核 /详情-->
    <div v-if="moduleType === 3 || moduleType === 2">
      <el-button v-if="moduleType === 3" type="primary" size="mini" @click="onExamine('OK')">同意</el-button>
      <el-button v-if="formData.status === 'OK' && $checkBtnRole('examine', $route.meta.roles)" size="mini" @click="onInvoice('WAIT')">反审</el-button>
    </div>
  </div>
</template>

<script>
import TemplatePage from '@/components/template/template-page-1.vue'
import { getcustomerFrontList } from '@/api/stock'
import { getListCostBillV2 } from '@/api/logisticsBill'

import { debounce } from '@/utils/common'

import { getStagecustomerListV2, getDealerListV2 } from '@/api/basic_data/dealer'
import {
  addCustomerTransfer,
  updateCustomerTransfer,
  getCustomerTransferDetail,
  examineCustomerTransfer,
  setNeExamine
} from '@/api/transferOrder'
import { mapGetters } from 'vuex'

export default {
  components: { TemplatePage },
  props: {
    edit: {
      type: Boolean,
      default: false
    },
    detailsId: {
      type: String,
      default: null
    },
    moduleType: {
      type: Number,
      default: null
    }
  },
  data() {
    return {
      visible: false,
      // 表格属性
      tableAttributes: {
        // 启用勾选列
        selectColumn: true,
        selectable: this.selectable
      }, // 关闭新增弹窗

      // 表格事件
      tableEvents: {
        'selection-change': this.selectionChange
      },
      itemTableEvents: { 'selection-change': this.itemSelectionChange },
      defaultTableAttributes: {

        border: true,
        headerCellClassName: 'headerRowColor',
        size: 'mini',
        'summary-method': this.$getSummaries,
        'show-summary': true
      },
      recordSelected: [],
      formData: {
        customerNumber: '',
        customerName: '',
        transferTime: '',
        createBy: '',
        transferCustomerNumber: '',
        transferCustomerName: '',
        stockType: '',
        createTime: '',
        notes: ''
      },
      formRules: {
        customerNumber: [{ required: true, message: '请输入', trigger: 'blur' }],
        customerName: [{ required: true, message: '请输入', trigger: 'blur' }],
        transferTime: [{ required: true, message: '请选择', trigger: 'change' }],
        transferCustomerNumber: [{ required: true, message: '请输入', trigger: 'blur' }],
        transferCustomerName: [{ required: true, message: '请选择', trigger: 'change' }],
        stockType: [{ required: true, message: '请输入', trigger: 'blur' }]
      },
      fileType: ['word', 'excel', 'ppt', 'pdf'],
      fileList: [],
      fileList2: [],
      srcList: [],
      dict: [],
      mainContractList: [],
      serviceProviderList: [],
      filetype: [],
      authList: [],
      selectData: [],
      itemRecordSelected: [],
      sonCustomerList: [],
      logisticsData: [],
      sonCustomerNumberList: [],
      sonCustomerNameList: [],
      setDisabled: {
        disabledDate: time => {
          return time.getTime() < new Date() - 24 * 3600 * 1000
        }
      }
    }
  },
  computed: {
    ...mapGetters(['customerNumber', 'customerName']),
    comDisabled() {
      // 禁止
      return !!~[2, 3].indexOf(this.moduleType || 1)
    },
    formItems() {
      return [
        {
          name: 'el-input',
          md: 6,
          attributes: { disabled: true, placeholder: '请输入' },
          formItemAttributes: { label: '商家编号', prop: 'customerNumber' }
        },
        {
          name: 'el-input',
          md: 6,
          attributes: { disabled: true, placeholder: '请输入' },
          formItemAttributes: { label: '商家名称', prop: 'customerName' }
        },
        {
          name: 'el-date-picker',
          md: 6,
          attributes: {
            type: 'datetime',
            style: { width: '100%' },
            placeholder: '选择日期时间',
            valueFormat: 'yyyy-MM-dd HH:mm:ss',
            disabled: this.comDisabled,
            pickerOptions: this.setDisabled
          },
          formItemAttributes: { label: '调整日期', prop: 'transferTime' }
        },
        {
          name: 'el-input',
          md: 6,
          attributes: { disabled: true, placeholder: '系统自动生成' },
          formItemAttributes: { label: '制单人', prop: 'createBy' }
        },
        {
          name: 'el-select',
          options: this.sonCustomerNumberList,
          events: {
            change: e => this.handleChange(e, 'transferCustomerNumber')
          },
          md: 6,
          attributes: {
            clearable: true,
            filterable: true,
            disabled: this.comDisabled
          },
          formItemAttributes: { label: '商家编号', prop: 'transferCustomerNumber' }
        },
        {
          name: 'el-select',
          options: this.sonCustomerNameList,
          md: 6,
          events: {
            change: e => this.handleChange(e, 'transferCustomerName')
          },
          attributes: {
            clearable: true,
            filterable: true,
            disabled: this.comDisabled
          },
          formItemAttributes: { label: '商家名称', prop: 'transferCustomerName' }
        },
        {
          name: 'el-select',
          md: 6,
          options: [
            { label: '嘉贤前置仓', value: 'JIAXIAN' }
            // { label: '商家仓', value: 'SHANGJIA' }
          ],
          attributes: { disabled: this.comDisabled, placeholder: '请输入' },
          formItemAttributes: { label: '调拨仓库', prop: 'stockType' }
        },
        {
          name: 'el-input',
          md: 6,
          attributes: { disabled: true, placeholder: '系统自动生成' },
          formItemAttributes: { label: '制单时间', prop: 'createTime' }
        },
        {
          name: 'el-input',
          md: 24,
          attributes: { type: 'textarea', style: { width: '100%' }, disabled: this.comDisabled, placeholder: '请输入' },
          formItemAttributes: { label: '备注', prop: 'notes' }
        }
      ]
    },
    formExamine() {
      return [
        {
          name: 'el-input',
          md: 6,
          attributes: { disabled: true },
          formItemAttributes: { label: '审核人', prop: 'approvalName' }
        },
        {
          name: 'el-input',
          md: 6,
          attributes: { disabled: true },
          formItemAttributes: { label: '审核时间', prop: 'approvalTime' }
        },
        {
          name: 'el-input',
          md: 24,
          attributes: { type: 'textarea', style: { width: '100%' }, placeholder: '请输入' },
          formItemAttributes: { label: '备注', prop: 'approvalRemark' }
        }
      ]
    },
    columns() {
      return [
        {
          columnAttributes: {
            label: '产品名称',
            prop: 'materialName'
          }
        },
        {
          columnAttributes: {
            label: '产品编码',
            prop: 'materialOldNumber'
          }
        },
        {
          columnAttributes: {
            label: '规格型号',
            prop: 'specification',
            width: 300
          }
        },
        ...(() => {
          if (~[1].indexOf(this.moduleType)) {
            return [
              {
                columnAttributes: {
                  label: '可调拨库存数',
                  prop: 'frontStockNum'
                }
              }
            ]
          }
          return []
        })(),

        {
          columnAttributes: {
            label: '调拨数量',
            prop: 'qty'
          },
          render: (h, { row, index }) => {
            return (
              <div style='margin:0 20px'>
                <el-input
                  type='number'
                  disabled={this.comDisabled}
                  value={row.qty}
                  // onInput={e => (row.qty = e)}
                  onInput={value => {
                    row.qty = value
                    this.debounceChange(value, index)
                  }}
                  placeholder='调拨数量'
                  size='mini'
                ></el-input>
              </div>
            )
          }
        },
        {
          columnAttributes: {
            label: '备注',
            prop: 'notes'
          },
          render: (h, { row }) => {
            return (
              <el-input
                type='text'
                value={row.notes}
                disabled={this.comDisabled}
                onInput={e => (row.notes = e)}
                placeholder='备注'
                size='mini'
              ></el-input>
            )
          }
        },
        {
          columnAttributes: {
            label: '调拨仓库',
            prop: 'stockName'
          }
        },
        {
          columnAttributes: {
            label: '操作',
            prop: ''
          },
          render: (h, { index }) => {
            return (
              <div>
                {!this.comDisabled ? (
                  <el-button
                    type='text'
                    size='default'
                    onClick={() => {
                      this.handleDel(index)
                    }}
                  >
                    删除
                  </el-button>
                ) : null}
              </div>
            )
          }
        }
      ]
    },
    detailData() {
      return [
        ...[
          !this.comDisabled
            ? {
              name: 'slot-component',
              md: 24,
              attributes: { disabled: false },
              formItemAttributes: { label: '', prop: '' },
              render: () => {
                return (
                  <div>
                    <el-button
                      size='mini'
                      onClick={() => {
                        this.visible = true
                        this.recordSelected = []
                      }}
                    >
                        添加
                    </el-button>
                    <el-button size='mini' onClick={() => this.handleAllDel()}>
                        删除
                    </el-button>
                  </div>
                )
              }
            }
            : {}
        ],
        {
          name: 'slot-component',
          md: 24,
          attributes: { disabled: false },
          formItemAttributes: { label: '', prop: '' },
          render: (h, { props }) => {
            var { value } = props
            return (
              <zj-table
                isDrop={true}
                columns={this.columns}
                tableData={this.selectData}
                tableAttributes={{ border: true, selectColumn: !this.comDisabled }}
                tableEvents={this.itemTableEvents}
              ></zj-table>
            )
          }
        }
      ]
    },
    formLogistics() {
      return [
        {
          columnAttributes: {
            label: '补贴费用',
            prop: 'allowanceCost',
            width: 200
          }
        },
        {
          columnAttributes: {
            label: '所属销售公司类型',
            prop: 'belongCompanyType',
            width: 200
          },
          render: (h, { row }) => {
            const { belongCompanyType } = row
            const typeObj = {
              GE_JIANG: '格匠',
              GUANG_ZHOU: '广州销售公司',
              FO_SHAN: '佛山销售公司',
              OTHER: '其他销售公司'
            }
            return <div>{typeObj[belongCompanyType] || row.belongCompanyType }</div>
          }
        },
        {
          columnAttributes: {
            label: '运费结算系数',
            prop: 'coefficient',
            width: 200
          }
        },
        {
          columnAttributes: {
            label: '备注',
            prop: 'comment',
            width: 200
          }
        },
        {
          columnAttributes: {
            label: '最终运费',
            prop: 'cost',
            width: 200
          }
        },
        {
          columnAttributes: {
            label: '客户名称',
            prop: 'customerName',
            width: 200
          }
        },
        {
          columnAttributes: {
            label: '客户电话',
            prop: 'customerPhone',
            width: 200
          }
        },
        {
          columnAttributes: {
            label: '无法生成的原因',
            prop: 'errorResult',
            width: 200
          }
        },
        {
          columnAttributes: {
            label: '是否已经对过帐',
            prop: 'isAccountChecking',
            width: 200
          },
          render: (h, { row }) => {
            const { isAccountChecking } = row
            return <div>{+isAccountChecking ? '是' : '否'}</div>
          }
        },
        {
          columnAttributes: {
            label: '是否已经审核',
            prop: 'isAudit',
            width: 200
          },
          render: (h, { row }) => {
            const { isAudit } = row
            return <div>{+isAudit ? '是' : '否'}</div>
          }
        },
        {
          columnAttributes: {
            label: '是否完结',
            prop: 'isFinish',
            width: 200
          },
          render: (h, { row }) => {
            const { isFinish } = row
            return <div>{+isFinish ? '已经完结' : '未完结'}</div>
          }
        },
        {
          columnAttributes: {
            label: '实际是否卸货',
            prop: 'isRealUnload',
            width: 200
          },
          render: (h, { row }) => {
            const { isRealUnload } = row
            return <div>{+isRealUnload ? '是' : '否'}</div>
          }
        },
        {
          columnAttributes: {
            label: '实际是否上楼',
            prop: 'isRealUpstairs',
            width: 200
          },
          render: (h, { row }) => {
            const { isRealUpstairs } = row
            return <div>{+isRealUpstairs ? '是' : '否'}</div>
          }
        },
        {
          columnAttributes: {
            label: '是否卸货',
            prop: 'isUnload',
            width: 200
          },
          render: (h, { row }) => {
            const { isUnload } = row
            return <div>{+isUnload ? '是' : '否'}</div>
          }
        },
        {
          columnAttributes: {
            label: '是否上楼',
            prop: 'isUpstairs',
            width: 200
          },
          render: (h, { row }) => {
            const { isUpstairs } = row
            return <div>{+isUpstairs ? '是' : '否'}</div>
          }
        },
        {
          columnAttributes: {
            label: '物料名称',
            prop: 'materialCode',
            width: 200
          }
        },
        {
          columnAttributes: {
            label: '计费分类',
            prop: 'materialCostType',
            width: 200
          }
        },
        {
          columnAttributes: {
            label: '产品名称',
            prop: 'materialName',
            width: 200
          }
        },
        {
          columnAttributes: {
            label: '规格型号',
            prop: 'materialSpecification',
            width: 350
          }
        },
        {
          columnAttributes: {
            label: '物料类型',
            prop: 'materialType',
            width: 200
          }
        },
        {
          columnAttributes: {
            label: '商家编码',
            prop: 'merchantCode',
            width: 200
          }
        },
        {
          columnAttributes: {
            label: '商家名称',
            prop: 'merchantName',
            width: 200
          }
        },
        {
          columnAttributes: {
            label: '订单号',
            prop: 'orderCode',
            width: 200
          }
        },
        {
          columnAttributes: {
            label: '订单时间',
            prop: 'orderDate',
            width: 200
          }
        },
        {
          columnAttributes: {
            label: '订单类型',
            prop: 'orderType',
            width: 200
          },
          render: (h, { row }) => {
            const { orderType } = row
            const typeObj = {
              TOB: '商家机工程机类型',
              ALL: '所有类型，广州的订单统一 开单价',
              TOC: '佛山销售销售订单类型公司'
            }
            return <div>{typeObj[orderType]|| row.orderType}</div>
          }
        },
        {
          columnAttributes: {
            label: '订单类型细分',
            prop: 'orderTypeDetail',
            width: 200
          },
          render: (h, { row }) => {
            const { orderType } = row
            const typeObj = {
              PICKING_UP_ORDER: '前置仓提货订单',
              SALE_ORDER: '销售订单',
              MERCHANT_WAREHOUSE_ORDER: '商家仓订单',
              PROJECT_ORDER: '工程机订单',
              SALE_RETURN_ORDER: '销售退货单'
            }
            return <div>{typeObj[orderType]|| row.typeObj}</div>
          }
        },
        {
          columnAttributes: {
            label: '收货送货地址',
            prop: 'receiptAddress',
            width: 200
          }
        },
        {
          columnAttributes: {
            label: '退货单号',
            prop: 'returnOrderCode',
            width: 200
          }
        },
        {
          columnAttributes: {
            label: '补贴结算系数',
            prop: 'subsidyCoefficient',
            width: 200
          }
        },
        {
          columnAttributes: {
            label: '嘉贤创建时间',
            prop: 'time',
            width: 200
          }
        },
        {
          columnAttributes: {
            label: '费用汇总',
            prop: 'totalCost',
            width: 200
          }
        },
        {
          columnAttributes: {
            label: '单价计算',
            prop: 'unitPrice',
            width: 200
          }
        },
        {
          columnAttributes: {
            label: '卸货上楼结算系数',
            prop: 'unloadUpstairsCoefficient',
            width: 200
          }
        },
        {
          columnAttributes: {
            label: '上楼卸货费用',
            prop: 'unloadUpstairsCost',
            width: 200
          }
        },
        {
          columnAttributes: {
            label: '发货仓库编码',
            prop: 'warehouseCode',
            width: 200
          }
        },
        {
          columnAttributes: {
            label: '发货仓库名称',
            prop: 'warehouseName',
            width: 200
          }
        }
      ]
    },
    formOutbound() {
      return [
        {
          columnAttributes: {
            label: '条码',
            prop: 'barCode',
            width: 200
          }
        },
        {
          columnAttributes: {
            label: '出库时间',
            prop: 'consignerTimeV2',
            width: 200
          }
        },
        {
          columnAttributes: {
            label: '创建人',
            prop: 'createBy',
            width: 200
          }
        },
        {
          columnAttributes: {
            label: '创建时间',
            prop: 'createTime',
            width: 200
          }
        },
        {
          columnAttributes: {
            label: '送货时间',
            prop: 'deliveryTimeV2',
            width: 200
          }
        },
        {
          columnAttributes: {
            label: '条码唯一id',
            prop: 'id',
            width: 200
          }
        },
        {
          columnAttributes: {
            label: '物料代码',
            prop: 'materialCode',
            width: 200
          }
        },
        {
          columnAttributes: {
            label: '物料类型',
            prop: 'materialType',
            width: 200
          }
        },
        {
          columnAttributes: {
            label: '销售订单号',
            prop: 'orderNumber',
            width: 200
          }
        },
        {
          columnAttributes: {
            label: '收货人',
            prop: 'receiptCompany',
            width: 200
          }
        },
        {
          columnAttributes: {
            label: '商家名称',
            prop: 'salesCompany',
            width: 200
          }
        },
        {
          columnAttributes: {
            label: '规格',
            prop: 'specification',
            width: 350
          }
        },
        {
          columnAttributes: {
            label: '更新人',
            prop: 'updateBy',
            width: 200
          }
        },
        {
          columnAttributes: {
            label: '修改时间',
            prop: 'updateTime',
            width: 200
          }
        },
        {
          columnAttributes: {
            label: '发货仓库名称',
            prop: 'warehouse',
            width: 200
          }
        }
      ]
    },
    formLogisticsData() {
      return [
        {
          name: 'slot-component',
          md: 24,
          attributes: { disabled: false },
          formItemAttributes: { label: '', prop: '' },
          render: (h, { props }) => {
            var { value } = props
            return (
              <zj-table
                tableAttributes={{ maxHeight: '600px', ...this.defaultTableAttributes }}
                isDrop={true}
                columns={this.formLogistics}
                tableData={this.logisticsData}
                tableEvents={this.itemTableEvents}
              ></zj-table>
            )
          }
        }
      ]
    }
  },
  mounted() {
    this.getStagecustomerListV2()
    if (this.detailsId) {
      getCustomerTransferDetail({ id: this.detailsId }).then(res => {
        this.formData = res.data
        this.selectData = res.data.orders.map(k => {
          k.disabledId = k.customerStockId
          k.stockName = '嘉贤前置仓'

          return k
        })
        delete this.formData.orders
        if (this.detailsId && this.moduleType === 2) {
          getListCostBillV2({
            pageNum: 1,
            pageSize: -1,
            params: [
              {
                param: 'order_code',
                compare: '=',
                value: this.formData.jiaxianOrderId
              }
            ]
          }).then(res => {
            res.data.records.forEach(item => {
              item.sums1 = ['orderHasSendQty', 'subsidyCoefficient', 'unloadUpstairsCoefficient', 'coefficient']
              item.sums2 = ['cost', 'unitPrice', 'totalCost', 'allowanceCost']
            })
            this.logisticsData = res.data.records
          })
        }
      })
    }
  },
  methods: {
    debounceChange: debounce(function(val, index) {
      if (val <= 0) {
        this.selectData[index].qty = 1
      } else {
        this.selectData[index].qty = parseInt(val)
      }
    }, 500),
    // 列表请求函数
    getList(...p) {
      this.recordSelected = []
      return getcustomerFrontList(...p)
    },
    // 表格列解析渲染数据更改
    columnParsing(item, defaultData) {
      return defaultData
    }, // 监听勾选变化
    selectionChange(data) {
      this.recordSelected = data
    },
    itemSelectionChange(data) {
      this.itemRecordSelected = data
    },
    selectable(row) {
      if (this.selectData.length) {
        for (let j = 0; j < this.selectData.length; j++) {
          if (row.id === this.selectData[j].disabledId) {
            this.$set(row, 'disabledId', this.selectData[j].disabledId)
          }
        }
      }

      if (!row.disabledId) {
        return true
      } else {
        return false
      }
    },
    getStagecustomerListV2() {
      this.formData.customerNumber = this.customerNumber
      this.formData.customerName = this.customerName
      getStagecustomerListV2({
        pageNum: 1,
        pageSize: -1,
        params: [
          {
            param: 'a.higher_prant_number',
            compare: '=',
            value: this.customerNumber || ''
          }
        ]
      }).then(res => {
        this.sonCustomerList = res.data.records

        this.sonCustomerNameList = res.data.records.map(k => {
          return {
            label: k.name,
            value: k.id
          }
        })
        this.sonCustomerNumberList = res.data.records.map(k => {
          return {
            label: k.number,
            value: k.id
          }
        })
        if (this.detailsId && this.sonCustomerList.length) {
          const transfer = this.sonCustomerList.find(k => k.number === this.formData.transferCustomerNumber)
          this.formData.transferCustomerNumber = transfer.id
          this.formData.transferCustomerName = transfer.id
        }
      })
    },
    handleAddData() {
      this.selectData = [...this.selectData, ...this.recordSelected]
      for (let i = 0; i < this.$refs.pageRef.$children[0].tableData.length; i++) {
        for (let j = 0; j < this.selectData.length; j++) {
          if (this.$refs.pageRef.$children[0].tableData[i].id == this.selectData[j].id) {
            this.$set(this.$refs.pageRef.$children[0].tableData[i], 'disabledId', this.selectData[j].id)
          }
        }
      }
      this.selectData = this.selectData.map(k => {
        return {
          materialCode: k.materialCode,
          materialId: '',
          materialName: k.materialName,
          materialOldNumber: k.materialOldNumber,
          notes: '',
          qty: 0,
          frontStockNum: k.frontStockNum,
          specification: k.specification,
          disabledId: k.disabledId,
          stockName: '嘉贤前置仓',
          customerStockId: k.disabledId
        }
      })
      this.visible = false
      this.handleClearSelection()
    },
    handleAllDel() {
      if (this.itemRecordSelected.length) {
        if (this.$refs.pageRef) {
          for (let i = 0; i < this.$refs.pageRef.$children[0].tableData.length; i++) {
            for (let j = 0; j < this.itemRecordSelected.length; j++) {
              if (this.$refs.pageRef.$children[0].tableData[i].id === this.itemRecordSelected[j].disabledId) {
                this.$set(this.$refs.pageRef.$children[0].tableData[i], 'disabledId', null)
              }
            }
          }
        }
        for (let j = 0; j < this.itemRecordSelected.length; j++) {
          for (let k = 0; k < this.selectData.length; k++) {
            if (this.selectData[k].disabledId === this.itemRecordSelected[j].disabledId) {
              this.selectData.splice(k, 1)
            }
          }
        }
        this.handleClearSelection()
      } else {
        this.$errorMsg('请选择删除项')
      }
    },
    handleDel(index) {
      if (this.$refs.pageRef) {
        for (let i = 0; i < this.$refs.pageRef.$children[0].tableData.length; i++) {
          if (this.$refs.pageRef.$children[0].tableData[i].id === this.selectData[index].disabledId) {
            this.$set(this.$refs.pageRef.$children[0].tableData[i], 'disabledId', null)
          }
        }
      }
      this.selectData.splice(index, 1)
      this.handleClearSelection()
    },
    handleClearSelection() {
      this.recordSelected = []
      this.$refs.pageRef && this.$refs.pageRef.refreshList()
    },
    handleChange(e) {
      if (e) {
        this.formData.transferCustomerName = e
        this.formData.transferCustomerNumber = e
      } else {
        this.formData.transferCustomerNumber = ''
        this.formData.transferCustomerName = ''
      }
    },
    handlerefreshList() {
      this.$emit('refresh')
      this.onClose()
    },
    onClose() {
      this.formData = {}
      this.selectData = []
      this.$emit('close')
    },
    onReset() {
      this.$refs.formRef.resetFields()
      this.selectData = []
    },
    onSubmit(type = null) {
      this.$refs.formRef.validate(valid => {
        for (let i = 0; i < this.selectData.length; i++) {
          if (this.selectData[i].qty <= 0) {
            this.$errorMsg('调拨数量不能小于1')
            return
          }
        }
        const transfer = this.sonCustomerList.find(
          k => k.id === (this.formData.transferCustomerNumber || this.formData.transferCustomerName)
        )
        console.log(transfer, 999)
        if (valid) {
          const params = {
            ...this.formData,
            orders: this.selectData,
            transferCustomerNumber: transfer.number,
            transferCustomerName: transfer.name
          }
          if (this.moduleType === 1) {
            params.status = type
            addCustomerTransfer(params).then(() => {
              this.$successMsg(type === 'SAVE' ? '保存成功' : '新增成功')
              this.handlerefreshList()
            })
          } else {
            updateCustomerTransfer(params).then(() => {
              this.$successMsg('编辑成功')
              this.handlerefreshList()
            })
          }
        } else {
          console.log('error submit!!')
          return false
        }
      })
    },
    onExamine(type = null) {
      examineCustomerTransfer({
        id: this.detailsId,
        status: type
      }).then(() => {
        this.$successMsg('审核成功')
        this.handlerefreshList()
      })
    },
    onInvoice(type = null) {
      setNeExamine({
        id: this.detailsId,
        status: type
      }).then(() => {
        this.$successMsg('反审成功')
        this.handlerefreshList()
      })
    }
  }
}
</script>

<style lang="scss" scoped>
.header1style {
  text-align: right;
  font-size: 12px;
  color: red;
  line-height: 18px;
}
</style>
