transferDialog.vue 2.18 KB
<template>
  <el-dialog
    title="立库移库"
    :visible.sync="visible"
    :showtrans="showtrans"
    width="500px"
    append-to-body
    @open="diaOpen"
    @close="$emit('update:showtrans', false)"
  >
    <el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="80px">
      <el-form-item label="移出库位" prop="sourceLocation">
        <el-input v-model="ruleForm.sourceLocation"></el-input>
      </el-form-item>
      <el-form-item label="移入库位" prop="destinationLocation">
        <el-input v-model="ruleForm.destinationLocation"></el-input>
      </el-form-item>
    </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 { createTransferTask } from "@/api/task/taskHeader";
export default {
  props: {
    showtrans: {
      type: Boolean,
      default: false,
    },
  },
  data() {
    return {
      visible: this.showtrans,
      ruleForm: {
        sourceLocation: "",
        destinationLocation: "",
      },
      rules: {
        sourceLocation: [
          {
            required: true,
            message: "请输入移出库位",
            trigger: ["blur", "change"],
          },
        ],
        destinationLocation: [
          {
            required: true,
            message: "请输入移入库位",
            trigger: ["blur", "change"],
          },
        ],
      },
    };
  },
  watch: {
    showtrans() {
      this.visible = this.showtrans;
    },
  },
  methods: {
    diaOpen() {
      this.resetForm("ruleForm");
    },
    submitForm() {
      this.$refs["ruleForm"].validate((valid) => {
        if (valid) {
          createTransferTask(this.ruleForm).then((response) => {
            if (response.code === 200) {
              this.msgSuccess("移库成功");
              this.visible = false;
            } else {
              this.msgError(response.msg);
            }
          });
        } else {
          return false;
        }
      });
    },
    cancel() {
      this.resetForm("ruleForm");
      this.visible = false;
    },
  },
};
</script>