<template>
  <div :class="$style.wrapContent">
    <sd-webflow ref="flow" @actionBtnClick="handleBtnClick" @saveproject="afterSaveInfo">
      <template v-slot:form="{ model }">
        <table>
          <tr>
            <!-- 文件标题 -->
            <sd-form-item-td name="fileTitle" @keyup="setTitle(model)"/>
            <!-- 文件编号 -->
            <sd-form-item-td name="fileCode">
              <template v-slot:read-and-edit="{ editable }">
                <a-input
                    v-if="editable"
                    v-model="model.fileCode"
                    placeholder="自动生成"
                    :disabled="true"
                    read-only
                ></a-input>
                <span v-else>{{ model.fileCode }}</span>
              </template>
            </sd-form-item-td>
          </tr>
          <tr>
            <!-- 被审计单位 -->
            <sd-form-item-td name="auditedUnitIds" label="被审计单位"/>
            <!-- 文件类型 -->
            <sd-form-item-td name="fileType"/>
          </tr>
          <tr>
            <!-- 内容描述 -->
            <sd-form-item-td name="fileDesc" :colspan="3">
              <sd-quill-editor
                  v-model="model.fileDesc"
                  style=" z-index: -1000;"
                  :options="editorOption"
              />
              <template v-slot:read>
                <div class="ql-editor" v-html="model.fileDesc"></div>
              </template>
            </sd-form-item-td>
          </tr>
          <tr>
            <!-- 附件 -->
            <sd-form-item-td name="attachment" :colspan="3"/>
          </tr>
          <tr>
            <!-- 编制人员ID -->
            <sd-form-item-td name="creatorName"/>
            <!-- 编制时间 -->
            <sd-form-item-td name="creationTime"/>
          </tr>
        </table>
      </template>
    </sd-webflow>
  </div>
</template>

<script>
import AuditService from '@product/iam/audit/plan/audit-service'
import auditComdocumentService from "@product/iam/audit/work/projectmanage/comdocument/audit-comdocument-service";
import components from './_import-components/audit-comdocument-form-import'

export default {
  name: 'AuditComdocumentForm',
  metaInfo: {
    title: '综合文档',
  },
  components,
  data() {
    return {
      editorOption: {
        projectName: '',
        placeholder: '请从此处开始输入文本...',
      },
    }
  },
  created() {
  },
  mounted() {
    // 初始化表单信息
    this.initData()
  },
  methods: {
    // 初始化表单信息
    initData() {
      if (JSON.stringify(this.$route.query) !== '{}') {
        const projectId = JSON.parse(this.$route.query.extParams).projectId
        this.$refs.flow.setFieldValue('projectId', projectId)
        AuditService.getProjectInfoById(projectId).then((res) => {
          // 获取项目信息·
          if (res.data) {
            this.projectName = res.data.projectTitle
          }
        })
      }
    },
    actionBtnClick() {
    },
    setTitle(model) {
      this.$refs.flow.setFieldValue('title', this.projectName + '综合文档')
    },
    afterSaveInfo(flowData) {
      this.$refs.flow.setFieldValue('fileCode', flowData.processFormData.processFormPropertyValues[1].value)
    }
  },
}
</script>

<style module lang="scss">
@use '@/common/design' as *;
</style>
