<template>
  <!-- Form -->
  <el-dialog title="收货地址" :visible.sync="dialogFormVisible" width="30%">
    <el-form
      :model="ruleForm"
      :rules="rules"
      ref="ruleForm"
      label-width="100px"
      class="demo-ruleForm"
    >
      <el-form-item label="分区名称" prop="Name">
        <el-input v-model="ruleForm.Name"></el-input>
      </el-form-item>
      <el-form-item label="分区ID" prop="Id">
        <el-input v-model="ruleForm.Id"></el-input>
      </el-form-item>
      <el-form-item style="float: right; margin-top: 20px">
        <el-button @click="dialogFormVisible = false">取 消</el-button>
        <el-button type="primary" @click="submitForm('ruleForm')"
          >添 加</el-button
        >
      </el-form-item>
    </el-form>
  </el-dialog>
</template>

<script>
import logicConfig from "@/logicConfig";
import ScanController from "@/controller/old-adm/ScanController";
export default {
  name: "dialogZone",
  data() {
    return {
      dialogFormVisible: false,
      ruleForm: {
        Name: "",
        Id: "",
        ParentId: "OtherZone",
      },
      rules: {
        Name: [
          { required: true, message: "请输入分区名称", trigger: "blur" },
          // {min: 3, max: 5, message: '长度在 3 到 5 个字符', trigger: 'blur'}
        ],
        Id: [{ required: true, message: "请输入分区ID", trigger: "blur" }],
      },
    };
  },
  methods: {
    submitForm(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          let pa = {
            Content: [this.ruleForm],
          };
          ScanController.zoneCreateType(pa, (res) => {
            this.dialogFormVisible = false;
            switch (res.result) {
              case logicConfig.resultObj.success:
                this.$message.success("添加成功");
                this.ruleForm.Name = "";
                this.ruleForm.Id = "";
                this.$emit("createSuccess");
                break;
              default:
                this.$message.error("添加失败");
                break;
            }
          });
        } else {
          console.log("error submit!!");
          return false;
        }
      });
    },
  },
};
</script>

<style scoped>
</style>
