<template>
  <div>
    <a-spin :spinning="spinning">
      <sd-detail-form
        ref="form"
        v-sd-watermark="waterMark"
        page-id="audit/project/iamAuditProject"
        form-id="iamAuditProject"
        :record-id="this.$route.query.projectId ? parseInt(this.$route.query.projectId) : null"
        :class="$style.form"
        @saved="saved"
        @close="close(true)"
      >
        <template v-slot="{ model, fields }">
          <table>
            <tr>
              <sd-form-item-td name="projectTitle">
                <span>{{ model.projectTitle }}</span>
              </sd-form-item-td>
              <sd-form-item-td name="projectCode">
                <span>{{ model.projectCode }}</span>
              </sd-form-item-td>
            </tr>
            <tr>
              <sd-form-item-td name="auditType">
                <span>{{ fields.auditType.attr.displayValue }}</span>
              </sd-form-item-td>
              <sd-form-item-td name="auditedUnitNames">
                <span>{{ model.auditedUnitNames }}</span>
              </sd-form-item-td>
            </tr>
            <tr>
              <sd-form-item-td name="auditMode" :colspan="3">
                <span>{{ fields.auditMode.attr.displayValue }}</span>
              </sd-form-item-td>
              <!-- <sd-form-item-td name="auditBasis">
                <span>{{ fields.auditBasis.attr.displayValue }}</span>
              </sd-form-item-td> -->
            </tr>
            <tr class="bklabeloverflow">
              <!-- 总部板块/二级单位审计部门负责人 -->
              <sd-form-item-td name="projectPrincipalId" label="项目负责人">
                <span>{{ fields.projectPrincipalId.attr.displayValue }}</span>
              </sd-form-item-td>
              <sd-form-item-td name="groupLeaderId">
                <span>{{ fields.groupLeaderId.attr.displayValue }}</span>
              </sd-form-item-td>
            </tr>
            <tr>
              <sd-form-item-td name="auditProcess">
                <template v-slot:read-and-edit>
                  <span>{{ JSON.parse(model.auditProcess)[0].name }}</span>
                </template>
              </sd-form-item-td>
              <sd-form-item-td name="auditperiodStart" :label="'审计期间'">
                <template v-slot:read-and-edit>
                  <span
                    >{{ fields.auditperiodStart.attr.displayValue }} ~
                    {{ fields.auditperiodEnd.attr.displayValue }}</span
                  >
                </template>
              </sd-form-item-td>
            </tr>
            <tr>
              <sd-form-item-td name="projectScore" :colspan="3">
                <a-form-model-item
                  :rules="[
                    {
                      validator: validator,
                      required: true,
                      trigger: ['change', 'blur'],
                    },
                  ]"
                  prop="projectScore"
                >
                  <a-input v-model="model.projectScore"></a-input
                ></a-form-model-item>
              </sd-form-item-td>
            </tr>
            <tr>
              <sd-form-item-td name="scoreContext" :colspan="3">
                <a-textarea v-model="model.scoreContext" :rows="3" @input="descInput" />
                <!-- <span>字数限制：{{ enter }}/1000</span> -->
              </sd-form-item-td>
            </tr>
            <tr>
              <sd-form-item-td name="editUser" />
              <sd-form-item-td name="editDate" />
            </tr>
            <tr>
              <td
                style="padding-top: 20px;margin-top: 20px;text-align: center;border:none"
                :colspan="4"
              >
                <a-button type="primary" @click="saveForm">保存</a-button>
              </td>
            </tr>
          </table>
        </template>
      </sd-detail-form>
    </a-spin>
  </div>
</template>

<script>
import { Message, Modal } from 'ant-design-vue'
import axios from '@/common/services/axios-instance'
import crossWindowWatcher from '@/common/services/cross-window-watcher'
import systemManage from '@/system-manage/system-manage'
import components from './_import-components/audit-projectscore-form-import'

export default {
  name: 'AuditProjectscoreForm',
  metaInfo: {
    title: '项目考评',
  },
  components,
  data() {
    return {
      // enter: 0,
      spinning: false,
      pageId: 'audit/project/iamAuditProject',
      projectId: '',
      projectStatus: '',
      waterMark: systemManage.getFormWaterMark(),
    }
  },
  methods: {
    // descInput() {
    //   debugger

    //   this.enter = this.$refs.form.getFieldValue('scoreContext').length
    //   if (this.enter > 1000) {
    //     Modal.error({
    //       title: '提示：最长可输入1000字符',
    //     })
    //   }
    // },
    saved() {
      this.spinning = false
      Message.success('保存成功', 1).then((res) => {
        this.$refs.form.resetWatchField()
      })
    },
    // 保存
    saveForm() {
      debugger
      var id = this.$refs.form.getFieldValue('id')
      if (id && id != null) {
        axios({
          url: `api/xcoa-mobile/v1/iamauditproject/score?id=` + id,
          method: 'get',
        }).then((res) => {
          if (res.status === 200) {
            if (res.data) {
              this.$refs.form.saveBtnClick()
            }
          }
        })
      } else {
        this.$refs.form.saveBtnClick()
      }
    },
    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';

:global(.title_sd-detail-form_common) {
  visibility: hidden;
}

.form {
  :global(.buttons_sd-detail-form_common) {
    visibility: hidden;
  }
}

.tablexm tr td {
  border: none !important;
}
</style>
