<template>
  <div>
    <p-modal
      title="异常处理"
      :visible="visible"
      :draggable="true"
      :destroyOnClose ='true'
      @ok="handleOk"
      @cancel="handleCancel"
      @enlargeChange="enlargeChange"
    >
      <p-grid-form ref="form" :span="18" :items="items" @submit="hanlderSubmit" />
    </p-modal>
  </div>
</template>
<script>
import { rcvError } from './api'

const items = [
  {
    type: 'textarea',
    name: 'abnormalReasons',
    label: '异常原因',
    span: 20,
    limit: 100,
    value: '',
  },
]
export default {
  props: {
    visible: {
      type: Boolean,
      default: false,
    },
    exceptionData: {
      type: Array,
      default: null,
    },
    refException: {
      type: Object,
      default: null,
    },
    
    mainException: {
      type: Object,
      default: null,
    },
  },

  model: {
    prop: 'visible',
    event: 'change',
  },
  watch: {
    visible: {
      handler(visible) {
        if (!visible) return
      },
    },
  },

  data() {
    return {
      // visible: false,
      items,
    }
  },
  methods: {
    hanlderSubmit(evnet, form) {
      evnet.preventDefault()
      console.log(form.getFieldsValue())
    },
    handleOk(e) {
      var params = {}
      var ref = this.refException
      var form = this.$refs.form.form.getFieldsValue()
      params.detailList = this.exceptionData
      params.head = this.mainException
      console.log(params,'ppppppppppp');
      // params.head.consignorid = params.head.CONSIGNORID
      params.head.billno = params.head.BILLNO
      params.head.billtype = params.head.rcvType
      params.head.branchid = params.head.BRANCHID
      params.head.branchcode = params.head.warehouseCode
      params.head.branchname = params.head.warehouseName
      params.head.consignorid = params.head.mtlOwnerId
      params.head.consignorcode = params.head.mtlOwnerNum
      params.head.consignorname = params.head.mtlOwnerName
      params.head.refbilltype = params.head.rcvType
      params.head.refbillid = params.head.billid
      params.head.refbillcode = params.head.billno
      params.detailList.forEach((t) => {
        t.billno = params.head.billno
        t.seqno = t._row_count
        t.refSeqno = t._row_count
        t.itemid = t.itemId
        t.asnLineId =t.tempAsnLineId
        // t.billtype = params.head.rcvType
        t.branchid = params.head.BRANCHID
        t.branchcode = params.head.warehouseCode
        t.branchname = params.head.warehouseName
        t.consignorid = params.head.mtlOwnerId
        t.consignorcode = params.head.mtlOwnerNum
        t.consignorname = params.head.mtlOwnerName
        t.refBilltype = params.head.rcvType
        t.refBillid = params.head.billid
        t.refBillno = params.head.billno
        t.affirmedPcs = t.oddCaseQty
        t.affirmedQty = t.pieceQty
        t.packSize = t.qty
        t.attrStr1 = t.ID
        t.abnormalReasons = form.abnormalReasons
      })
      rcvError(params).then((res) => {
        if (!res.success) {
          this.$exception(res)
          return
        }
        this.$message.success(this.$lang('异常处理成功'))
        ref.removeSelectedRow()//默认删除勾选数据
        this.$emit('change', false)
      })
    },
    handleCancel(e) {
      this.$emit('change', false)
    },
    enlargeChange(isEnlarge) {
      console.log(isEnlarge)
    },
  },
}
</script>