itemCRUDDialog.vue 2.96 KB
<template>
  <el-dialog
    :title="title"
    :visible.sync="visible"
    width="700px"
    append-to-body
    @close="$emit('update:show', false)"
  >
    <el-form ref="diaForm" :title="title" :model="diaForm" :rules="rules" label-width="100px">
      <el-row gutter="20">
        <el-col span="12">
          <el-form-item label="库位类型" prop="containerType">
            <el-select v-model="diaForm.containerType" placeholder="请输入库位类型">
              <el-option v-for="item in containerType"
                         :label="item.dictLabel"
                         :value="item.dictValue" />
            </el-select>
          </el-form-item>
        </el-col>

        <el-col span="12">
          <el-form-item label="增加数量(个)" prop="quantity">
            <el-input v-model="diaForm.quantity" placeholder="请选择增加数量(个)">
            </el-input>
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>

    <div slot="footer" class="dialog-footer">
      <el-button type="primary" @click="submitForm">确 定</el-button>
      <el-button @click="cancel">取 消</el-button>
    </div>

  </el-dialog>
</template>

<script>
  export default{
    name: 'itemCRUDDialog',
    props:{
      show:{
        type:Boolean,
        default:false
      },
      switch:{
        type:Boolean,
        default:false
      },
      diaForm: {
        type:Object,
        default:{}
      },
      title: {
        type:String,
        default:''
      },
      containerType:{
        type:Array,
        default:[]
      }
    },
    watch:{
      show(){
        this.visible = this.show
        if (!this.switch){
          this.diaForm = {}
        }
      }
    },
    data() {
      return {
        visible: this.show,
        rules: {
          quantity: [
            { required: true, message: '请输入个数', trigger: 'blur' },
            { type:'number', message: '请输入数字'}
          ]
        },
        title:''
      }
    },
    methods:{
      /** 提交按钮 */
      submitForm: function() {
        this.$refs['diaForm'].validate(valid => {
          if (valid) {
            if (this.switch) {
              edit(this.diaForm).then(response => {
                if (response.code === 200) {
                  this.msgSuccess('修改成功')
                  this.show = false
                  this.handleQuery()
                }
              })
            } else {
              add(this.diaForm).then(response => {
                if (response.code === 200) {
                  this.msgSuccess('新增成功')
                  this.show = false
                  this.handleQuery()
                }
              })
            }
          }
        })
      },
      // 重置对话框表单
      reset() {
        this.resetForm('diaForm')
        this.visible = false
      },
      //关闭对话框
      cancel() {
        this.diaOpen = false
        this.reset()
      },
    }
  }
</script>

<style scoped>

</style>