<template>
  <ele-modal :visible.sync="visible" title="处置" width="400px" :close-on-click-modal="false" :maxable="true">
    <el-form :model="formData" :rules="rules" ref="formRef">
      <el-form-item label="处置方式" props="a">
        <el-input value="改型" readonly></el-input>
      </el-form-item>
      <el-form-item label="仓库" props="warehouseCode">
        <DictSelection dictName="处置仓库" v-model="formData.warehouseCode" />
      </el-form-item>
      <el-form-item label="数量" props="disposeWeight">
        <el-input v-model="formData.disposeWeight" placeholder="请输入">
          <span slot="suffix"> PCS</span>
        </el-input>
      </el-form-item>
    </el-form>
    <div slot="footer">
      <el-button @click="cancel">取消</el-button>
      <el-button type="primary" @click="confirm">确认</el-button>
    </div>
  </ele-modal>
</template>

<script>
  export default {
    data() {
      return {
        visible: false,
        formData: {
          warehouseCode: '',
          warehouse: '',
          disposeWeight: ''
        },
        callback: null,
        rules: {
          warehouseCode: [{ required: true, message: '请输入' }],
          disposeWeight: [{ required: true, message: '请输入' }]
        }
      };
    },
    methods: {
      open(disposeType, callback) {
        this.visible = true;
        this.formData.disposeType = disposeType;
        this.callback = callback;
      },
      confirm() {
        this.$refs.formRef.validate((value) => {
          if (value) {
            this.$emit('confirm', this.formData);
            this.callback && this.callback(this.formData);
            this.cancel();
          }
        });
      },
      cancel() {
        this.formData = {};
        this.visible = false;
      }
    }
  };
</script>
