<template>
  <div :class="$style.delayForm">
    <audit-form-top-banner :handel-save-form="saveForm" @handelSaveForm="saveForm">
      <div :class="$style.titleHide">
        <sd-detail-form
          ref="docform"
          form-id="iamQuestionInventory"
          page-id="audit/question/iamQuestionInventory"
          :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="border:none;padding-left:5px" v-show="initDate(model,fields)">
                  <audit-advanced-group
                    :expand="trackExpand"
                    :expand-str="'trackExpand'"
                    :group-label="'整改跟踪基本信息'"
                    tablestyle="''"
                    @changedClick="changedClick"
                  ></audit-advanced-group>
                </td>
              </tr>
            </table>

            <table v-show="trackExpand">
              <colgroup>
                <col style="width: 180px;"/>
                <col />
                <col style="width: 180px;"/>
                <col
              /></colgroup>
              <tr>
                <!-- 项目名称 -->
                <sd-form-item-td name="projectName">{{ model.projectName }}</sd-form-item-td>
                <!-- 项目来源 -->
                <sd-form-item-td name="projectSource">{{ model.projectSource }}</sd-form-item-td>
              </tr>
              <tr>
                <!-- 项目编号 -->
                <sd-form-item-td name="projectCode">{{ model.projectCode }}</sd-form-item-td>
                <!-- 整改责任主体 -->
                <sd-form-item-td name="auditedUnitName">{{
                  model.auditedUnitName
                }}</sd-form-item-td>
              </tr>
              <tr>
                <!-- 整改责任主体联系人 -->
                <sd-form-item-td name="auditedContactsName">{{
                  model.auditedContactsName
                }}</sd-form-item-td>
                <!-- 整改跟踪人 -->
                <sd-form-item-td name="resppersonsName">{{
                  model.resppersonsName
                }}</sd-form-item-td>
              </tr>
              <tr>
                <!-- 整改计划反馈截止日期 -->
                <sd-form-item-td name="expectFinishDate" :colspan="3">{{
                  model.expectFinishDate
                }}</sd-form-item-td>
              </tr>
              <tr>
                <!-- 整改要求 -->
                <sd-form-item-td name="requirement" :colspan="3">{{
                  model.requirement
                }}</sd-form-item-td>
              </tr>
              <!-- 整改要求附件 -->
              <tr>
                <sd-form-item-td name="rectattach" :colspan="3">
                  <template v-slot:read-and-edit="{ editable }">
                    <sd-attachment
                      v-model="model.rectattach"
                      :group-id="JSON.parse(fields.rectattach.value).value"
                      :read-only="true"
                    />
                  </template>
                </sd-form-item-td>
              </tr>
            </table>

            <table>
              <tr>
                <td style="border:none;padding-left:5px">
                  <audit-advanced-group
                    :expand="findExpand"
                    :expand-str="'findExpand'"
                    :group-label="'审计发现_基本信息'"
                    tablestyle="''"
                    @changedClick="changedClick"
                  ></audit-advanced-group>
                </td>
              </tr>
            </table>

            <table v-show="findExpand">
              <colgroup>
                <col style="width: 180px;"/>
                <col />
                <col style="width: 180px;"/>
                <col
              /></colgroup>
              <tr>
                <!-- 审计发现标题 -->
                <sd-form-item-td name="findingTitle">{{ model.findingTitle }}</sd-form-item-td>
                <!-- 审计发现编号 -->
                <sd-form-item-td name="findingCode">{{ model.findingCode }}</sd-form-item-td>
              </tr>
              <tr>
                <!-- 审计发现类别 -->
                <sd-form-item-td name="findType" :colspan="3">
                  <template v-slot:read-and-edit="{ editable }">
                    {{ fngetjson(model.findType) }}
                  </template>
                </sd-form-item-td>
              </tr>
              <tr>
                <!-- 审计发现描述 -->
                <sd-form-item-td name="findDesc" :colspan="3">{{ model.findDesc }}</sd-form-item-td>
              </tr>
              <tr>
                <!-- 审计建议描述 -->
                <sd-form-item-td name="suggestion" :colspan="3">{{
                  model.suggestion
                }}</sd-form-item-td>
              </tr>
              <tr>
                <!-- 问题责任部门 -->
                <sd-form-item-td name="responsibleDeptName">{{
                  model.responsibleDeptName
                }}</sd-form-item-td>
                <!-- 所属业务域 -->
                <sd-form-item-td name="businessProcess" ></sd-form-item-td>
              </tr>
              <tr>
                <!-- 是否问责 -->
                <sd-form-item-td name="whetherOrderDuty"></sd-form-item-td>
                <!-- 问责要求 -->
                <sd-form-item-td name="orderDutyAsk">{{ model.orderDutyAsk }}</sd-form-item-td>
              </tr>
            </table>

            <table>
              <tr>
                <td style="border:none;padding-left:5px">
                  <audit-advanced-group
                    :expand="rectplanExpand"
                    :expand-str="'rectplanExpand'"
                    :group-label="'审计发现_整改计划信息'"
                    tablestyle="''"
                    @changedClick="changedClick"
                  ></audit-advanced-group>
                </td>
              </tr>
            </table>

            <table v-show="rectplanExpand">
              <colgroup>
                <col style="width: 180px;"/>
                <col />
                <col style="width: 180px;"/>
                <col
              /></colgroup>
              <tr>
                <!-- 整改责任部门 -->
                <sd-form-item-td name="responsibleDeptName">{{
                  model.responsibleDeptName
                }}</sd-form-item-td>
                <!-- 直接责任人 -->
                <sd-form-item-td name="directResponsible">{{
                  model.directResponsible
                }}</sd-form-item-td>
              </tr>
              <tr>
                <!-- 领导责任人 -->
                <sd-form-item-td name="leaderResponsible">{{
                  model.leaderResponsible
                }}</sd-form-item-td>
                <!-- 共同责任部门 -->
                <sd-form-item-td name="commonDutyDepart">{{
                  model.commonDutyDepart
                }}</sd-form-item-td>
              </tr>
              <tr>
                <!-- 拟整改完成日期 -->
                <sd-form-item-td name="finishDate" :colspan="3">{{
                  model.finishDate | sdDateFormat('YYYY-MM-DD')
                }}</sd-form-item-td>
              </tr>
              <tr>
                <!-- 拟整改措施 -->
                <sd-form-item-td name="measure" :colspan="3">{{ model.measure }}</sd-form-item-td>
              </tr>
              <tr>
                <!-- 说明 -->
                <sd-form-item-td name="remark" :colspan="3">{{ model.remark }}</sd-form-item-td>
              </tr>
            </table>

            <table>
              <tr>
                <td style="border:none;padding-left:5px">
                  <audit-advanced-group
                    :expand="delayExpand"
                    :expand-str="'delayExpand'"
                    :group-label="'审计发现_延期申请'"
                    tablestyle="''"
                    @changedClick="changedClick"
                  ></audit-advanced-group>
                </td>
              </tr>
            </table>

            <table v-show="delayExpand">
              <colgroup>
                <col style="width: 180px;"/>
                <col />
                <col style="width: 180px;"/>
                <col
              /></colgroup>
              <sd-form-item-td name="findingId" :hidden="true" />
              <tr>
                <!-- 申请延至日期 -->
                <sd-form-item-td name="delayDate" :colspan="3" />
              </tr>
              <tr>
                <!-- 申请延期说明 -->
                <sd-form-item-td name="delayDesc" :colspan="3">
                  <a-textarea v-model="model.delayDesc" />
                </sd-form-item-td>
              </tr>
              <tr>
                <!-- 延期后整改措施 -->
                <sd-form-item-td name="rectifyStep" :colspan="3">
                  <a-textarea v-model="model.rectifyStep" />
                </sd-form-item-td>
              </tr>
              <tr>
                <!-- 附件 -->
                <sd-form-item-td name="attachment" :colspan="3" />
              </tr>
            </table>
          </template>
        </sd-detail-form>
      </div>
    </audit-form-top-banner>
  </div>
</template>

<script>
import { Message } from 'ant-design-vue'
import axios from '@/common/services/axios-instance'
import crossWindowWatcher from '@/common/services/cross-window-watcher'
import auditFormTopBanner from '../../components/audit-form-top-banner'
import auditAdvancedGroup from '../../components/audit-advanced-group.vue'
import auditAdvancedGroupMixins from '../../components/audit-advanced-group-mixins'
import components from './_import-components/audit-delay-form-import'

export default {
  name: 'AuditDelayForm',
  metaInfo: {
    title: '整改延期申请单',
  },
  components: {
    ...components,
    auditAdvancedGroup,
    auditFormTopBanner,
  },
  mixins: [auditAdvancedGroupMixins],
  data() {
    return {
      rectplanExpand: true,
      findExpand: true,
      trackExpand: true,
      delayExpand: true,
      flag:true,
    }
  },
  methods: {
    initDate(model,fields){
      if(this.flag){
      fields.businessProcess.readonly = true
      fields.whetherOrderDuty.readonly = true
        this.flag = false
      }
      return true
    },
    fngetjson(data) {
      if (data !== undefined || data !== '') {
        if (typeof JSON.parse(data) === 'object') {
          return JSON.parse(data).text
        } else {
          return data
        }
      } else {
        return ''
      }
    },
    close(flag) {
      crossWindowWatcher.notifyChange(this.$route.fullPath, flag)
      window.close()
    },
    // 保存
    saveForm() {
      const params = {
        plansubId: this.$route.query.record,
        delayDate: this.$refs.docform.getFieldValue('delayDate').valueOf(),
        delayDesc: this.$refs.docform.getFieldValue('delayDesc'),
        rectifyStep: this.$refs.docform.getFieldValue('rectifyStep'),
        attachment: JSON.parse(this.$refs.docform.SdForm.fields.attachment.value).value,
        findingId: this.$refs.docform.getFieldValue('findingId'),
      }
      this.$refs.docform.validateFields().then(() => {
        axios({
          url: 'api/xcoa-mobile/v1/iamquestioninventory/saveRectify',
          method: 'post',
          data: params,
        }).then((res) => {
          Message.success('保存成功').then(() => {
            this.saved()
          })
        })
      })
    },
    saved() {
      this.close(true)
    },
  },
}
</script>

<style module lang="scss">
@import '@/webflow/sd-flow-form.scss';
.titleHide {
  :global(.title_sd-detail-form_common) {
    display: none;
  }
}
.delayForm {
  width: 100%;
  height: 100%;
  :global(span.toptitle.toptitle_audit-form-top-banner_product::after) {
    content: '整改延期申请';
  }
  :global(span.toptitle.toptitle_audit-form-top-banner_product span) {
    display: none;
  }
}
</style>
