itemCRUDDialog.vue 4.63 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="data" :rules="rules" label-width="35%">
      <el-row :gutter="20" v-if="flag">
        <el-col :span="12">
          <el-form-item label="容器类型" prop="containerType">
            <el-select v-model="data.containerType" placeholder="请选择容器类型">
              <el-option v-for="item in containerType"
                         :key="item.code"
                         :label="item.name"
                         :value="item.code"/>
            </el-select>
          </el-form-item>
        </el-col>

        <el-col :span="12">
          <el-form-item label="增加数量(个)" prop="quantity">
            <el-input v-model.number="data.quantity" placeholder="请输入增加数量(个)">
            </el-input>
          </el-form-item>
        </el-col>
      </el-row>

      <el-row :gutter="20" v-if="!flag">
        <el-col :span="12">
          <el-form-item label="库位编码" prop="locationCode" >
            <el-input v-model.number="data.locationCode" placeholder="请输入库位编码" />
          </el-form-item>
        </el-col>

          <el-col :span="12" >
            <el-form-item label="容器状态" prop="status">
              <el-select v-model="data.status" placeholder="请选择容器类型">
                <el-option v-for="item in containerStatus"
                           :key="item.code"
                           :label="item.name"
                           :value="item.code"/>
              </el-select>
            </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>
  import {add, edit} from '@/api/config/InventoryInfo/container'

  export default {
    name: 'itemCRUDDialog',
    props: {
      temData: {
        type: String,
        default: ""
      },
      show: {
        type: Boolean,
        default: false
      },
      containerType: {
        type: Array,
        default: () => []
      },
      flag: {
        type: Boolean,
        default: true
      }
    },
    watch: {
      show() {
        this.visible = this.show
        if (!this.visible) {
          this.cancel()
        }
        if (this.flag){
          this.data = {}
        }else {
          this.data = JSON.parse(this.temData)
          this.data = {"locationCode":this.data.locationCode,
            "status":this.data.status}
        }
      }
    },
    data() {
      return {
        data:{},
        visible: this.show,
        rules: {
          quantity: [
            {required: true, message: '请输入个数', trigger: 'blur'},
            {type: 'number', message: '请输入数字'}
          ],
          containerType: [
            {required: true, message: '请选择容器类型', trigger: 'blur'},
          ],
          status: [
            {required: true, message: '请选择容器状态', trigger: 'blur'},
          ]
        },
        containerStatus: [
          {
            code: "lock",
            name: "锁"
          },
          {
            code: "empty",
            name: "空"
          },
          {
            code: "full",
            name: "满"
          },
          {
            code: "some",
            name: "有"
          },

        ],
        title: '增加容器'
      }
    },
    methods: {
      /** 提交按钮 */
      submitForm: function () {
        if (this.flag) {
          this.$refs['diaForm'].validate(valid => {
            if (valid) {
              add(this.data).then(response => {
                if (response.code === 200) {
                  this.$emit('globalQuery')
                  this.msgSuccess('新增成功')
                  this.visible = false
                }
              })
            }
          })
        } else {
          this.$refs['diaForm'].validate(valid => {
            if (valid) {
              edit(this.data).then(response => {
                if (response.code === 200) {
                  this.$emit('globalQuery')
                  this.msgSuccess('修改成功')
                  this.visible = false
                }
              })
            }
          })
        }
      },
      // 重置对话框表单
      reset() {
        this.resetForm('diaForm')
        this.visible = false
      },
      //关闭对话框
      cancel() {
        this.reset()
      },
    }
  }
</script>

<style scoped>

</style>