<template>
  <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
    <el-form ref="form" :model="form" :rules="rules" label-width="80px">
      <el-form-item label="隐患所属机构" prop="orgId">
        <el-input v-model="form.orgId" placeholder="请输入隐患所属机构" />
      </el-form-item>
      <el-form-item label="隐患所属机构名称" prop="orgName">
        <el-input v-model="form.orgName" placeholder="请输入隐患所属机构名称" />
      </el-form-item>
      <el-form-item label="隐患所属机构path" prop="orgPath">
        <el-input v-model="form.orgPath" placeholder="请输入隐患所属机构path" />
      </el-form-item>
      <el-form-item label="来源任务id" prop="srcTaskId">
        <el-input v-model="form.srcTaskId" placeholder="请输入来源任务id" />
      </el-form-item>
      <el-form-item label="来源任务名称" prop="srcTaskName">
        <el-input v-model="form.srcTaskName" placeholder="请输入来源任务名称" />
      </el-form-item>
      <el-form-item label="检查内容">
        <editor v-model="form.checkContent" :min-height="192" />
      </el-form-item>
      <el-form-item label="隐患描述" prop="questionDesc">
        <el-input v-model="form.questionDesc" placeholder="请输入隐患描述" />
      </el-form-item>
      <el-form-item label="提出人id" prop="submitorId">
        <el-input v-model="form.submitorId" placeholder="请输入提出人id" />
      </el-form-item>
      <el-form-item label="提出人名称" prop="submitorName">
        <el-input v-model="form.submitorName" placeholder="请输入提出人名称" />
      </el-form-item>
      <el-form-item label="发现时间" prop="submitTime">
        <el-date-picker
          clearable
          v-model="form.submitTime"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择发现时间"
        >
        </el-date-picker>
      </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>
export default {
  data() {
    return {
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 表单参数
      form: {},
      // 表单校验
      rules: {},
    };
  },
  methods:{
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        orgId: null,
        orgName: null,
        orgPath: null,
        srcType: null,
        srcTaskId: null,
        srcTaskName: null,
        checkContent: null,
        questionDesc: null,
        submitorId: null,
        submitorName: null,
        submitTime: null,
        confirmStatus: null,
        reformStatus: null,
        createTime: null,
        updateTime: null,
        createBy: null,
        updateBy: null
      };
      this.resetForm("form");
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateQuestion(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addQuestion(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加隐患问题清单";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getQuestion(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改隐患问题清单";
      });
    },
  }
};
</script>
