<template>
  <audit-form-top-banner :handel-save-form="saveForm" @handelSaveForm="saveForm">
    <sd-detail-form
      ref="form"
      form-id="iamAuditProject"
      page-id="audit/project/iamAuditProject"
      :record-id="this.$route.query.record ? parseInt(this.$route.query.record) : null"
      :class="$style.form"
      @close="close(true)"
      @saved="saved"
    >
      <template v-slot="{ model, fields }">
        <table>
          <tr>
            <td style="padding-left:5px;border:none">
              <audit-advanced-group
                :expand="score"
                :expand-str="'score'"
                :group-label="'基本信息'"
                tablestyle="''"
                @changedClick="changedClick"
              ></audit-advanced-group>
            </td>
          </tr>
        </table>

        <table v-show="score">
          <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">
              <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="projectPrincipalName" label="项目负责人">
              <span>{{ model.projectPrincipalName }}</span>
            </sd-form-item-td>
            <!-- 审计组长 -->
            <sd-form-item-td name="groupLeaderName" label="审计组长">
              <span>{{ model.groupLeaderName }}</span>
            </sd-form-item-td>
          </tr>
          <tr>
            <!-- 审计流程 -->
            <sd-form-item-td name="auditProcess">
              <template v-slot:read-and-edit="{ editable }">
                <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" />
            </sd-form-item-td>
          </tr>
          <tr>
            <!-- 编制人员 -->
            <sd-form-item-td name="editUser" />
            <!-- 编制日期 -->
            <sd-form-item-td name="editDate" />
          </tr>
        </table>
      </template>
    </sd-detail-form>
  </audit-form-top-banner>
</template>

<script>
import debounce from 'lodash.debounce'
import axios from '@/common/services/axios-instance'
import crossWindowWatcher from '@/common/services/cross-window-watcher'
import auditAdvancedGroup from '../../components/audit-advanced-group.vue'
import auditAdvancedGroupMixins from '../../components/audit-advanced-group-mixins'
import auditFormTopBanner from '../../components/audit-form-top-banner'
import components from './_import-components/audit-project-score-import'

export default {
  name: 'AuditProjectScore',
  metaInfo: {
    title: '项目评价',
  },
  components: {
    ...components,
    auditAdvancedGroup,
    auditFormTopBanner,
  },
  mixins: [auditAdvancedGroupMixins],
  data() {
    return {
      score: true,
    }
  },
  mounted() {
    // 初始化数据字典信息
    this.initDictionaryInfo()
  },
  methods: {
    saved() {
      this.close(true)
    },
    close(flag) {
      crossWindowWatcher.notifyChange(this.$route.fullPath, flag)
      window.close()
    },
    // 保存
    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()
      }
    },
  },
}
</script>

<style module lang="scss">
@import '@/webflow/sd-flow-form.scss';
.wrapContent {
  padding-top: 20px;
}
</style>
