<template>
  <div>
    <base-dialog :closeEscape="true" :showClose="false" :closeModal="false" @handleConfirmClick="choiceHandleConfirm"
      :dialogVisible.sync="choiceDialog" class="userDialog" :title="projectName" width="70%" top="10vh"
      :footerShow="true">
        <div v-loading="loading">
          <base-form
            ref="customForm"
            :formRow="topFormRow"
            style="padding: 10px 0"
            justifyContent="flex-end"
            :rules="rules"
            :isFunBtn="false"
            @elDialogClick="elDialogClick"
          >
          </base-form>
          <assembly ref="assembly" ></assembly>
        </div>
    </base-dialog>
  </div>
</template>

<script>
import baseDialog from "@/components/base/BaseNewDialog/index.vue";
import baseForm from "@/components/base/baseNewForm/index.vue";
import assembly from "./assembly"
import configData from "./configData";
import { SaveData } from '@/api/apis/bugManage'
export default {
  data() {
    return {
      choiceDialog: false,
      topFormRow: configData.Editor,
      rules: configData.rules,
      sourceData: [],
      stateData: [],
      loading: false,
    };
  },

  components: {
    baseDialog,
    baseForm,
    assembly
  },

  props: {
    projectName: {
      type: [Number, String],
			default: true
    },
    documentId: {
      type: [Number, String],
			default: true
    }
  },

  computed: {},

  mounted() {},

  mounted() {},

  methods: {
    choiceHandleConfirm() {
      this.$refs.customForm.$refs["ruleForm"].validate((valid) => {
        if (valid) {
          this.submitTo();
        } else {
          return;
        }
      });
    },
    async submitTo() {
      if (this.$refs.assembly.content == null || this.$refs.assembly.content == "") {
        this.$message({
          message: `文本编辑器内内容不能为空`,
          type: "warning",
        });
        return
      }
      const res = await SaveData({
        dataMain: {
          billid: "00000000-0000-0000-0000-000000000000",
          projectID: this.documentId,
          ...this.$refs.customForm.ruleForm,
          content: this.$refs.assembly.content,
        }
      })
      if (res.code == 1) {
        this.choiceDialog = false
        this.$message({
          message: "保存成功",
          type: "success",
        });
        this.$emit('renew');
      }
    },
    elDialogClick() {}
  },
};
</script>
<style scoped lang="scss">

</style>
