
<style scoped>
.user-panel {
  margin: 10px auto;
}
</style>
<template>
  <el-dialog
    :visible.sync="showDialog"
    :title="title"
    :modal-append-to-body="false"
    style="text-align: left"
    @close="closeDialog"
    :close-on-click-modal="false"
  >
    <div class="user-panel" v-loading="loading">
      <el-form
        ref="form"
        :model="formModel"
        :rules="ruleValidate"
        :label-width="'100px'"
      >
        <el-form-item label="" prop="id">
          <el-input
            v-model="formModel.id"
            placeholder="请输入"
            style="width: 300px"
          ></el-input>
        </el-form-item>
        <el-form-item label="" prop="createBy">
          <el-input
            v-model="formModel.createBy"
            placeholder="请输入"
            style="width: 300px"
          ></el-input>
        </el-form-item>
        <el-form-item label="" prop="createTime">
          <el-input
            v-model="formModel.createTime"
            placeholder="请输入"
            style="width: 300px"
          ></el-input>
        </el-form-item>
        <el-form-item label="" prop="updateBy">
          <el-input
            v-model="formModel.updateBy"
            placeholder="请输入"
            style="width: 300px"
          ></el-input>
        </el-form-item>
        <el-form-item label="" prop="updateTime">
          <el-input
            v-model="formModel.updateTime"
            placeholder="请输入"
            style="width: 300px"
          ></el-input>
        </el-form-item>
        <el-form-item label="删除标示" prop="delFlag">
          <el-input
            v-model="formModel.delFlag"
            placeholder="请输入删除标示"
            style="width: 300px"
          ></el-input>
        </el-form-item>
        <el-form-item label="用户ID" prop="jobUserId">
          <el-input
            v-model="formModel.jobUserId"
            placeholder="请输入用户ID"
            style="width: 300px"
          ></el-input>
        </el-form-item>
        <el-form-item label="审批人" prop="approvePersonId">
          <el-input
            v-model="formModel.approvePersonId"
            placeholder="请输入审批人"
            style="width: 300px"
          ></el-input>
        </el-form-item>
        <el-form-item label="审批时间" prop="approveTime">
          <el-input
            v-model="formModel.approveTime"
            placeholder="请输入审批时间"
            style="width: 300px"
          ></el-input>
        </el-form-item>
        <el-form-item label="审批状态" prop="approvalStatus">
          <el-input
            v-model="formModel.approvalStatus"
            placeholder="请输入审批状态"
            style="width: 300px"
          ></el-input>
        </el-form-item>
      </el-form>
    </div>
    <span slot="footer" class="dialog-footer">
      <el-button @click="closeDialog">取 消</el-button>
      <el-button type="primary" @click="handleSubmit" :loading="submitting"
        >确 定</el-button
      >
    </span>
  </el-dialog>
</template>
<script>
import Constant from "@/constant";
import userAuthenticationApproveApi from "@/api/base/userAuthenticationApprove";

export default {
  props: ["businessKey", "title"],
  data() {
    return {
      formModel: {},
      ruleValidate: {
        id: [{ required: true, message: "不能为空", trigger: "blur" }],
        createBy: [{ required: true, message: "不能为空", trigger: "blur" }],
        createTime: [{ required: true, message: "不能为空", trigger: "blur" }],
        updateBy: [{ required: true, message: "不能为空", trigger: "blur" }],
        updateTime: [{ required: true, message: "不能为空", trigger: "blur" }],
        delFlag: [
          { required: true, message: "删除标示不能为空", trigger: "blur" },
        ],
        jobUserId: [
          { required: true, message: "用户ID不能为空", trigger: "blur" },
        ],
        approvePersonId: [
          { required: true, message: "审批人不能为空", trigger: "blur" },
        ],
        approveTime: [
          { required: true, message: "审批时间不能为空", trigger: "blur" },
        ],
        approvalStatus: [
          { required: true, message: "审批状态不能为空", trigger: "blur" },
        ],
      },
      showDialog: true,
      loading: false,
      submitting: false,
    };
  },
  methods: {
    closeDialog() {
      this.$emit("close", false);
    },
    handleSubmit() {
      var self = this;

      this.$refs["form"].validate((valid) => {
        if (valid) {
          (function () {
            var id = self.formModel.id;

            if (id == null || id.length == 0) {
              return userAuthenticationApproveApi.add(self.formModel);
            } else {
              return userAuthenticationApproveApi.update(self.formModel);
            }
          })().then(function (response) {
            var jsonData = response.data;

            if (jsonData.result) {
              self.$message({
                message: "保存成功!",
                type: "success",
              });

              self.$emit("close", true);
            } else {
              self.$message({
                message: jsonData.message + "",
                type: "warning",
              });

              self.$emit("close", false);
            }
          });
        }
      });
    },
  },
  mounted: function () {
    var self = this;

    (function () {
      if (self.businessKey.length == 0) {
        return userAuthenticationApproveApi.create();
      } else {
        return userAuthenticationApproveApi.edit(self.businessKey);
      }
    })()
      .then((response) => {
        var jsonData = response.data;
        self.loading = false;

        if (jsonData.result) {
          self.formModel = jsonData.data;
        } else {
          self.$message.error(jsonData.message + "");
        }
      })
      .catch((error) => {
        self.$message.error(error + "");
      });
  },
};
</script>