<template>
  <div :class="$style.factconfirmForm">
    <audit-form-top-banner
      :handel-save-form="!readOnly ? saveForm : null"
      :form-data="mode"
      @handelSaveForm="saveForm"
    >
      <div :class="$style.wrapContent">
        <sd-detail-form
          ref="form"
          v-sd-watermark="waterMark"
          page-id="audit/work/factConfirm/iamAuditDiscover"
          form-id="iamAuditDiscover"
          :record-id="recordId"
          :class="$style.form"
          :read-only="readOnly"
          @close="close(true)"
          @saved="saved"
          @sdFormReady="
            () => {
              this.sdFormReady()
            }
          "
        >
          <template v-slot="{ model, fields }">
            <table>
              <tr>
                <td style="padding-left:5px;border:none">
                  <audit-advanced-group
                    :group-label="'事实确认信息'"
                    :expand-str="'basic'"
                    @changedClick="expandChange"
                  ></audit-advanced-group>
                </td>
              </tr>
            </table>

            <table v-show="expandInfo.basic">
              <colgroup>
                <col style="width: 15%;"/>
                <col style="width: 35%;"/>
                <col style="width: 15%;"/>
                <col style="width: 35%;"
              /></colgroup>
              <tr>
                <!-- 确认状态-->
                <sd-form-item-td name="confirmsStatus" :colspan="3"></sd-form-item-td>
              </tr>
              <tr>
                <!-- 被审计单位签证意见 -->
                <sd-form-item-td name="visaOpinion" :colspan="3">
                  <template v-slot>
                    <a-textarea
                      v-model="model.visaOpinion"
                      :auto-size="{ minRows: 3, maxRows: 3 }"
                    ></a-textarea>
                  </template>
                </sd-form-item-td>
              </tr>
              <tr>
                <!-- 附件 -->
                <sd-form-item-td name="attachment" :colspan="3" />
              </tr>
            </table>

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

            <table v-show="expandInfo.findbasic">
              <colgroup>
                <col style="width: 15%;"/>
                <col style="width: 35%;"/>
                <col style="width: 15%;"/>
                <col style="width: 35%;"
              /></colgroup>
              <tr>
                <sd-form-item-td name="findTitle" :colspan="3" />
              </tr>
              <tr>
                <sd-form-item-td name="findCode">
                  <template v-slot:read-and-edit>
                    {{ model.findCode }}
                  </template>
                </sd-form-item-td>
                <sd-form-item-td name="auditedUnit" />
              </tr>
              <tr>
                <sd-form-item-td name="findDesc" :colspan="3">
                  <template v-slot>
                    <a-textarea
                      v-model="model.findDesc"
                      :auto-size="{ minRows: 3, maxRows: 3 }"
                    ></a-textarea>
                  </template>
                </sd-form-item-td>
              </tr>
              <tr>
                <sd-form-item-td name="findType">
                  <!-- <template v-slot:read-and-edit="{ editable }">
                  <a-input v-model="model.findType" read-only @click="showfindcat" />
                </template> -->
                  <template v-slot>
                    <a-input v-model="findType" read-only @click="showfindcat" />
                    <a-input v-model="model.findType" :hidden="true" />
                  </template>
                  <template v-slot:read>
                    {{ JSON.parse(model.findType).text }}
                  </template>
                </sd-form-item-td>
                <sd-form-item-td name="suggestionType" />
              </tr>
              <tr>
                <sd-form-item-td name="suggestion" :colspan="3">
                  <template v-slot>
                    <a-textarea
                      v-model="model.suggestion"
                      :auto-size="{ minRows: 3, maxRows: 3 }"
                    ></a-textarea>
                  </template>
                </sd-form-item-td>
              </tr>
              <tr>
                <sd-form-item-td name="stepName">
                  <template v-slot:read-and-edit="{ editable }">
                    <a-input
                      v-if="editable"
                      v-model="model.stepName"
                      type="text"
                      read-only
                      @click="showstep(model)"
                    />
                    <span v-else>{{ model.stepName }}</span>
                  </template>
                </sd-form-item-td>
                <sd-form-item-td name="problemType" />
              </tr>
              <tr>
                <sd-form-item-td name="responsibleDept" />
                <sd-form-item-td name="riskLevel" />
              </tr>
              <tr>
                <sd-form-item-td name="businessProcess" />
                <sd-form-item-td name="whetherOrderDuty" />
              </tr>
              <tr>
                <sd-form-item-td name="orderDutyAsk" :colspan="3">
                  <template v-slot>
                    <a-textarea
                      v-model="model.orderDutyAsk"
                      :auto-size="{ minRows: 3, maxRows: 3 }"
                    ></a-textarea>
                  </template>
                </sd-form-item-td>
              </tr>
              <tr>
                <sd-form-item-td v-if="initParam(model)" name="findRemark" :colspan="3">
                  <template v-slot>
                    <a-textarea
                      v-model="model.findRemark"
                      :auto-size="{ minRows: 3, maxRows: 3 }"
                    ></a-textarea>
                  </template>
                </sd-form-item-td>
              </tr>
            </table>

            <table>
              <tr>
                <sd-form-item-td name="iamAuditDiscoverMoneyEntitys" :label="null" :colspan="4">
                  <template v-slot:read-and-edit="{ editable }">
                    <audit-advanced-group
                      :expand="moneyExpand"
                      expand-str="moneyExpand"
                      :group-label="'问题涉及金额列表'"
                      @changedClick="changedClick"
                    >
                      <template>
                        <xm-child-table
                          v-if="dataReady"
                          ref="childTable"
                          v-model="model.iamAuditDiscoverMoneyEntitys"
                          :read-only="!editable"
                          :fields="
                            [
                              {
                                caption: '序号',
                                name: 'sortNum',
                                dataType: 'sortNum',
                              },
                            ].concat(
                              Array.from(fields.iamAuditDiscoverMoneyEntitys.attr.dync).slice(1, 3)
                            )
                          "
                          :columns="childMoneyColumns"
                          :modal-width="'800px'"
                          @change="changetablemoney"
                          @saved="changetablemoney"
                        >
                          <!-- input-form 表示这部分是子表组件的form插槽 -->
                          <template v-slot:form="{ model, fields }">
                            <table>
                              <colgroup>
                                <col style="width: 15%;" />
                                <col style="width: 85%;" />
                              </colgroup>
                              <tr>
                                <sd-form-item-td name="assetType"> </sd-form-item-td>
                              </tr>
                              <tr>
                                <sd-form-item-td name="amount"> </sd-form-item-td>
                              </tr>
                            </table>
                          </template>
                        </xm-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="4">
                  <template v-slot:read-and-edit="{ editable }">
                    <table style="width:100%">
                      <tr
                        ><td
                          v-if="editable"
                          style="width:60px !important;border:none"
                          class="ant-form-item-label ant-form-item-label"
                        ></td
                        ><td
                          style="width:80px !important;border:none"
                          class="ant-form-item-label ant-form-item-label"
                        ></td>
                        <td style="width:50% !important;border:none;" class="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>
            </table>

            <table>
              <tr>
                <sd-form-item-td name="iamAuditDiscoverRuleEntitys" :label="null" :colspan="4">
                  <template v-slot:read-and-edit="{ editable }">
                    <audit-advanced-group :group-label="'相关法律法规条文'">
                      <template>
                        <xm-child-table
                          v-if="dataReady"
                          ref="childTable"
                          v-model="model.iamAuditDiscoverRuleEntitys"
                          :read-only="!editable"
                          :fields="childRuleFields"
                          :columns="childRuleColumns"
                          :modal-width="'800px'"
                        >
                          <!-- input-form 表示这部分是子表组件的form插槽 -->
                          <template v-slot:form="{ model, fields }">
                            <table>
                              <colgroup>
                                <col style="width: 15%;" />
                                <col style="width: 85%;" />
                              </colgroup>
                              <tr>
                                <sd-form-item-td name="ruleName"> </sd-form-item-td>
                              </tr>
                              <tr>
                                <sd-form-item-td name="ruleNumber"> </sd-form-item-td>
                              </tr>
                              <tr>
                                <sd-form-item-td name="ruleContent"> </sd-form-item-td>
                              </tr>
                            </table>
                          </template>
                        </xm-child-table>
                      </template>
                    </audit-advanced-group>
                  </template>
                </sd-form-item-td>
              </tr>
            </table>

            <table>
              <tr>
                <sd-form-item-td name="iamWorkDiscoverEvidenceEntitys" :label="null" :colspan="4">
                  <template v-slot:read-and-edit="{ editable }">
                    <audit-advanced-group :group-label="'审计取证单列表'">
                      <template>
                        <xm-paper-child-table
                          v-if="dataReady"
                          ref="childTable"
                          v-model="model.iamWorkDiscoverEvidenceEntitys"
                          :read-only="!editable"
                          :fields="childEvidenceFields"
                          :columns="childEvidenceColumns"
                          :createvidence="showevidenceTable"
                          :evidencetable="true"
                          :modal-width="'800px'"
                        >
                          <!-- input-form 表示这部分是子表组件的form插槽 -->
                          <template v-slot:form="{ model, fields }">
                            <table>
                              <colgroup>
                                <col style="width: 15%;" />
                                <col style="width: 85%;" />
                              </colgroup>
                              <tr>
                                <sd-form-item-td name="materialName"> </sd-form-item-td>
                              </tr>
                              <tr>
                                <sd-form-item-td name="materialCode"> </sd-form-item-td>
                              </tr>
                              <tr>
                                <sd-form-item-td name="attachment"> </sd-form-item-td>
                              </tr>
                            </table>
                          </template>
                        </xm-paper-child-table>
                      </template>
                    </audit-advanced-group>
                  </template>
                </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
              >
              </sd-data-table-ex>
            </a-modal>
            <!-- 选择审计步骤模板 -->
            <a-modal
              :visible="stepnamevisible"
              title="请选择"
              width="1200px"
              :body-style="{
                minHeight: '500px',
              }"
              :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>
          </template>
        </sd-detail-form>
      </div>
    </audit-form-top-banner>
  </div>
</template>

<script>
import { Modal, Message } from 'ant-design-vue'
import moment from 'moment'
import axios from '@/common/services/axios-instance'
import systemManage from '@/system-manage/system-manage'
import auditFormTopBanner from '@product/iam/components/audit-form-top-banner'
import crossWindowWatcher from '@/common/services/cross-window-watcher'
import AuditAccountService from '@product/iam/audit/work/projectmanage/account/audit-account-service'
import { getUserInfo } from '@/common/store-mixin'
import auditAdvancedGroup from '../../../../components/audit-advanced-group.vue'
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 xmPaperChildTable from '../paper/table/xm-paper-child-table.vue'
import xmPaperChildTableMixins from '../paper/table/xm-paper-child-table-mixins'
import components from './_import-components/audit-factconfirm-form-import'
import auditService from './audit-factconfirm-service'

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 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,
  },
]
export default {
  name: 'AuditFactconfirmForm',
  metaInfo: {
    title: '事实确认表单',
  },
  components: {
    ...components,
    auditFormTopBanner,
    auditAdvancedGroup,
    AuditFindCatTree,
    xmPaperChildTable,
  },
  mixins: [auditAdvancedGroupMixins, xmPaperChildTableMixins],
  data() {
    return {
      selectedRowKeys: [],
      steplist: [],
      stepmodalcolumns,
      stepnamevisible: false,
      moneyExpand: true,
      dataReady: false,
      expandInfo: {
        basic: true,
        findbasic: true,
      },
      mode: null,
      findcatvisible: false,
      findcat: '',
      findType: '',
      projectId: '',
      waterMark: systemManage.getFormWaterMark(),
      recordId: this.$route.query.record ? parseInt(this.$route.query.record) : null,
      childOtherFields: [],
      childOtherColumns: [],
      childMoneyFields: [
        {
          title: '序号',
          dataIndex: 'xh',
          dataType: 'string',
          customRender: (text, record, index) => `${index + 1}`,
          width: '80px',
          name: 'xh',
        },
        {
          title: '问题金额性质',
          dataIndex: 'assetType',
          name: 'assetType',
        },
        {
          title: '问题金额（万元）',
          dataIndex: 'amount',
          name: 'amount',
        },
      ],
      childMoneyColumns: [
        {
          title: '序号',
          dataIndex: 'sortNum',
          customRender: (text, record, index) => `${index + 1}`,
          width: '80px',
        },
        {
          title: '问题金额性质',
          dataIndex: 'assetType',
          name: 'assetType',
          width: '50%',
          sdHidden: 'false',
        },
        {
          title: '问题金额（万元）',
          dataIndex: 'amount',
          name: 'amount',
        },
      ],
      childRuleFields: [
        {
          title: '序号',
          dataIndex: 'xh',
          dataType: 'string',
          customRender: (text, record, index) => `${index + 1}`,
          width: '30px',
          name: 'xh',
        },
        {
          title: '标题',
          dataIndex: 'ruleName',
          name: 'ruleName',
        },
        {
          title: '发文字号',
          dataIndex: 'ruleNumber',
          name: 'ruleNumber',
        },
        {
          title: '条文',
          dataIndex: 'ruleContent,',
          name: 'ruleContent',
        },
      ],
      childRuleColumns: [
        {
          title: '序号',
          dataIndex: 'xh',
          dataType: 'string',
          customRender: (text, record, index) => `${index + 1}`,
          width: '80px',
        },
        {
          title: '标题',
          dataIndex: 'ruleName',
          name: 'ruleName',
          width: '40%',
        },
        {
          title: '发文字号',
          dataIndex: 'ruleNumber',
          name: 'ruleNumber',
          width: '15%',
        },
        {
          title: '条文',
          dataIndex: 'ruleContent,',
          name: 'ruleContent',
        },
      ],
      childEvidenceFields: [
        {
          title: '序号',
          dataIndex: 'xh',
          dataType: 'string',
          customRender: (text, record, index) => `${index + 1}`,
          width: '30px',
          name: 'xh',
        },

        {
          title: '取证单名称',
          dataIndex: 'materialName',
          name: 'materialName',
        },
        {
          title: '取证单编号',
          dataIndex: 'materialCode',
          name: 'materialCode',
        },
        {
          title: '附件',
          dataIndex: 'attachment',
          name: 'attachment',
        },
      ],
      childEvidenceColumns: [
        {
          title: '序号',
          dataIndex: 'xh',
          dataType: 'string',
          customRender: (text, record, index) => `${index + 1}`,
          width: '80px',
        },
        {
          title: '取证单名称',
          dataIndex: 'materialName',
          name: 'materialName',
        },
        {
          title: '取证单编号',
          dataIndex: 'materialCode',
          name: 'materialCode',
          width: '200px',
        },
        {
          title: '附件',
          dataIndex: 'attachment',
          name: 'attachment',
        },
      ],
      keyDictionary: {
        other: [],
        submission: [],
        disclose: [],
        asset: [],
      },
      keyOptions: {
        other: [],
        submission: [],
        disclose: [],
        asset: [],
      },
      evidencevisible: false,
      evidenceexpressions: [],
      evidencemodalcolumns,
      readOnly: false,
    }
  },
  created() {
    const projectId = this.$route.query.projectId
    if (projectId) {
      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: `%已结束%`,
      })
    }
  },
  mounted() {
    // 初始化信息
    // setTimeout(() => {
    //   this.initData()
    // }, 1000)
  },
  methods: {
    initParam(model) {
      // 设置父id
      if (!this.getflag) {
        var form = this.$refs.form
        if (form.formData) {
          this.fngetdata(model)
        }
        this.initData(model)
        setTimeout(() => {
          this.$refs.form.setFieldValue('projectId', this.projectId)
        }, 1000)
      }
      return true
    },
    fngetdata(model) {
      if (this.$refs.form) {
        // 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
      }
      axios({
        url: 'api/xcoa-mobile/v1/page/wp/audit/work/operate/paper/iamWorkPaper?id=' + this.paperId,
        method: 'get',
      }).then((res) => {
        this.getflag = true
        const obj = res.data.pageFormData.pageFieldInfos.find(
          (item) => item.name === 'iamWorkPaperProgrameEntityList'
        )
        if (obj !== null) {
          if (obj.value !== undefined) {
            const data = JSON.parse(obj.value)
            data.forEach((item, index) => {
              item.sortNum = index + 1
              item.key = index + 1
              if (item.importance !== undefined) {
                item.importance = obj.attr.dync
                  .find((it) => it.name === 'importance')
                  .attr.selectListItem.find((i) => i.value === item.importance).label
              }
              if (item.isExecited !== undefined) {
                item.isExecited = obj.attr.dync
                  .find((it) => it.name === 'isExecited')
                  .attr.selectListItem.find((i) => i.value === item.isExecited).label
              }
              console.log(item)
            })
            this.steplist = data
          }
        }
      })
      // 事实确认权限
      auditService.verifyDataPerms(this.recordId, this.projectId).then((res) => {
        if (res.data) {
          this.readOnly = false
        } else {
          this.readOnly = true
        }
      })
      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.form.setFieldValue('auditedUnit', this.units)
                }, 1000)
              }
            }
          }
          // 找到项目状态 如果是关闭或者归档 则设置只读
          const status = res.data.pageFormData.pageFieldInfos.find(
            (item) => item.name === 'itemStatus'
          )
          if (status) {
            if (status.value === '05' || status.value === '07') {
              this.readOnly = true
            }
          }
        })
        //   // 项目阅读权限人员屏蔽保存按钮
        //   const readAuthorityCodes = res.data.pageFormData.pageFieldInfos.find((item) => {
        //     return item.name === 'readAuthorityCodes'
        //   }).value
        //   const iamProjectUserList = JSON.parse(
        //     res.data.pageFormData.pageFieldInfos.find((item) => {
        //       return item.name === 'iamProjectUserList'
        //     }).value
        //   )
        //   const userInfo = getUserInfo()
        //   if (readAuthorityCodes) {
        //     var readUser = false
        //     if (iamProjectUserList) {
        //       iamProjectUserList.forEach((item, index) => {
        //         if (
        //           readAuthorityCodes.indexOf(userInfo.account) !== -1 &&
        //           readAuthorityCodes.indexOf(item.userAccount) === -1
        //         ) {
        //           readUser = true
        //         }
        //       })
        //       if (readUser) {
        //         this.readOnly = true
        //       }
        //     }
        //   }
        // })
      }
    },
    showSelection() {
      return true
    },
    onSelectChange(selectedRowKeys) {
      this.selectedRowKeys = selectedRowKeys
    },
    showstep(model) {
      if (model !== null && model !== undefined) {
        this.fngetdata(model)
      }
      this.stepnamevisible = !this.stepnamevisible
    },
    fngetdata1(model) {
      axios({
        url: 'api/xcoa-mobile/v1/page/wp/audit/work/operate/paper/iamWorkPaper?id=' + model.paperId,
        method: 'get',
      }).then((res) => {
        this.getflag = true
        const obj = res.data.pageFormData.pageFieldInfos.find(
          (item) => item.name === 'iamWorkPaperProgrameEntityList'
        )
        if (obj !== null) {
          if (obj.value !== undefined) {
            const data = JSON.parse(obj.value)
            data.forEach((item, index) => {
              item.sortNum = index + 1
              item.key = index + 1
              if (item.importance !== undefined) {
                item.importance = obj.attr.dync
                  .find((it) => it.name === 'importance')
                  .attr.selectListItem.find((i) => i.value === item.importance).label
              }
              if (item.isExecited !== undefined) {
                item.isExecited = obj.attr.dync
                  .find((it) => it.name === 'isExecited')
                  .attr.selectListItem.find((i) => i.value === item.isExecited).label
              }
            })
            this.steplist = data
          }
        }
      })
    },
    handlestepOk() {
      const stepname = []
      this.selectedRowKeys.forEach((item) => {
        stepname.push(this.steplist[item - 1].stepName)
      })
      this.$refs.form.setFieldValue('stepName', stepname.join(','))
      this.showstep()
    },
    handlestepCancel() {
      this.showstep()
    },

    showfindcat() {
      this.findcatvisible = !this.findcatvisible
    },
    // 页面加载完成后
    sdFormReady() {
      this.mode = this.$refs.form.formData.mode
    },
    handlefindcatOk() {
      if (this.findcat !== '') {
        this.$refs.form.setFieldValue(
          'findType',
          JSON.stringify({
            id: this.findcat.id,
            text: this.findcat.text,
          })
        )
        this.showfindcat()
        this.findType = this.findcat.text
        this.findcat = ''
      } else {
        Modal.warning({
          title: '提示',
          content: '请选择分类!',
        })
        return false
      }
    },
    handlefindcatCancel() {
      this.showfindcat()
    },
    treeSelect(select, info) {
      if (info.node) {
        this.findcat = info.node.dataRef
      } else {
        this.findcat = info
      }
      // this.$refs.docform.setFieldValue('paperId', this.findcat)
    },
    changetablemoney(data) {
      let money = 0
      data.forEach((item, index) => {
        // item.sortNum = index + 1
        if (item.amount !== undefined) {
          money = money + parseFloat(item.amount)
        }
      })
      this.$refs.form.setFieldValue('reservestring1', money.toString())
    },
    getFields(fields, business) {
      const xh = [
        {
          caption: '序号',
          dataType: 'string',
          index: 0,
          mobileVisible: true,
          name: 'xh',
          width: '30px',
        },
      ]
      let filterField = []
      if (business === 'money') {
        filterField = 'assetType,amount'.split(',')
      } else if (business === 'rule') {
        filterField = 'ruleName,ruleNumber,ruleContent'.split(',')
      } else if (business === 'evidence') {
        filterField = 'materialName,materialCode,attachment'.split(',')
      }
      // fields.reverse()
      fields = fields.filter((item) => {
        return filterField.indexOf(item.name) !== -1
      })
      // return [...fields]
      return [...xh, ...fields]
    },
    expandChange(areaKey) {
      this.expandInfo[areaKey] = !this.expandInfo[areaKey]
    },
    initData(model) {
      // const id = this.$refs.form.getFieldValue('id')
      if (this.$refs.form) {
        // const findcatstr = this.$refs.form.getFieldValue('findType')
        const findcatstr = model.findType
        if (findcatstr !== '' && findcatstr !== undefined) {
          const findcatobj = JSON.parse(findcatstr)
          this.findType = findcatobj.text
        }

        let child = this.$refs.form.formData.pageFormData.pageFieldInfos.find((item) => {
          return item.name === 'iamAuditDiscoverMoneyEntitys'
        })
        if (child) {
          this.childMoneyFields = this.getFields(child.attr.dync, 'money')
        }

        child = this.$refs.form.formData.pageFormData.pageFieldInfos.find((item) => {
          return item.name === 'iamAuditDiscoverRuleEntitys'
        })
        if (child) {
          this.childRuleFields = this.getFields(child.attr.dync, 'rule')
        }

        child = this.$refs.form.formData.pageFormData.pageFieldInfos.find((item) => {
          return item.name === 'iamWorkDiscoverEvidenceEntitys'
        })
        if (child) {
          this.childEvidenceFields = this.getFields(child.attr.dync, 'evidence')
        }
        this.dataReady = true
      }
    },

    saveForm() {
      this.$refs.form.saveBtnClick()
    },
    saved() {
      Message.success('保存成功', 1).then((res) => {
        this.close(true)
      })
    },
    close(flag) {
      crossWindowWatcher.notifyChange(this.$route.fullPath, flag)
      window.close()
    },

    // 展示选择列表
    showevidenceTable() {
      this.evidencevisible = !this.evidencevisible
    },
    // 弹出窗确认
    handleOk() {
      this.showevidenceTable()
      // 获取别选择的行信息
      let list = []
      if (this.$refs.form.getFieldValue('iamWorkDiscoverEvidenceEntitys')) {
        list = this.$refs.form.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.form.setFieldValue('iamWorkDiscoverEvidenceEntitys', list)
    },
    // 弹出窗取消
    handleCancel() {
      this.showevidenceTable()
    },
  },
}
</script>

<style module lang="scss">
@use '@/common/design' as *;
@import '@/webflow/sd-flow-form.scss';

.wrapContent {
  .rangeDate {
    :global(.ant-row .ant-form-item) {
      width: 47.5% !important;
    }
  }

  .rangeDate2 {
    :global(.ant-row .ant-form-item) {
      width: 19.3% !important;
    }
  }

  :global(.ant-form-item-label) {
    width: 15% !important;
  }

  :global(.ant-input-number) {
    width: 100% !important;
  }
}
.itemOption > div {
  float: left;
  width: 50%;
}

.factconfirmForm {
  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;
  }
}
:global(.evidencechildtable) {
  :global(.header_sd-data-table_common) {
    padding-right: 20px;
  }
}
</style>
