<template>
  <div>
    <el-form :model="dialogForm" ref="addForm" :rules="rules_check" label-width="80px" label-position="left">
      <el-form-item label="自评分数" prop="jddr_zp_score">
        <el-input v-model="dialogForm.jddr_zp_score" type="number" :min="0"></el-input>
      </el-form-item>
      <el-form-item label="自评" prop="jddr_zp_content">
        <el-input v-model="dialogForm.jddr_zp_content" type="textarea" rows="5"></el-input>
        <!-- <Tinymce v-if="dialogFormVisible" v-model="dialogForm.jddr_zp_content" :height="300" :key="timestamp"></Tinymce> -->
      </el-form-item>
      <el-form-item label="佐证材料" prop="jddr_zzcl_json">
        <FileUpload v-if="showUpload" :full.sync="dialogForm.jddr_zzcl_json" :key="timestamp" multiple></FileUpload>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
import { ddrwDetail, xfdxTjjlAdd, xfdxTjjlDetail, xfdxTjjlEdit } from "../api";
import Tinymce from "@/components/TinymceVue/index.vue";
import FileUpload from "@/components/FileUpload/index.vue";
import { useUserStore } from "@/stores/user";
export default {
  data() {
    return {
      userInfo: useUserStore(),
      timestamp: Date.now(),
      showUpload: false,
      dialogForm: {
        jddr_zp_score: "",
        jddr_zp_content: "",
        jddr_zzcl_json: "",
      },
      rules_check: {
        jddr_zp_score: [{ required: true, message: '请填写自评分数', trigger: 'blur' }],
        jddr_zp_content: [{ required: true, message: '请填写自评', trigger: 'change' }],
        jddr_zzcl_json: [{ required: true, message: '选择佐证材料', trigger: 'submit' }],
      }
    }
  },
  props: ["parentId", "xfId", "currentId", "detailId", "dialogFormVisible"],
  watch: {
    detailId: {
      immediate: true,
      handler(val) {
        if (val == "") {
          this.resetForm();
        } else {
          this.initDetailInfo(val);
        }
      }
    }
  },
  components: { Tinymce, FileUpload },
  methods: {
    resetForm() {
      this.$refs.addForm && this.$refs.addForm.resetFields();

      this.showUpload = true;
    },
    async initDetailInfo(id) {
      let res = await xfdxTjjlDetail({ jddt_id: id });
      for (let key in this.dialogForm) {
        this.$set(this.dialogForm, key, res.one_info[key]);
      }
      this.showUpload = true;
    },
    commitData() {
      this.$refs.addForm.validate(async (valid) => {
        if (valid) {
          let data = {
            issubmit: '1',
            jdbg_dddx_ddrw_tjjl: {
              jddt_uo_id: this.userInfo.uo_id,
              jddt_uo_name: this.userInfo.uo_name,
              jdd_id: this.parentId,
              jddr_id: this.currentId || undefined,
              jddx_id: this.xfId,
              jddr_zp_score: this.dialogForm.jddr_zp_score,
              jddr_zp_content: this.dialogForm.jddr_zp_content,
              jddr_zzcl_json: this.dialogForm.jddr_zzcl_json,
              jddr_sh_status: "3"
            },
          };
          let obj = {};
          if (this.detailId == "") {
            obj = await xfdxTjjlAdd(data);
          } else {
            data = Object.assign({ jddt_id: this.detailId }, data);
            obj = await xfdxTjjlEdit(data);
          }
          if (obj) {
            this.$message.success("保存成功！");
            this.$emit("close", 1);
          }
        }
      })
    },
  }
}
</script>

<style>
</style>
