<template>
    <div>
      <el-dialog title="加工任务" :visible.sync="processForm" :before-close="handleProcessclose">
         <el-form
            inline
            label-position="top"
            :model="processDate"
            ref="processDate"
            :rules="rules">
            <div>
              <el-form-item
                label="货主"
                prop="ownerName">
                 <el-input v-model="processDate.ownerName" disabled></el-input>
              </el-form-item>
              <el-form-item
                label="子件"
                prop="subSkuName">
                  <PublicQuery
                  title="商品批次库位查询"
                  single
                  :before="beforeSelectSku"
                  @change="getGoodsDate"
                  cfgKey="kitWmsInvLotLocNotHold"
                  baseUrl="/kit_web/kitweb"
                  :textField.sync="processDate.subSkuName"
                ></PublicQuery>
              </el-form-item>
              <el-form-item
                label="包装规格"
                prop="packDesc">
                <PublicQuery
                title="包装规格"
                single
                disabled
                cfgKey="kitWmsPackage"
                baseUrl="/kit_web/kitweb"
                :valueField.sync="processDate.packDesc"
                :textField.sync="processDate.packDesc"
              ></PublicQuery>
              </el-form-item>
               <el-form-item
                label="批次号"
                prop="lotNum">
                 <el-input v-model="processDate.lotNum"></el-input>
              </el-form-item>
              <el-form-item
                label="包装单位"
                prop="uomDesc">
                <PublicQuery
                title="包装单位"
                single
                :rowData.sync="processDate.uomData"
                cfgKey="kitWmsUom"
                baseUrl="/kit_web/kitweb"
                :valueField.sync="processDate.uomDesc"
                :textField.sync="processDate.uomDesc"
              ></PublicQuery>
              </el-form-item>
              <el-form-item
                label="数量"
                prop="qtyUom">
                 <el-input v-model="processDate.qtyUom" type="number" @input="changeNum"></el-input>
              </el-form-item>
              <el-form-item
                label="数量EA"
                prop="qtyEa">
                 <el-input v-model="processDate.qtyEa" disabled></el-input>
              </el-form-item>
              <el-form-item
                label="库位"
                prop="locCode">
                 <el-input v-model="processDate.locCode" disabled></el-input>
              </el-form-item>
              <el-form-item
                label="跟踪号"
                prop="traceId">
                 <el-input v-model="processDate.traceId"></el-input>
              </el-form-item>
              <el-form-item
                label="目标库位"
                prop="toLoc">
                 <PublicQuery
                title="库位"
                single
                :before="beforeSelectToLoc"
                cfgKey="kitWmsLoc"
                baseUrl="/kit_web/kitweb"
                :valueField.sync="processDate.toLoc"
                :textField.sync="processDate.toLoc"
                @change="getTargetLocation"
              ></PublicQuery>
              </el-form-item>
              <el-form-item
                label="目标跟踪号"
                prop="toId">
                <el-input v-model="processDate.toId"></el-input>
              </el-form-item>
            </div>
          </el-form>
          <div class="more-query-btn">
            <el-button v-auth="50300030101" type="primary" @click="handleConfirm('processDate')">确认</el-button>
          </div>
      </el-dialog>
    </div>
</template>
<script>
export default {
  data () {
    return {
      rules: {
        subSkuName: [{ required: true, message: '请输入子件', trigger: 'change' }],
        uomDesc: [{ required: true, message: '请输入包装单位', trigger: 'blur' }],
        qtyUom: [{ required: true, message: '请输入数量', trigger: 'blur' }],
        toLoc: [{ required: true, message: '请输入目标库位', trigger: 'blur' }],
        toId: [{ required: true, message: '请输入目标跟踪号', trigger: 'blur' }]
      }
    }
  },
  props: {
    processForm: Boolean,
    processDate: {
      type: Object,
      default: () => ({})
    },
  },
  mounted () {

  },
  methods: {
    getTargetLocation (row) {
      this.form.toLoc = row.locCode
    },
    getGoodsDate (row) {
      this.processDate.subSkuName = row.skuName
      this.processDate.packDesc = row.packDesc
      this.processDate.lotNum = row.lotNum
      this.processDate.uomDesc = row.uomDesc
      this.processDate.qtyUom = row.qty
      this.processDate.qtyEa = row.qty
      this.processDate.locCode = row.locCode
      this.processDate.traceId = row.traceId
      this.processDate.uomQty = row.uomQty
      this.processDate.uom = row.printUom
      this.processDate.subSkuCode = row.skuCode
      this.processDate.packCode = row.packCode
    },
    handleProcessclose () {
      this.$emit('handleProcessclose')
    },
    handleConfirm (formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          console.log('000')
          this.$emit('handleDistribution', this.processDate)
          this.$emit('handleProcessclose')
        } else {
          console.log('error submit!!')
          return false
        }
      })
    },
    changeNum () {
      this.processDate.qtyEa = parseFloat(this.processDate.qtyUom).toFixed(2)
    },
    beforeSelectSku () {
      return {
        queryParams: {
          ownerCodeParam: this.processDate.ownerCode,
          skuCodeParam: this.processDate.skuCodes
        }
      }
    },
    beforeSelectToLoc () {
      return {
        queryParams: {
          // locUseTypes: this.processDate.ownerCode,
        }
      }
    }
  }
}
</script>
