<template>
  <audit-form-top-banner :handel-save-form="hasLeaderAuthority === 'true' ? saveForm : null" @handelSaveForm="saveForm">
    <sd-detail-form
        ref="form"
        v-sd-watermark="waterMark"
        page-id="audit/work/projectcost/iamProjectCost"
        form-id="iamProjectAccount"
        :record-id="this.$route.query.record ? parseInt(this.$route.query.record) : null"
        :class="[$style.form]"
        :read-only="hasLeaderAuthority === 'false' "
        @close="close(true)"
        @saved="saved"
    >
      <template v-slot="{ model, fields }">
        <table>
          <tr>
            <!-- 文件标题 -->
            <sd-form-item-td name="title"/>
            <!-- 发生日期 -->
            <sd-form-item-td name="occurrenceDate"/>
          </tr>
          <tr>
            <!-- 财务科目 -->
            <sd-form-item-td name="financialSubjects"/>
            <!-- 费用金额 -->
            <sd-form-item-td name="costAmount">
              <a-input-number
                  v-model="model.costAmount"
                  :min="0"
                  :precision="2"
                  style="width: 100%;"
              ></a-input-number>
              <template v-slot:read>
                {{ model.costAmount === undefined ? model.costAmount : model.costAmount.toFixed(2) }}
              </template>
            </sd-form-item-td>
          </tr>
          <tr>
            <!-- 费用描述 -->
            <sd-form-item-td name="costDesc" :colspan="3">
              <sd-quill-editor
                  v-model="model.costDesc"
                  style=" z-index: -1000;"
                  :options="editorOption"
              />
              <template v-slot:read>
                <div class="ql-editor" v-html="model.costDesc"></div>
              </template>
            </sd-form-item-td>
          </tr>
          <tr>
            <!-- 附件 -->
            <sd-form-item-td name="attachment" :colspan="3">
              <template v-slot:read-and-edit="{ editable }">
                <sd-attachment
                    v-model="model.attachment"
                    :group-id="JSON.parse(fields.attachment.value).value"
                    :read-only="!editable"
                />
              </template>
            </sd-form-item-td>
          </tr>
          <tr>
            <!-- 编制人员ID -->
            <sd-form-item-td name="creatorName"/>
            <!-- 编制时间 -->
            <sd-form-item-td name="creationTime"/>
          </tr>
        </table>
      </template>
    </sd-detail-form>
  </audit-form-top-banner>
</template>

<script>
import {Message} from "ant-design-vue";
import systemManage from "@/system-manage/system-manage";
import auditFormTopBanner from "@product/iam/components/audit-form-top-banner";
import crossWindowWatcher from "@/common/services/cross-window-watcher";
import components from './_import-components/audit-projectcost-form-import'

export default {
  name: 'AuditProjectCostForm',
  metaInfo: {
    title: '项目费用',
  },
  components: {
    ...components,
    auditFormTopBanner,
  },
  data() {
    return {
      projectId: '',
      waterMark: systemManage.getFormWaterMark(),
      editorOption: {
        projectName: '',
        placeholder: '请从此处开始输入文本...',
      },
      hasLeaderAuthority: this.$route.query.hasLeaderAuthority,
    }
  },
  created() {
    const projectId = this.$route.query.projectId
    if (projectId) {
      this.projectId = projectId
    }
  },
  mounted() {
    // 初始化信息
    setTimeout(() => {
      this.initData()
    }, 1000)
  },
  methods: {
    initData() {
      this.$refs.form.setFieldValue('projectId', this.projectId)
    },
    saveForm() {
      this.$refs.form.saveBtnClick()
    },
    saved() {
      Message.success('保存成功', 1).then((res) => {
        this.close(true)
      })
    },
    close(flag) {
      crossWindowWatcher.notifyChange(this.$route.fullPath, flag)
      window.close()
    },
  },
}
</script>

<style module lang="scss">
@use '@/common/design' as *;
@import '@/webflow/sd-flow-form.scss';


</style>
