<template>
    <div>
        <el-dialog
          title="商品拣货位"
          v-if="goodsFormVisible"
          :visible.sync="goodsFormVisible"
          :before-close="close"
          width="66%">
          <el-form
            inline
            ref="goodsForm"
            label-position="top"
            :model="formData"
            :rules="rules">
            <div>
              <el-form-item
                label="库位拣货位类型"
                prop="locPkType">
                <el-select v-model="formData.locPkType">
                  <el-option label="固定拣货位" value="FPL"></el-option>
                  <el-option label="动态拣货位" value="DPL"></el-option>
                </el-select>
              </el-form-item>
              <el-form-item
                label="商品拣货位类型"
                prop="skuLocType">
                <el-select v-model="formData.skuLocType">
                  <el-option label="箱拣货库位" value="CS"></el-option>
                  <el-option label="件拣货库位" value="EA"></el-option>
                  <el-option label="箱件合并拣货库位" value="PC"></el-option>
                </el-select>
              </el-form-item>
              <el-form-item
                label="固定拣货位"
                prop="locCode"
                :rules="formData.locPkType==='FPL'?rules.locCode:[]">
                <PublicQuery
                title="库位"
                single
                :disabled="formData.locPkType!=='FPL'"
                :rowData.sync="locData"
                cfgKey="bdWmsLoc"
                baseUrl="/bd_web/bdweb"
                :valueField.sync="formData.locCode"
                :textField.sync="formData.locCode"
              ></PublicQuery>
              </el-form-item>
              <el-form-item
                label="动态拣货区"
                prop="zoneCode"
                :rules="formData.locPkType==='DPL'?rules.zoneCode:[]">
                <PublicQuery
                title="库区"
                single
                :disabled="formData.locPkType!=='DPL'"
                :rowData.sync="zoneData"
                cfgKey="bdWmsZone"
                baseUrl="/bd_web/bdweb"
                :valueField.sync="formData.zoneCode"
                :textField.sync="formData.zoneName"
              ></PublicQuery>
              </el-form-item>
              <el-form-item
                label="动态拣货数量"
                prop="qtyLoc">
                <el-input v-model="formData.qtyLoc" disabled></el-input>
              </el-form-item>
              <el-form-item
                label="库存上限EA"
                prop="maxLimit">
                <el-input v-model="formData.maxLimit" ></el-input>
              </el-form-item>
              <el-form-item
                label="库存下限EA"
                prop="minLimit">
                <el-input v-model="formData.minLimit" ></el-input>
              </el-form-item>
              <el-form-item
                label="最小补货数量"
                prop="minRp">
                <el-input v-model="formData.minRp"></el-input>
              </el-form-item>
              <el-form-item
                label="最小补货单位"
                prop="rpUom">
                <PublicQuery
                title="包装单位"
                single
                :rowData.sync="rpUomData"
                cfgKey="bdWmsUom"
                baseUrl="/bd_web/bdweb"
                :valueField.sync="formData.rpUom"
                :textField.sync="formData.cdprDesc"
              ></PublicQuery>
              </el-form-item>
              <el-form-item
                label="是否被占用数"
                prop="isRpAlloc">
                <el-checkbox v-model="formData.isRpAlloc" true-label="Y" false-label="N"></el-checkbox>
              </el-form-item>
              <el-form-item
                label="是否超量分配"
                prop="isOverAlloc">
                 <el-checkbox v-model="formData.isOverAlloc" true-label="Y" false-label="N"></el-checkbox>
              </el-form-item>
              <el-form-item
                label="是否超量补货"
                prop="isOverRp">
                 <el-checkbox v-model="formData.isOverRp" true-label="Y" false-label="N"></el-checkbox>
              </el-form-item>
            </div>
          </el-form>
          <div class="more-query-btn">
            <el-button v-auth="50300030101" type="primary" @click="handleConfirm">确认</el-button>
            <el-button v-auth="50300030101" type="primary" @click="handleConfirmAdd">确认并添加</el-button>
          </div>
        </el-dialog>
    </div>
</template>
<script>
export default {
  data () {
    return {
      activeNames: ['1', '2'],
      formData: {
        isRpAlloc: 'N',
        isOverAlloc: 'N',
        isOverRp: 'N'
      },
      locData: {}, // 固定拣货位
      zoneData: {}, // 动态拣货区
      rpUomData: {}, // 最小补货单位
      date: '',
      rules: {
        locPkType: [{ required: true, message: '库位拣货位类型必填', trigger: 'change' }],
        skuLocType: [{ required: true, message: '商品拣货位类型必填', trigger: 'change' }],
        locCode: [{ required: true, message: '固定拣货位必填', trigger: 'change' }],
        zoneCode: [{ required: true, message: '动态拣货区必填', trigger: 'change' }],
        maxLimit: [{ required: true, message: '库存上限EA必填', trigger: 'change' }],
        minLimit: [{ required: true, message: '库存下限EA必填', trigger: 'change' }],
        minRp: [{ required: true, message: '最小补货数量必填', trigger: 'change' }],
        rpUom: [{ required: true, message: '最小补货单位必填', trigger: 'change' }]
      }
    }
  },
  props: {
    goodsFormVisible: Boolean,
    code: String,
    currentRow: {
      type: Object,
      default: () => ({})
    },
    rowIndex: '',
    editBool: Boolean
  },
  mounted () {

  },
  methods: {
    close () {
      this.$emit('close')
    },

    // 确认
    handleConfirm () {
      let data = Object.assign({ isChecked: 'false' }, this.formData)
      if (this.editBool) {
        this.$emit('editOK', data, this.rowIndex)
        this.$refs.goodsForm.resetFields()
      } else {
        this.$refs.goodsForm.validate((valid) => {
          if (valid) {
            this.$emit('handleConfirm', data)
            this.$refs.goodsForm.resetFields()
          }
        })
      }
    },

    // 确认并添加
    handleConfirmAdd () {
      let data = Object.assign({ isChecked: 'false' }, this.formData)
      if (this.editBool) {
        this.$emit('editOK', data, this.rowIndex)
        this.$refs.goodsForm.resetFields()
      } else {
        this.$refs.goodsForm.validate((valid) => {
          if (valid) {
            this.$emit('handleConfirmAdd', data)
            this.$refs.goodsForm.resetFields()
          }
        })
      }
    },

    // 选商品前校验
    beforeSelectSku () {
      return {
        queryParams: {
          ownerCodeParam: this.code
        }
      }
    },
  },

  watch: {
    locData: {
      handler (item) {

      },
      deep: true
    },
    zoneData: {
      handler (item) {

      },
      deep: true
    },
    rpUomData: {
      handler (item) {

      },
      deep: true
    },
    currentRow: {
      handler (item) {
        this.formData = { ...item }
      },
      deep: true
    }
  }
}
</script>
