<template>
  <span>
    <audit-form-top-banner :handel-save-form="saveForm" @handelSaveForm="saveForm">
      <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"
        @close="close(true)"
        @saved="saved"
      >
        <template v-slot="{ model, fields }">
          <table
            ><tr
              ><td style="border:none">
                <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="false">
              <!-- id -->
              <sd-form-item-td :hidden="true" name="id" />
              <!-- 项目id -->
              <sd-form-item-td :hidden="true" name="projectId" />
            </tr>
            <tr v-show="false">
              <!-- 底稿id -->
              <sd-form-item-td :hidden="true" name="paperId" />
              <!-- 被审计单位id -->
              <sd-form-item-td :hidden="true" name="auditedUnitIds" />
            </tr>
            <tr v-show="basicExpand">
              <!-- 审计发现标题 -->
              <sd-form-item-td name="findTitle" :colspan="3">
                <a-input v-model="model.findTitle" style="width:calc(100% - 80px);" />
                <span style="padding:5px">
                  <a-button @click="showfind">选择</a-button>
                </span>
              </sd-form-item-td>
            </tr>
            <tr v-show="basicExpand">
              <!-- 审计发现编号 -->
              <sd-form-item-td name="findCode">
                <span>{{ model.findCode }}</span>
              </sd-form-item-td>
              <!-- 被审计单位 -->
              <sd-form-item-td name="auditedUnit" />
            </tr>
            <tr v-show="basicExpand">
              <!-- 审计发现描述 -->
              <sd-form-item-td name="findDesc" :colspan="3">
                <a-textarea
                  v-model="model.findDesc"
                  :auto-size="{ minRows: 3, maxRows: 3 }"
                ></a-textarea>
              </sd-form-item-td>
            </tr>
            <tr v-show="basicExpand">
              <!-- 审计发现类别 -->
              <sd-form-item-td name="findType">
                <a-input v-model="findType" read-only @click="showfindcat" />
                <a-input v-model="model.findType" :hidden="true" />
              </sd-form-item-td>
              <!-- 审计建议类型 -->
              <sd-form-item-td name="suggestionType" />
            </tr>
            <tr v-show="basicExpand">
              <!-- 审计建议描述 -->
              <sd-form-item-td name="suggestion" :colspan="3">
                <a-textarea
                  v-model="model.suggestion"
                  :auto-size="{ minRows: 3, maxRows: 3 }"
                ></a-textarea>
              </sd-form-item-td>
            </tr>

            <tr v-show="basicExpand">
              <!-- 对应审计步骤 -->
              <sd-form-item-td name="stepName">
                <a-input v-model="model.stepName" type="text" read-only @click="showstep(model)" />
              </sd-form-item-td>
              <!-- 问题类型 -->
              <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">
                <a-textarea v-model="model.orderDutyAsk" :auto-size="{ minRows: 3, maxRows: 3 }" />
              </sd-form-item-td>
            </tr>
            <tr v-show="basicExpand">
              <!-- 备注 -->
              <sd-form-item-td v-if="initParam(model)" name="findRemark" :colspan="3">
                <a-textarea v-model="model.findRemark" :auto-size="{ minRows: 3, maxRows: 3 }" />
              </sd-form-item-td>
            </tr>
            <tr
              ><td :colspan="4">
                <sd-form-item :label="null" name="iamAuditDiscoverMoneyEntitys">
                  <audit-advanced-group
                    :expand="moneyExpand"
                    :expand-str="'moneyExpand'"
                    :group-label="'问题涉及金额列表'"
                    tablestyle="''"
                    @changedClick="changedClick"
                    ><template>
                      <xm-child-table
                        v-show="moneyExpand"
                        ref="moneyData"
                        v-model="model.iamAuditDiscoverMoneyEntitys"
                        :class="$style.deptPlanChild"
                        :label="null"
                        :columns="moneycolumns"
                        :colspan="4"
                        name="iamAuditDiscoverMoneyEntitys"
                        :fields="
                          [
                            {
                              caption: '序号',
                              name: 'sortNum',
                              dataType: 'sortNum',
                            },
                          ].concat(
                            Array.from(fields.iamAuditDiscoverMoneyEntitys.attr.dync).slice(1, 3)
                          )
                        "
                        @change="changetablemoney"
                        @saved="changetablemoney"
                      >
                        <!-- 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="id" :hidden="true"/></tr>
                            <tr><sd-form-item-td name="assetType"/></tr>
                            <tr><sd-form-item-td name="amount"/></tr>
                          </table>
                        </template>
                      </xm-child-table> </template
                  ></audit-advanced-group> </sd-form-item
              ></td>
            </tr>
            <tr v-show="moneyExpand">
              <sd-form-item-td :label="null" name="reservestring1" :colspan="4">
                <template v-slot:read-and-edit="{ editable }">
                  <table style="width:100%">
                    <tr
                      ><td
                        v-if="editable"
                        style="width:60px;border:none"
                        class="ant-form-item-label ant-form-item-label"
                      ></td
                      ><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>
                        <template>
                          <div :class="$style.wrapper">
                            <div v-show="ruleExpand && editable" :class="$style.btnselect">
                              <a-button
                                type="link"
                                :class="$style.batchselect"
                                @click="lawsRelSelect"
                                ><a-icon type="check-circle" :theme="'filled'" />选择
                              </a-button>
                            </div>
                          </div>
                        </template>
                        <xm-child-table
                          v-show="ruleExpand"
                          ref="ruleData"
                          v-model="model.iamAuditDiscoverRuleEntitys"
                          :class="$style.deptPlanChild"
                          :label="null"
                          :colspan="4"
                          :columns="rulecolumns"
                          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> -->
                        </xm-child-table></template
                      ></audit-advanced-group
                    >
                  </template>
                </sd-form-item></td
              >
            </tr>
            <tr
              ><td :colspan="4">
                <sd-form-item :label="null" name="iamWorkDiscoverEvidenceEntitys">
                  <audit-advanced-group
                    :expand="evidenceExpand"
                    :expand-str="'evidenceExpand'"
                    :group-label="'审计取证单列表'"
                    tablestyle="''"
                    @changedClick="changedClick"
                    ><template>
                      <xm-paper-child-table
                        v-show="evidenceExpand"
                        ref="evidenceData"
                        v-model="model.iamWorkDiscoverEvidenceEntitys"
                        :class="$style.deptPlanChild"
                        :label="null"
                        :colspan="4"
                        name="iamWorkDiscoverEvidenceEntitys"
                        :columns="evidencecolumns"
                        :fields="
                          Array.from(fields.iamWorkDiscoverEvidenceEntitys.attr.dync).slice(0, 4)
                        "
                        :input-props="evidencecolumns"
                        :createvidence="showevidenceTable"
                        :evidencetable="true"
                        @change="changetable"
                      >
                      </xm-paper-child-table></template
                  ></audit-advanced-group> </sd-form-item
              ></td>
            </tr>
          </table>

          <!-- 选择导入模板 -->
          <a-modal
            :visible="evidencevisible"
            title="请选择"
            width="1200px"
            :body-style="{
              minHeight: '700px',
              overflowX: 'hidden',
            }"
            class="evidencechildmodal"
            :destroy-on-close="true"
            @ok="handleOk"
            @cancel="handleCancel"
          >
            <sd-data-table-ex
              ref="evidenceTable"
              class="evidencechildtable"
              check-type="checkbox"
              :filter-expressions="evidenceexpressions"
              :columns="evidencemodalcolumns"
              form-id="iamAuditEvidenceSheet"
              page-id="audit/evidence/iamAuditEvidenceSheet"
              :search-fields="[
                'itemTitle',
                'itemCode',
                'auditedUnitNames',
                'creatorName',
                'docStatus',
              ]"
              :show-selection="showSelection"
            >
            </sd-data-table-ex>
          </a-modal>
          <!-- 选择审计步骤模板 -->
          <a-modal
            :visible="stepnamevisible"
            title="请选择"
            width="1200px"
            :body-style="{
              minHeight: '700px',
            }"
            :destroy-on-close="true"
            @ok="handlestepOk"
            @cancel="handlestepCancel"
          >
            <sd-table
              ref="stepTable"
              :loading="false"
              class="stepnameTable"
              :columns="stepmodalcolumns"
              :data-source="steplist"
              :pagination="true"
              :bordered="true"
              :row-selection="{
                type: 'radio',
                selectedRowKeys: selectedRowKeys,
                onChange: onSelectChange,
              }"
            />
          </a-modal>
          <!-- 发现分类树 -->
          <a-modal
            :visible="findcatvisible"
            title="请选择"
            width="700px"
            :destroy-on-close="true"
            @ok="handlefindcatOk"
            @cancel="handlefindcatCancel"
          >
            <AuditFindCatTree @treeSelect="treeSelect" />
          </a-modal>
          <!-- 选择审计步骤模板 -->
          <a-modal
            :visible="findvisible"
            title="请选择"
            width="1200px"
            :body-style="{
              minHeight: '700px',
            }"
            :destroy-on-close="true"
            @ok="handlefindOk"
            @cancel="handlefindCancel"
          >
            <sd-data-table-ex
              ref="findTable"
              class="modalTable"
              check-type="radio"
              :filter-expressions="expressions"
              :columns="findcolumns"
              form-id="iamProblem"
              page-id="audit/auditsource/problem/iamProblem"
              :search-fields="['docTitle', 'problemNumber']"
              show-selection
            >
            </sd-data-table-ex>
          </a-modal>
        </template>
      </sd-detail-form>
    </audit-form-top-banner>
    <!-- 法律法规选择器 -->
    <audit-matters-select-modal
      :visible="visible"
      :org-id="null"
      :show-selection="showSelectionlaw"
      @listSelected="listSelected"
    ></audit-matters-select-modal>
  </span>
</template>

<script>
import { xmLocalStorage } from '@/common/services/storage-service'
import { Modal, Message } from 'ant-design-vue'
import crossWindowWatcher from '@/common/services/cross-window-watcher'
import axios from '@/common/services/axios-instance'
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 xmPaperChildTable from '../paper/table/xm-paper-child-table.vue'
import xmPaperChildTableMixins from '../paper/table/xm-paper-child-table-mixins'
import auditAdvancedGroupMixins from '../../../../components/audit-advanced-group-mixins'
import AuditFindCatTree from '../../../../components/audit-find-cat-tree.vue'
import AuditFindCatTreeMixins from '../../../../components/audit-find-cat-tree-mixins'
import auditMattersSelectModal from '../../../matters/audit-matters-select-modal.vue'
import components from './_import-components/iam-operate-find-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,
  },
]
const evidencemodalcolumns = [
  {
    title: '序号',
    dataIndex: 'sortNum',
    customRender: (text, record, index) => `${index + 1}`,
    width: '80px',
  },
  {
    title: '取证单名称',
    dataIndex: 'itemTitle',
  },
  {
    title: '取证单编号',
    dataIndex: 'itemCode',
    width: '30%',
  },
  {
    title: '附件',
    dataIndex: 'attachment',
    sdHidden: true,
  },
]
const stepmodalcolumns = [
  {
    title: '序号',
    dataIndex: 'sortNum',
    customRender: (text, record, index) => `${index + 1}`,
    width: '80px',
  },
  {
    title: '步骤',
    dataIndex: 'stepName',
  },
  {
    title: '重要性',
    dataIndex: 'importance',
    width: '100px',
  },
  {
    title: '是否执行',
    dataIndex: 'isExecited',
    width: '120px',
  },
]
const findcolumns = [
  {
    title: '序号',
    dataIndex: 'sortNum',
    customRender: (text, record, index) => `${index + 1}`,
    width: '80px',
  },
  {
    title: '问题标题',
    dataIndex: 'docTitle',
  },
  {
    title: '问题编号',
    dataIndex: 'problemNumber',
    width: '150px',
  },
  {
    title: '问题描述',
    dataIndex: 'problemDesc',
  },
  {
    title: '',
    dataIndex: 'iamAuditLawsRelEntitys',
    sdHidden: true,
  },
]
export default {
  name: 'IamOperateFindForm',
  metaInfo: {
    title: '审计发现',
  },
  components: {
    ...components,
    auditFormTopBanner,
    auditAdvancedGroup,
    xmPaperChildTable,
    AuditFindCatTree,
    auditMattersSelectModal,
  },
  mixins: [auditAdvancedGroupMixins, xmPaperChildTableMixins, AuditFindCatTreeMixins],
  data() {
    return {
      selectedRowKeys: [],
      moneyExpand: true,
      basicExpand: true,
      ruleExpand: true,
      evidenceExpand: true,
      moneycolumns,
      rulecolumns,
      evidencecolumns,
      iamWorkDiscoverEvidenceEntitys: [],
      projectId: '',
      paperId: '',
      evidencemodalcolumns,
      stepmodalcolumns,
      findcolumns,
      evidencevisible: false,
      expressions: [],
      units: [],
      findlist: [],
      steplist: [],
      stepnamevisible: false,
      findcatvisible: false,
      findvisible: false,
      findcat: '',
      findType: '',
      getflag: false,
      visible: false,
      evidenceexpressions: [],
      matterexpression: [],
      confirmsStatus: false,
      selectlist: [],
      isIni: false,
    }
  },
  created() {
    let projectId = ''
    let paperId = ''
    if (this.$route.query.projectId) {
      projectId = this.$route.query.projectId
      if (projectId !== '' && projectId !== undefined) {
        this.projectId = projectId
        this.evidenceexpressions.push({
          dataType: 'long',
          name: 'projectId',
          op: 'eq',
          longValue: this.projectId,
        })
        this.evidenceexpressions.push({
          dataType: 'str',
          name: 'docStatus',
          op: 'like',
          stringValue: `%已结束%`,
        })
      }
      paperId = this.$route.query.id
      if (paperId !== '' && paperId !== undefined) {
        this.paperId = paperId
      }
    }
  },
  methods: {
    showSelection(record) {
      if (this.selectlist.findIndex((i) => i === record.itemCode) === -1) {
        return true
      } else {
        return false
      }
    },
    showSelectionlaw(record) {
      this.selectlist = this.$refs.ruleData.value
      if (this.selectlist.length === 0) {
        return true
      } else if (
        this.selectlist.findIndex(
          (i) => i.ruleName + '-' + i.ruleNumber === record.docTitle + '-' + record.dispatchWord
        ) > -1
      ) {
        return false
      } else {
        return true
      }
    },
    initParam(model) {
      if (this.isIni) return true
      this.isIni = true
      // 设置父id
      if (!this.getflag) {
        var form = this.$refs.docform
        if (form.formData.mode) {
          this.fngetdata(model)
        }
      }
      return true
    },
    fngetdata(model) {
      if (this.$refs.docform) {
        // 获取当前发现文档是否已确认
        if (model.id) {
          axios({
            url: 'api/xcoa-mobile/v1/iam-audit-discover/needAffirm?id=' + model.id,
            method: 'get',
          }).then((res) => {
            this.confirmsStatus = res.data
          })
        }
        // const findcatstr = this.$refs.docform.getFieldValue('findType')
        const findcatstr = model.findType
        if (findcatstr !== '' && findcatstr !== undefined) {
          const findcatobj = JSON.parse(findcatstr)
          this.findType = findcatobj.text
        }
      }
      let flag = true // 默认是新建
      // 获取项目数据的 审计单位ID 和 工作底稿 对应审计步骤 和字典 审计发现列表
      if (this.projectId === '' || this.projectId === undefined) {
        flag = false
        this.projectId = model.projectId
        this.evidenceexpressions.push({
          dataType: 'long',
          name: 'projectId',
          op: 'eq',
          longValue: this.projectId,
        })
        this.evidenceexpressions.push({
          dataType: 'str',
          name: 'docStatus',
          op: 'like',
          stringValue: `%已结束%`,
        })
      }
      if (this.paperId === '' || this.paperId === undefined) {
        this.paperId = model.paperId
      }
      // 通过缓存获取步骤
      this.steplist = JSON.parse(xmLocalStorage.getItem('findPrograme'))

      if (flag) {
        axios({
          url: 'api/xcoa-mobile/v1/page/wp/audit/project/iamAuditProject?id=' + this.projectId,
          method: 'get',
        }).then((res) => {
          const obj = res.data.pageFormData.pageFieldInfos.find(
            (item) => item.name === 'auditedUnitIds'
          )
          if (obj !== null) {
            if (obj.value !== undefined) {
              this.units = JSON.parse(obj.value)
              this.units.forEach((item) => {
                item.id = item.code
              })
              // const fieldunit = this.$refs.docform.getFieldValue('auditedUnit')
              const fieldunit = model.auditedUnit
              if (fieldunit === '' || fieldunit === undefined) {
                setTimeout(() => {
                  this.$refs.docform.setFieldValue('auditedUnit', this.units)
                }, 1000)
              }
            }
          }
        })
      }
    },
    showfindcat() {
      this.findcatvisible = !this.findcatvisible
    },
    handlefindcatOk() {
      if (this.findcat !== '') {
        this.$refs.docform.setFieldValue('findType', JSON.stringify(this.findcat))
        this.showfindcat()
        this.findType = this.findcat.text
        this.findcat = ''
      } else {
        Modal.warning({
          title: '提示',
          content: '请选择分类!',
        })
        return false
      }
    },
    handlefindcatCancel() {
      this.showfindcat()
    },
    showstep(model) {
      if (model !== null && model !== undefined) {
        this.fngetdata(model)
      }
      this.stepnamevisible = !this.stepnamevisible
    },
    handlestepOk() {
      let stepname = ''
      this.selectedRowKeys.forEach((i) => {
        stepname = stepname + this.steplist[i - 1].stepName ? this.steplist[i - 1].stepName : ''
      })
      this.$refs.docform.setFieldValue('stepName', stepname)
      this.showstep()
    },
    handlestepCancel() {
      this.showstep()
    },

    // 展示选择列表
    showevidenceTable() {
      this.selectlist = []
      let list = []
      if (this.$refs.docform.getFieldValue('iamWorkDiscoverEvidenceEntitys')) {
        list = this.$refs.docform.getFieldValue('iamWorkDiscoverEvidenceEntitys')
      }
      list.forEach((l) => {
        if (l.materialCode) {
          this.selectlist.push(l.materialCode)
        }
      })
      this.evidencevisible = !this.evidencevisible
    },
    // 弹出窗确认
    handleOk() {
      this.showevidenceTable()
      // 获取别选择的行信息
      let list = []
      if (this.$refs.docform.getFieldValue('iamWorkDiscoverEvidenceEntitys')) {
        list = this.$refs.docform.getFieldValue('iamWorkDiscoverEvidenceEntitys')
      }
      const selectInfo = this.$refs.evidenceTable.getSelectedRows()
      let i = 1
      selectInfo.forEach((item) => {
        const mmc = {}
        mmc.materialName = item.itemTitle
        mmc.sortNum = i
        mmc.materialCode = item.itemCode
        mmc.projectId = this.projectId
        if (isNaN(item.attachment)) {
          mmc.attachment = item.attachment
        } else {
          mmc.attachment = JSON.stringify({ value: item.attachment })
        }
        i = i + 1
        list.push(mmc)
      })
      this.$refs.docform.setFieldValue('iamWorkDiscoverEvidenceEntitys', list)
      // const selectInfo = this.$refs.evidenceTable.getSelectedRows()
      // let i = 1
      // selectInfo.forEach((item) => {
      //   item.materialName = item.itemTitle
      //   item.materialCode = item.itemCode
      //   item.attachment = JSON.stringify({ value: item.attachment })
      //   item.projectId = this.projectId
      //   item.sortNum = i
      //   i = i + 1
      // })
      // this.$refs.docform.setFieldValue('iamWorkDiscoverEvidenceEntitys', selectInfo)
    },
    // 弹出窗取消
    handleCancel() {
      this.showevidenceTable()
    },
    showfind(model) {
      this.findvisible = !this.findvisible
    },
    handlefindOk() {
      const selectInfo = this.$refs.findTable.getSelectedRows()
      if (selectInfo.length === 1) {
        this.$refs.docform.setFieldValue('findTitle', selectInfo[0].docTitle)
        // this.$refs.docform.setFieldValue('findCode', selectInfo[0].problemNumber)
        this.$refs.docform.setFieldValue('suggestion', selectInfo[0].problemDesc)
        this.$refs.docform.setFieldValue(
          'iamAuditDiscoverRuleEntitys',
          selectInfo[0].iamAuditLawsRelEntitys.map((item) => {
            return {
              ruleName: item.lawsTitle,
              ruleNumber: item.lawsDocNumber,
              ruleContent: item.lawsArticle,
            }
          })
        )
        this.showfind()
      } else {
        Modal.warning({
          title: '提示',
          content: '请选择一个发现问题!',
        })
        return false
      }
    },
    handlefindCancel() {
      this.showfind()
    },
    // 保存
    saveForm() {
      this.$refs.moneyData.save().then((res) => {
        // 确认当前审计发现是否被确认，被确认则弹出提示
        const id = this.$refs.docform.getFieldValue('id')
        if (id !== undefined) {
          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)
          }
          AuditOperatePaperService.checkOperateFind(id).then((res) => {
            if (!res.data) {
              this.$refs.docform.saveBtnClick()
            } else {
              Modal.confirm({
                title: '审计发现已确认，请确认是否要修改？',
                content: '',
                okText: '确定',
                okType: 'danger',
                cancelText: '取消',
                onOk: () => {
                  axios({
                    url: 'api/xcoa-mobile/v1/iam-audit-discover/changeAffirm?id=' + id,
                    method: 'get',
                  }).then((res) => {
                    this.$refs.docform.saveBtnClick()
                  })
                },
                onCancel: () => {
                  this.$refs.docform.saveBtnClick()
                },
              })
            }
          })
        } else {
          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)
      })
    },
    onSelectChange(selectedRowKeys) {
      this.selectedRowKeys = selectedRowKeys
    },
    changetable(data) {
      data.forEach((item, index) => {
        item.sortNum = index + 1
      })
    },
    changetablemoney(data) {
      let money = 0
      data.forEach((item, index) => {
        // item.sortNum = index + 1
        if (item.amount !== undefined) {
          money = money + parseFloat(item.amount)
        }
      })
      this.$refs.docform.setFieldValue('reservestring1', this.getTotal(data).toString())
    },
    treeSelect(select, info) {
      if(info.node){
      this.findcat = info.node.dataRef
      }else{
        this.findcat = info
      }
      // this.$refs.docform.setFieldValue('paperId', this.findcat)
    },

    // 选择法律制度
    lawsRelSelect() {
      // 选择事项分类
      this.visible = true
    },
    listSelected(keys, keyinfos) {
      let iamAuditLaws = []
      if (this.$refs.docform.getFieldValue('iamAuditDiscoverRuleEntitys')) {
        iamAuditLaws = this.$refs.docform.getFieldValue('iamAuditDiscoverRuleEntitys')
      }
      keyinfos.forEach((element) => {
        const mmc = {}
        mmc.ruleName = element.docTitle
        mmc.ruleNumber = element.dispatchWord ? element.dispatchWord : ''
        mmc.ruleContent = ''
        iamAuditLaws.push(mmc)
      })
      this.visible = false
      this.$refs.docform.setFieldValue('iamAuditDiscoverRuleEntitys', iamAuditLaws)
    },
  },
}
</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-top: 4%;
      padding-left: 24%;
    }
  }

  .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;
  }
}
.btnselect {
  position: relative;
  float: right;
  top: 4px;
  .batchselect {
    z-index: 100;
    margin-right: 190px;
  }
}
.findcat-div {
  height: 500px;
}
:global(.evidencechildtable) {
  overflow-x: hidden;
  :global(.header_sd-data-table_common) {
    padding-right: 20px;
  }
}
:global(.stepnameTable) {
  :global(.ant-table-tbody > tr > td) {
    border-right: none;
    border-left: none;
  }
  :global(.ant-table-thead > tr > th) {
    border-right: none;
    border-left: none;
  }
  :global(table) {
    border: none !important;
  }
  :global(.ant-table-placeholder) {
    border: none !important;
  }
}
</style>
