<template>
  <audit-form-top-banner>
    <sd-detail-form
      ref="docform"
      page-id="audit/work/operate/find/iamAuditDiscover"
      :record-id="this.$route.query.record ? parseInt(this.$route.query.record) : null"
      :class="[$style.form, 'readonlyform']"
      read-only="true"
    >
      <template v-slot="{ model, fields }">
        <table
          ><tr
            ><td style="border:none;padding-left:5px">
              <audit-advanced-group
                :expand="basicExpand"
                :expand-str="'basicExpand'"
                :group-label="'基本信息'"
                tablestyle="''"
                @changedClick="changedClick"
              ></audit-advanced-group> </td></tr
        ></table>

        <table>
          <colgroup>
            <col style="width: 15%;"/>
            <col style="width: 35%;"/>
            <col style="width: 15%;"/>
            <col style="width: 35%;"
          /></colgroup>
          <tr v-show="basicExpand">
            <!-- 项目id -->
            <sd-form-item-td :hidden="true" name="projectId" />
            <!-- 底稿id -->
            <sd-form-item-td :hidden="true" name="paperId">
              <span>{{ model.paperId }}</span>
            </sd-form-item-td>
            <!-- 审计发现标题 -->
            <sd-form-item-td name="findTitle" :colspan="3" />
          </tr>
          <tr v-show="basicExpand">
            <!-- 审计发现编号 -->
            <sd-form-item-td name="findCode" />
            <!-- 被审计单位 -->
            <sd-form-item-td name="auditedUnitNames" />
            <!-- 被审计单位id -->
            <sd-form-item-td :hidden="true" name="auditedUnitIds" />
          </tr>
          <tr v-show="basicExpand">
            <!-- 审计发现描述 -->
            <sd-form-item-td name="findDesc" :colspan="3" />
          </tr>
          <tr v-show="basicExpand">
            <!-- 审计发现类别 -->
            <sd-form-item-td name="findType">
              <template v-slot:read-and-edit="{ editable }">
                {{ JSON.parse(model.findType).text }}
              </template>
            </sd-form-item-td>
            <!-- 审计建议类型 -->
            <sd-form-item-td name="suggestionType" />
          </tr>
          <tr v-show="basicExpand">
            <!-- 审计建议描述 -->
            <sd-form-item-td name="suggestion" :row="3" :colspan="3" />
          </tr>

          <tr v-show="basicExpand">
            <!-- 对应审计步骤 -->
            <sd-form-item-td name="stepName" />
            <!-- 问题类型 -->
            <sd-form-item-td name="problemType" />
          </tr>
          <tr v-show="basicExpand">
            <!-- 问题责任部门 -->
            <sd-form-item-td name="responsibleDept" />
            <!-- 风险评级 -->
            <sd-form-item-td name="riskLevel" />
          </tr>
          <tr v-show="basicExpand">
            <!-- 所属业务域 -->
            <sd-form-item-td name="businessProcess" />
            <!-- 是否问责 -->
            <sd-form-item-td name="whetherOrderDuty" />
          </tr>
          <tr v-show="basicExpand">
            <!-- 问责要求 -->
            <sd-form-item-td name="orderDutyAsk" :colspan="3" />
          </tr>
          <tr v-show="basicExpand">
            <!-- 备注 -->
            <sd-form-item-td name="findRemark" :colspan="3" />
          </tr>
          <tr
            ><td :colspan="4">
              <sd-form-item :label="null" name="iamAuditDiscoverMoneyEntitys">
                <template v-slot:read-and-edit="{ editable }">
                  <audit-advanced-group
                    :expand="moneyExpand"
                    :expand-str="'moneyExpand'"
                    :group-label="'问题涉及金额列表'"
                    tablestyle="''"
                    @changedClick="changedClick"
                    ><template>
                      <sd-child-table
                        v-show="moneyExpand"
                        ref="moneyData"
                        v-model="model.iamAuditDiscoverMoneyEntitys"
                        :class="$style.deptPlanChild"
                        :label="null"
                        :colspan="8"
                        :columns="moneycolumns"
                        name="iamAuditDiscoverMoneyEntitys"
                        :fields="
                          Array.from(fields.iamAuditDiscoverMoneyEntitys.attr.dync).slice(0, 3)
                        "
                        :read-only="true"
                        @change="changetable"
                      >
                        <!-- input-form 表示这部分是子表组件的form插槽 -->
                        <template v-slot:form="{ model }">
                          <table>
                            <tr><sd-form-item-td name="projectId" :hidden="true"/></tr>
                            <tr><sd-form-item-td name="findId" :hidden="true"/></tr>
                            <tr><sd-form-item-td name="sortNum" :hidden="true"/></tr>
                            <tr><sd-form-item-td name="id" :hidden="true"/></tr>
                            <tr><sd-form-item-td name="assetType"/></tr>
                            <tr><sd-form-item-td name="amount"/></tr>
                          </table>
                        </template> </sd-child-table></template
                  ></audit-advanced-group>
                </template> </sd-form-item
            ></td>
          </tr>
          <tr v-show="moneyExpand">
            <sd-form-item-td :label="null" name="reservestring1" :colspan="8">
              <template v-slot:read-and-edit="{ editable }">
                <table style="width:100%">
                  <tr
                    ><td
                      style="width:80px;border:none"
                      class="ant-form-item-label ant-form-item-label"
                    ></td
                    ><td
                      style="width:50%;border:none;"
                      class="ant-form-item-label ant-form-item-label"
                      ><label title="合计" class=""> 合计 </label></td
                    ><td style="border:none;border-left:1px solid #e8e8e8;"
                      ><span>{{ model.reservestring1 }}</span></td
                    ></tr
                  >
                </table>
              </template>
            </sd-form-item-td>
          </tr>
          <tr
            ><td :colspan="4">
              <sd-form-item :label="null" name="iamAuditDiscoverRuleEntitys">
                <template v-slot:read-and-edit="{ editable }">
                  <audit-advanced-group
                    :expand="ruleExpand"
                    :expand-str="'ruleExpand'"
                    :group-label="'相关法规制度条文'"
                    tablestyle="''"
                    @changedClick="changedClick"
                    ><template>
                      <sd-child-table
                        v-show="ruleExpand"
                        ref="ruleData"
                        v-model="model.iamAuditDiscoverRuleEntitys"
                        :class="$style.deptPlanChild"
                        :label="null"
                        :colspan="8"
                        :columns="rulecolumns"
                        :read-only="true"
                        name="iamAuditDiscoverRuleEntitys"
                        :fields="
                          Array.from(fields.iamAuditDiscoverRuleEntitys.attr.dync).slice(0, 4)
                        "
                        @change="changetable"
                      >
                        <!-- input-form 表示这部分是子表组件的form插槽 -->
                        <template v-slot:form="{ model }">
                          <table>
                            <tr><sd-form-item-td name="projectId" :hidden="true"/></tr>
                            <tr><sd-form-item-td name="findId" :hidden="true"/></tr>
                            <tr><sd-form-item-td name="sortNum" :hidden="true"/></tr>
                            <tr><sd-form-item-td name="id" :hidden="true"/></tr>
                            <tr><sd-form-item-td name="ruleName"/></tr>
                            <tr><sd-form-item-td name="ruleNumber"/></tr>
                            <tr><sd-form-item-td name="ruleContent"/></tr>
                          </table>
                        </template> </sd-child-table></template
                  ></audit-advanced-group>
                </template> </sd-form-item
            ></td>
          </tr>
          <tr
            ><td :colspan="4">
              <sd-form-item :label="null" name="iamWorkDiscoverEvidenceEntitys">
                <template v-slot:read-and-edit="{ editable }">
                  <audit-advanced-group
                    :expand="evidenceExpand"
                    :expand-str="'evidenceExpand'"
                    :group-label="'审计取证单列表'"
                    tablestyle="''"
                    @changedClick="changedClick"
                    ><template>
                      <sd-child-table
                        v-show="evidenceExpand"
                        ref="evidenceData"
                        v-model="model.iamWorkDiscoverEvidenceEntitys"
                        :read-only="true"
                        :class="$style.deptPlanChild"
                        :label="null"
                        :colspan="8"
                        :columns="evidencecolumns"
                        name="iamWorkDiscoverEvidenceEntitys"
                        :fields="
                          Array.from(fields.iamWorkDiscoverEvidenceEntitys.attr.dync).slice(0, 4)
                        "
                        @change="changetable"
                      >
                      </sd-child-table></template
                  ></audit-advanced-group>
                </template> </sd-form-item
            ></td>
          </tr>
        </table>
      </template>
    </sd-detail-form>
  </audit-form-top-banner>
</template>

<script>
import { Message } from 'ant-design-vue'
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 AuditOperatePaperService from '../paper/audit-operate-paper-service'
import auditAdvancedGroupMixins from '../../../../components/audit-advanced-group-mixins'
import components from './_import-components/iam-operate-find-detail-form-import'
const moneycolumns = [
  {
    title: '序号',
    dataIndex: 'sortNum',
    customRender: (text, record, index) => `${index + 1}`,
    width: '80px',
  },
  {
    title: '问题金额性质',
    dataIndex: 'assetType',
    width: '50%',
  },
  {
    title: '问题金额（万元）',
    dataIndex: 'amount',
  },
]
const rulecolumns = [
  {
    title: '序号',
    dataIndex: 'sortNum',
    customRender: (text, record, index) => `${index + 1}`,
    width: '80px',
  },
  {
    title: '标题',
    dataIndex: 'ruleName',
    width: '40%',
  },
  {
    title: '发文字号',
    dataIndex: 'ruleNumber',
    width: '15%',
  },
  {
    title: '条文',
    dataIndex: 'ruleContent',
  },
]
const evidencecolumns = [
  {
    title: '序号',
    dataIndex: 'sortNum',
    customRender: (text, record, index) => `${index + 1}`,
    width: '80px',
  },
  {
    title: '取证单名称',
    dataIndex: 'materialName',
  },
  {
    title: '取证单编号',
    dataIndex: 'materialCode',
    width: '200px',
  },
  {
    title: '附件',
    dataIndex: 'attachment',
  },
  {
    dataIndex: 'projectId',
    sdHidden: true,
  },
]
export default {
  name: 'IamOperateDetailFindForm',
  metaInfo: {
    title: '审计发现',
  },
  components: {
    ...components,
    auditFormTopBanner,
    auditAdvancedGroup,
    // SdDetailForm,
    // sd-form-item-td,
    // SdQuillEditor,
  },
  mixins: [auditAdvancedGroupMixins],
  data() {
    return {
      moneyExpand: true,
      basicExpand: true,
      ruleExpand: true,
      evidenceExpand: true,
      moneycolumns,
      rulecolumns,
      evidencecolumns,
      iamWorkDiscoverEvidenceEntitys: [],
      projectId: '',
      paperId: '',
    }
  },
  mounted() {},
  created() {
    let projectId = ''
    let paperId = ''
    if (this.$route.query.projectId) {
      projectId = this.$route.query.projectId
      if (projectId !== '' && projectId !== undefined) {
        this.projectId = projectId
      }
      paperId = this.$route.query.id
      if (paperId !== '' && paperId !== undefined) {
        this.paperId = paperId
      }
      if (projectId !== '' && projectId !== undefined && paperId !== '' && paperId !== undefined) {
        this.getPaperDiscord(this.projectId, this.paperId)
      }
    }
  },
  methods: {
    getPaperDiscord(projectId, paperid) {
      // 获取取证列表
      const params = { docStatus: '已结束', projectId: this.projectId, paperId: paperid }
      AuditOperatePaperService.getAuditGetPaperFind(params).then((res) => {
        console.log(res)
      })
    },
    // 保存
    saveForm() {
      if (this.projectId !== '' && this.projectId !== undefined) {
        this.$refs.docform.setFieldValue('projectId', this.projectId)
      }
      if (this.paperId !== '' && this.paperId !== undefined) {
        this.$refs.docform.setFieldValue('paperId', this.paperId)
      }
      this.$refs.docform.saveBtnClick()
    },
    close(flag) {
      crossWindowWatcher.notifyChange(this.$route.fullPath, flag)
      window.close()
    },
    saved() {
      Message.success('保存成功', 1).then((res) => {
        this.close(true)
      })
    },
    changetable(data) {
      data.forEach((item, index) => {
        item.sortNum = index + 1
      })
    },
  },
}
</script>

<style module lang="scss">
@import '@/webflow/sd-flow-form.scss';
.ant-card-body {
  padding: 12px;

  :global(.buttons_sd-detail-form_common) {
    :global(.ant-form-item-control-wrapper) {
      padding-left: 24%;
      padding-top: 4%;
    }
  }

  .tr_border {
    box-sizing: border-box;
    border-right: 1px solid #e8e8e8;
    border-left: 1px solid #e8e8e8;
  }

  :global(.title_sd-detail-form_common) {
    font-size: 1.5em;
    text-align: center;
  }
}
</style>
