<template>
  <span>
    <sd-webflow
      ref="flow"
      :removed-tabs="['sdRelatedDoc']"
      :validate-form="validForm"
      :class="$style.materialListForm"
      @actionBtnClick="actionBtnClick"
    >
      <template v-slot:form="{ model, fields }">
        <div v-show="loading" :class="$style.loadingDiv">
          <a-spin :spinning="true" tip="创建数据中..." />
        </div>
        <table>
          <tr>
            <td style="padding-left: 5px; border: none">
              <audit-advanced-group
                :expand="expandinfo"
                :expand-str="'expandinfo'"
                :group-label="'基本信息'"
                tablestyle="''"
                @changedClick="changedClick"
              ></audit-advanced-group>
            </td>
          </tr>
        </table>

        <table v-show="expandinfo">
          <tr>
            <!-- 资料清单名称 -->
            <sd-form-item-td name="title" />
            <!-- 在线反馈截至时间 -->
            <sd-form-item-td name="feedbackTime" :input-props="{ style: 'width:100%' }" />
          </tr>
          <tr style="display: none">
            <!-- 项目名称 -->
            <sd-form-item-td name="projectName" />
            <!-- 项目编号 -->
            <sd-form-item-td name="projectId" />
          </tr>
          <tr>
            <!-- 被审计单位 -->
            <sd-form-item-td name="auditedUnit" />
            <!-- 被审计单位联系人 -->
            <sd-form-item-td name="linkMan" />
          </tr>
          <tr>
            <!-- 说明 -->
            <sd-form-item-td name="materialExplain" :colspan="3">
              <a-textarea v-model="model.materialExplain" :auto-size="{ maxRows: 3, minRows: 3 }" />
            </sd-form-item-td>
          </tr>
          <tr>
            <!-- 编制人员 -->
            <sd-form-item-td name="creatorName" />
            <!-- 编制日期 -->
            <sd-form-item-td name="creationTime" />
          </tr>
        </table>

        <table>
          <tr
            ><td :colspan="4" :class="$style.childTd">
              <sd-form-item
                name="iamAuditMaterialEntities"
                :label="null"
                :input-td-attrs="{ class: 'materialEntities' }"
              >
                <template v-slot:read-and-edit="{ editable }">
                  <audit-advanced-group
                    :expand="expand"
                    :expand-str="'expand'"
                    :group-label="'资料清单'"
                    @changedClick="changedClick"
                  >
                    <template>
                      <div
                        v-show="expand && editable && (isEditChild ? false : true)"
                        :class="$style.btnmubandiv"
                      >
                        <a-button type="link" :class="$style.btnmuban" @click="showImportTable"
                          ><a-icon type="check-circle" :theme="'filled'" />
                          用模板创建
                        </a-button>
                      </div>
                      <!-- :add-button-show="isfeedback ? false : true" -->
                      <sd-child-table
                        ref="childTable"
                        v-model="iamAuditMaterialList"
                        :class="$style.projecttable"
                        label="审计资料"
                        :read-only="!editable"
                        :sequence-column="true"
                        :add-button-show="isEditChild ? false : true"
                        :delete-button-show="isEditChild ? false : true"
                        :fields="Array.from(fields.iamAuditMaterialEntities.attr.dync)"
                        :columns="childColumns"
                        :data-source="iamAuditMaterialList"
                        @change="changeCTable"
                      >
                        <!-- input-form 表示这部分是子表组件的form插槽 -->
                        <template v-slot:form="{ model, fields }">
                          <table :class="$style.xmTable">
                            <tr :class="$style.firstTr">
                              <td class="ant-form-item-label ant-form-item-label"></td>
                              <td></td>
                              <td class="ant-form-item-label ant-form-item-label"></td>
                              <td></td>
                            </tr>
                            <tr>
                              <!-- 资料名称 -->
                              <!-- <sd-form-item-td name="materialTitle" :colspan="3" /> -->
                              <sd-form-item-td name="materialTitle" :colspan="3">
                                <template v-slot:read-and-edit="{ editable }">
                                  <a-input
                                    v-if="isEditChild ? false : true && editable"
                                    v-model="model.materialTitle"
                                  ></a-input>
                                  <span v-else>{{ model.materialTitle }}</span>
                                </template>
                              </sd-form-item-td>
                            </tr>
                            <tr>
                              <!-- 被审计单位 -->
                              <!-- <sd-form-item-td name="auditedUnit" /> -->
                              <sd-form-item-td
                                v-if="isEditChild ? false : true"
                                name="auditedUnit"
                              />
                              <sd-form-item-td v-else name="auditedUnit">
                                {{ model.auditedUnitNames }}
                              </sd-form-item-td>
                              <!-- 资料编号 -->
                              <sd-form-item-td name="materialCode">
                                <template v-slot:read-and-edit="{ editable }">
                                  <a-input
                                    v-if="editable && !isEditChild"
                                    v-model="model.materialCode"
                                    placeholder="编号自动生成"
                                    read-only
                                  ></a-input>
                                  <span v-else>{{ model.materialCode }}</span>
                                </template>
                              </sd-form-item-td>
                            </tr>
                            <tr>
                              <!-- 资料描述 -->
                              <sd-form-item-td name="materialDesc" :colspan="3">
                                <template v-slot:read-and-edit="{ editable }">
                                  <!-- v-if="editable" -->
                                  <a-textarea
                                    v-if="isEditChild ? false : true && editable"
                                    v-model="model.materialDesc"
                                    :auto-size="{ minRows: 3, maxRows: 3 }"
                                  ></a-textarea>
                                  <span v-else>{{ model.materialDesc }}</span>
                                </template>
                              </sd-form-item-td>
                            </tr>
                            <tr>
                              <!-- 附件 -->
                              <sd-form-item-td name="attachment" :colspan="3">
                                <template v-slot:read-and-edit="{ editable }">
                                  <XmAttachmentCus
                                    v-model="model.attachment"
                                    :read-only="editable ? false : true"
                                    :group-id="JSON.parse(fields.attachment.value).value"
                                  />
                                </template>
                              </sd-form-item-td>
                            </tr>
                            <tr>
                              <!-- 材料提供部门 -->
                              <sd-form-item-td name="provisionDept" />
                              <!-- 材料提供人 -->
                              <sd-form-item-td name="provisionUser" />
                            </tr>

                            <tr>
                              <!-- 备注 -->
                              <!-- v-if="editable || isfeedback" -->
                              <sd-form-item-td name="remarks" :colspan="3">
                                <template v-slot:read-and-edit="{ editable }">
                                  <a-textarea
                                    v-if="editable || isEditChild"
                                    v-model="model.remarks"
                                    :auto-size="{ minRows: 3, maxRows: 3 }"
                                  ></a-textarea>
                                  <span v-else>{{ model.remarks }}</span>
                                </template>
                              </sd-form-item-td>
                            </tr>
                            <tr>
                              <!-- 编制人员 -->
                              <sd-form-item-td name="creatorName">
                                <template v-slot:read-and-edit="{ editable }">
                                  <a-input
                                    v-show="false"
                                    v-model="model.creatorName"
                                    :default-value="userinfo.name"
                                  ></a-input>
                                  <span>{{ userinfo.name }}</span>
                                </template>
                              </sd-form-item-td>
                              <!-- 编制日期 -->
                              <sd-form-item-td name="creationTime">
                                <template v-slot:read-and-edit="{ editable }">
                                  <span>{{ model.creationTime | sdDateFormat('YYYY-MM-DD') }}</span>
                                </template>
                              </sd-form-item-td>
                            </tr>
                            <tr>
                              <!-- 资料类型 -->
                              <!-- <sd-form-item-td
                                name="materialType"
                                component="a-select"
                                :colspan="3"
                              /> -->
                              <template>
                                <sd-form-item-td
                                  v-if="isEditChild ? false : true"
                                  name="materialType"
                                  :colspan="3"
                                  component="a-select"
                                />
                                <sd-form-item-td v-else name="materialType" :colspan="3">
                                  <span>{{
                                    fngetlabel(fields.materialType, model.materialType)
                                  }}</span>
                                </sd-form-item-td>
                              </template>
                            </tr>
                            <!-- 是否通过 发起人环节可编辑-->
                            <tr v-show="isShow">
                              <sd-form-item-td name="whetherPass" />
                            </tr>
                            <!-- 是否通过 只读显示-->
                            <tr v-show="!isShow">
                              <sd-form-item-td name="whetherPass" :label="'是否通过'">
                                <span read-only>{{ fnget(model.whetherPass) }}</span>
                              </sd-form-item-td>
                            </tr>
                          </table>
                        </template>
                        <template v-slot:attachment="{ field, text, record }">
                          <div @click="attClick">
                            <XmAttachmentCus
                              :key="key"
                              :read-only="isfeedback ? false : true"
                              :group-id="JSON.parse(text).value ? JSON.parse(text).value : text"
                            />
                            <!-- <sd-attachment
                              :key="key"
                              :group-id="JSON.parse(text).value ? JSON.parse(text).value : text"
                              :read-only="isfeedback ? false : true"
                            /> -->
                          </div>
                        </template>
                        <template v-slot:whetherPass="{ field, text, index, record }">
                          <div @click="attClick">
                            <a-radio-group v-if="isedit" v-model="record.whetherPass">
                              <a-radio :value="'1'">
                                是
                              </a-radio>
                              <a-radio :value="'0'">
                                否
                              </a-radio>
                            </a-radio-group>
                            <span v-else read-only>{{ fnget(record.whetherPass) }}</span>
                          </div>
                        </template>
                      </sd-child-table>
                    </template>
                  </audit-advanced-group>
                </template>
              </sd-form-item></td
            >
          </tr>
        </table>
      </template>
    </sd-webflow>
    <!-- 选择导入模板 -->
    <a-modal
      :visible="visible"
      title="选择模板"
      width="50%"
      :destroy-on-close="true"
      @ok="handleOk"
      @cancel="handleCancel"
    >
      <sd-data-table-ex
        ref="importTable"
        check-type="radio"
        :filter-expressions="expressions"
        :columns="columns"
        form-id="iamTemplate"
        page-id="audit/template/iamTemplate"
        :search-fields="['templateName', 'templateType', 'isDefault']"
        show-selection
      >
      </sd-data-table-ex>
    </a-modal>
  </span>
</template>

<script>
import moment from 'moment'
import { Message, Modal } from 'ant-design-vue'
import axios from '@/common/services/axios-instance'
import XmAttachmentCus from '@product/iam/core/attachment/xm-attachment-cus'
import iamAuditpreparationService from '../iam-audit-preparation-service'
import auditAdvancedGroup from '../../../../components/audit-advanced-group.vue'
import auditAdvancedGroupMixins from '../../../../components/audit-advanced-group-mixins'
import components from './_import-components/iam-audit-material-list-form-import'
import TableColumnTypes from '@/common/services/table-column-types'
import { getUserInfo } from '@/common/store-mixin'

export default {
  name: 'IamAuditMaterialListForm',
  metaInfo: {
    title: 'IamAuditMaterialListForm',
  },
  components: {
    ...components,
    auditAdvancedGroup,
    XmAttachmentCus,
  },
  mixins: [auditAdvancedGroupMixins],
  data() {
    return {
      attachmenKey: 0,
      loading: false,
      isShow: false,
      isfeedback: null,
      isEditChild: null,
      isedit: false,
      userinfo: getUserInfo(),
      today: moment().format('YYYY-MM-DD'),
      expressions: [
        {
          dataType: 'str',
          name: 'templateType',
          op: 'like',
          stringValue: '%1%',
        },
      ],
      columns: [
        {
          title: '序号',
          dataIndex: 'sortNumber',
          width: '70px',
          customRender: (text, record, index) => `${index + 1}`,
        },
        {
          title: '模板名称',
          dataIndex: 'templateName',
          scopedSlots: { customRender: 'islink' },
        },
        {
          title: '模板类型',
          dataIndex: 'templateType',
        },
        {
          title: '编制日期',
          dataIndex: 'authTime',
          sdRender: TableColumnTypes.date,
          sorter: true,
          defaultSortOrder: 'desc',
        },
        {
          title: '附件',
          dataIndex: 'attachment',
          sdHidden: true,
        },
      ],
      visible: false,
      childFields: [],
      childBhNum: null,
      auditedUnitDefault: null,
      key: 1,
      projectId: null,
      expandinfo: true,
      expand: true,
      childColumns: [
        {
          title: '资料名称',
          dataIndex: 'materialTitle',
          width: '18%',
        },
        {
          title: '资料编号',
          dataIndex: 'materialCode',
          width: '180px',
        },
        {
          title: '资料类型',
          dataIndex: 'materialType',
          width: '100px',
        },
        {
          title: '资料描述',
          dataIndex: 'materialDesc',
          width: '20%',
        },
        {
          title: '附件',
          dataIndex: 'attachment',
        },
        {
          title: '是否通过',
          dataIndex: 'whetherPass',
          width: '150px',
        },
        {
          title: '材料提供部门',
          dataIndex: 'provisionDept',
          sdHidden: true,
        },
        {
          title: '材料提供部门编号',
          dataIndex: 'provisionDeptCode',
          sdHidden: true,
        },
        {
          title: '材料提供部门名称',
          dataIndex: 'provisionDeptName',
          sdHidden: true,
        },
        {
          title: '被审计单位',
          dataIndex: 'auditedUnit',
          sdHidden: true,
        },
        {
          title: '备注',
          dataIndex: 'remarks',
          sdHidden: true,
        },

        {
          title: '材料提供人',
          dataIndex: 'provisionUser',
          sdHidden: true,
        },
        {
          title: '材料提供人账号',
          dataIndex: 'provisionUserAccount',
          sdHidden: true,
        },
        {
          title: '材料提供人名称',
          dataIndex: 'provisionUserName',
          sdHidden: true,
        },
        {
          title: '文档状态',
          dataIndex: 'docStatus',
          sdHidden: true,
        },
        {
          title: '项目ID',
          dataIndex: 'projectId',
          sdHidden: true,
        },
        {
          title: 'mainId',
          dataIndex: 'mainId',
          sdHidden: true,
        },
        {
          title: '编制人员',
          dataIndex: 'creatorName',
          sdHidden: true,
        },
        {
          title: '编制日期',
          dataIndex: 'creationTime',
          sdHidden: true,
        },
      ],
      ctShow: false,
      iamAuditMaterialEntities: [],
      iamAuditMaterialList: [],
      otherRateList: [], // 是否通过为否的数据
      otherList: [], // 通过的数据
      radioStyle: {},
    }
  },
  mounted() {
    const _this = this
    const ini = setInterval(() => {
      if (this.$refs.flow && (this.$refs.flow.$refs.form || this.$refs.flow.$refs.sdForm)) {
        clearInterval(ini)
        // 开始初始化
        this.initFun()
        // 处理子表数据
        const rateList = this.$refs.flow.getFieldValue('iamAuditMaterialEntities')
        if (rateList !== undefined) {
          // 是否通过为“否”的数据
          _this.otherRateList = rateList.filter((el) => {
            return el.whetherPass !== '1'
          })
          // 设置当前环节是否是 被审计单位联系人
          const isShow1 = this.$refs.flow.flowData.attrs.materialList$isRaterNode
          if (isShow1 === true) {
            this.iamAuditMaterialList = _this.otherRateList
            // 是否通过为“是”的数据
            _this.otherList = rateList.filter((el) => {
              return el.whetherPass === '1'
            })
          } else {
            this.iamAuditMaterialList = rateList
          }
        }
      }
    }, 100)
    if (this.$refs.flow.flowData.attrs.materialList$isShow !== undefined) {
      // 判断当前环节是否是 发起人环节
      const show = this.$refs.flow.flowData.attrs.materialList$isShow
      if (show === '1') {
        // 是发起人环节的情况(子表弹出框)，是否通过 字段可编辑
        this.isShow = true
      }
    }
  },
  created() {},
  methods: {
    // 初始化方法
    initFun() {
      debugger
      // 设置当前环节是否是反馈环节(被审计单位联系人环节)
      this.isfeedback = this.$refs.flow.flowData.attrs.audit$feedback
      // 设置当前环节是否是被审计单位联系人环节 (isEditChild - 用来控制子表按钮显示)
      const isEditchild = this.$refs.flow.flowData.attrs.audit$isEditChild
      if (isEditchild === '1') {
        this.isEditChild = true
      } else {
        this.isEditChild = false
      }
      // 设置当前环节是否是发起人环节
      const edit = this.$refs.flow.flowData.attrs.materialList$isShow
      if (edit === '1') {
        // 是发起人环节的情况(子表列表)，是否通过 字段可编辑
        this.isedit = true
      }
      this.key++
      // 先获取项目id
      if (this.$route.query.extParams) {
        this.projectId = JSON.parse(this.$route.query.extParams).projectId
      } else {
        this.projectId = this.$refs.flow.getFieldValue('projectId')
      }

      iamAuditpreparationService.getProjectInfoById(this.projectId).then((res) => {
        if (!this.$refs.flow.getFieldValue('projectName')) {
          this.$refs.flow.setFieldValue('projectName', res.data.projectTitle)
          this.$refs.flow.setFieldValue('projectId', parseFloat(this.projectId))
          this.$refs.flow.setFieldValue('title', res.data.projectTitle + '资料收集')
        }
      })
      // 设置审计单位默认值
      setTimeout(() => {
        iamAuditpreparationService.getAuditedUnitById(this.projectId).then((res) => {
          if (!this.$refs.flow.getFieldValue('auditedUnit')) {
            this.$refs.flow.setFieldValue('auditedUnit', res.data)
          }
          this.auditedUnitDefault = JSON.stringify(res.data)
          const child = this.$refs.flow.flowData.processFormData.processFormPropertyValues.find(
            (item) => {
              return item.name === 'iamAuditMaterialEntities'
            }
          )
          if (child) {
            this.childFields = this.getFields(child.attr.dync)
            this.key++
          }
        })
      }, 0)
    },
    fnget(data) {
      var name = ''
      if (data === '1') {
        name = '是'
      } else if (data === '0') {
        name = '否'
      } else {
        name
      }
      return name
    },
    actionBtnClick(evt, context) {
      debugger
      let rateList = this.iamAuditMaterialList
      const isList = this.otherList
      rateList = [...rateList, ...isList]
      this.$refs.flow.setFieldValue('iamAuditMaterialEntities', rateList)
      if (context.button.fakeId === 'workflow-push') {
        // 	G_1_PREPARATION_MATERIALLIST.3   （发起人环节-提交的结束）
        if (context.button.buttonId === 'G_1_PREPARATION_MATERIALLIST.3') {
          // const feedback = this.$refs.flow.flowData.attrs.audit$feedback
          const feedback = this.$refs.flow.flowData.attrs.materialList$edit
          if (feedback) {
            // 校验反馈环节 线上提供 是否上传了附件
            const childEntrys = this.$refs.flow.getFieldValue('iamAuditMaterialEntities')
            const instId = this.$refs.flow.flowData.instId
            const beanId = this.$refs.flow.flowData.processFormData.beanId
            const formId = this.$refs.flow.flowData.processFormData.formId
            let toSubmit = true // 默认可以提交
            // 如果没有字表内容
            if (childEntrys.length === 0) {
              return Promise.resolve(true)
            }
            evt.waitUntil(
              new Promise((resolve, reject) => {
                // 先阻止默认事件
                evt.defaultPrevented = true
                childEntrys.forEach((item, index) => {
                  const attId = JSON.parse(item.attachment).value
                  const chekcatt = new Promise((resolve, reject) => {
                    // 校验附件是否上传
                    axios({
                      url: `api/xcoa-mobile/v1/attachment-extend/attachments-info-perm/${attId}?formId=${formId}&beanId=${beanId}&instId=${instId}`,
                      method: 'get',
                    }).then((res) => {
                      if (
                        (item.materialType === '01' && res.data.length === 0) ||
                        (item.materialType === '01' && item.whetherPass !== '1')
                      ) {
                        axios({
                          url: `api/framework/v1/large-file/attachments-info-perm/${attId}`,
                          method: 'get',
                        }).then((res) => {
                          if (
                            (item.materialType === '01' &&
                              res.data.largeAttachments.length === 0) ||
                            (item.materialType === '01' && item.whetherPass !== '1')
                          ) {
                            resolve(false)
                          } else {
                            resolve(true)
                          }
                        })
                      } else {
                        resolve(true)
                      }
                    })

                    // iamAuditpreparationService
                    //   .checkAttachment(attId, beanId, instId, formId)
                    //   .then((res) => {
                    //     // if (item.materialType === '01' && res.data.length === 0) {
                    //     //   resolve(false)
                    //     // } else if (item.materialType === '01' && item.whetherPass !== '1') {
                    //     //   resolve(false)
                    //     // }
                    //     if (
                    //       (item.materialType === '01' && res.data.length === 0) ||
                    //       (item.materialType === '01' && item.whetherPass !== '1')
                    //     ) {
                    //       resolve(false)
                    //     } else {
                    //       resolve(true)
                    //     }
                    //   })
                  })
                  chekcatt.then((res) => {
                    if (!res) {
                      toSubmit = false
                    }
                    // 如果是最后一个
                    if (index === childEntrys.length - 1) {
                      if (toSubmit) {
                        evt.defaultPrevented = false
                        resolve()
                      } else {
                        Message.error(
                          '请检查所有“线上提供”的审计资料，必须上传附件并且都选择审核通过。',
                          3
                        )
                        resolve()
                      }
                    }
                  })
                })
              })
            )
          }
        }
      }
      // if (context.button.fakeId === 'workflow-push') {
      //   const feedback = this.$refs.flow.flowData.attrs.audit$feedback
      //   if (feedback) {
      //     // 校验反馈环节 线上提供 是否上传了附件
      //     const childEntrys = this.$refs.flow.getFieldValue('iamAuditMaterialEntities')
      //     const beanId = this.$refs.flow.flowData.instId
      //     const instId = this.$refs.flow.flowData.processFormData.beanId
      //     const formId = this.$refs.flow.flowData.processFormData.formId
      //     let toSubmit = true // 默认可以提交
      //     // 如果没有字表内容
      //     if (!childEntrys) {
      //       return Promise.resolve(true)
      //     }
      //     evt.waitUntil(
      //       new Promise((resolve, reject) => {
      //         // 先阻止默认事件
      //         evt.defaultPrevented = true
      //         childEntrys.forEach((item, index) => {
      //           const attId = JSON.parse(item.attachment).value
      //           const chekcatt = new Promise((resolve, reject) => {
      //             iamAuditpreparationService
      //               .checkAttachment(attId, beanId, instId, formId)
      //               .then((res) => {
      //                 if (item.materialType === '01' && res.data.length === 0) {
      //                   iamAuditpreparationService
      //                     .checkLargeAttachment(attId, beanId, instId, formId)
      //                     .then((res) => {
      //                       if (item.materialType === '01' && res.data.length === 0) {
      //                         resolve(false)
      //                       } else {
      //                         resolve(true)
      //                       }
      //                     })
      //                 } else {
      //                   resolve(true)
      //                 }
      //               })
      //           })
      //           chekcatt.then((res) => {
      //             if (!res) {
      //               toSubmit = false
      //             }
      //             // 如果是最后一个
      //             if (index === childEntrys.length - 1) {
      //               if (toSubmit) {
      //                 evt.defaultPrevented = false
      //                 resolve()
      //               } else {
      //                 Message.error('线上提供必须上传附件', 1)
      //                 resolve()
      //               }
      //             }
      //           })
      //         })
      //       })
      //     )
      //   }
      // }
    },
    changeCTable() {
      this.key++
    },
    // 附件列点击，停止默认事件
    attClick() {
      event.stopPropagation()
    },
    // 自定义校验
    validForm(a, b, c, d) {
      const data = this.$refs.flow.getFieldValue('iamAuditMaterialEntities')
      if (!data) {
        Message.warning('请添加资料清单信息', 1)
        return Promise.resolve(false)
      }
      data.forEach((item, index) => {
        if (item.id.toString().includes('fakeId')) {
          item.id = null
        }
      })
      this.$refs.flow.setFieldValue('iamAuditMaterialEntities', data)
      return Promise.resolve(true)
    },
    // 增加序号列
    getFields(fields) {
      const xh = [
        {
          caption: '序号',
          dataType: 'string',
          index: 0,
          mobileVisible: true,
          name: 'xh',
        },
      ]
      const newfields = [1, 2, 3, 4, 5]
      fields.forEach((item) => {
        item.readonly = false
        if (item.name === 'auditedUnit') {
          item.value = this.auditedUnitDefault
        }
        if (item.name === 'materialTitle') {
          item.required = true
          newfields.splice(0, 1, item)
        } else if (item.name === 'materialCode') {
          newfields.splice(1, 1, item)
        } else if (item.name === 'materialType') {
          newfields.splice(2, 1, item)
        } else if (item.name === 'materialDesc') {
          newfields.splice(3, 1, item)
        } else if (item.name === 'attachment') {
          newfields.splice(4, 1, item)
        } else if (item.name === 'whetherPass') {
          newfields.splice(5, 1, item)
        } else {
          newfields.push(item)
        }
      })
      // 对列进行排序

      return [...xh, ...newfields]
    },
    // 展示选择列表
    showImportTable() {
      this.visible = !this.visible
    },
    // 弹出窗确认
    handleOk() {
      debugger
      this.loading = true
      this.showImportTable()
      // 获取别选择的行信息
      const selectInfo = this.$refs.importTable.getSelectedRows()
      console.log('附件---', selectInfo[0].attachment)
      iamAuditpreparationService
        .importMaterialInfo(selectInfo[0].attachment, this.projectId)
        .then((res) => {
          Message.success('模板创建成功')
          const data = this.$refs.flow.getFieldValue('iamAuditMaterialEntities') || []
          const tableData = data.concat(res.data)
          tableData.forEach((item, index) => {
            if (!item.id) {
              item.id = 'fakeId' + index + 1
            }
          })
          // this.$refs.flow.setFieldValue('iamAuditMaterialEntities', tableData)
          this.iamAuditMaterialList = tableData
          this.loading = false
        })
    },
    // 弹出窗取消
    handleCancel() {
      this.showImportTable()
    },
    fngetlabel(obj, val) {
      if (obj.attr.selectListItem) {
        const o = obj.attr.selectListItem.find((item) => item.value === val)
        if (o) {
          return o.label
        } else {
          return val
        }
      } else {
        return val
      }
    },
  },
}
</script>

<style module lang="scss">
@use '@/common/design' as *;
:global(.materialEntities) {
  :global(.header_sd-child-table_common) {
    button:first-child {
      margin-right: 120px;
    }
  }
}
.btnmubandiv {
  position: relative;
  .btnmuban {
    position: absolute;
    top: 0;
    right: 190px;
    z-index: 100;
  }
}
.projecttable {
  table {
    border-collapse: collapse;
  }
}
:global(.ant-upload) {
  background: transparent !important;
  border: none !important;
}
// :global(.ant-upload-text) {
//   display: none !important;
// }
:global(.ant-upload-drag-icon) {
  margin-bottom: 0 !important;
  :global(.anticon) {
    font-size: 26px !important;
  }
}
.xm-table {
  :global(td.ant-form-item-label) {
    width: 15%;
  }
  :global(td.ant-form-item-control-wrapper) {
    width: 35%;
  }
}
.material-list-form {
  :global(.child-table-title) {
    display: none;
  }
}
.child-td {
  :global(.groupstyle_audit-advanced-group_product) {
    margin-left: 4px;
  }
}
.loading-div {
  position: absolute;
  z-index: 101;
  display: flex;
  flex-direction: column;
  justify-content: center;
  width: 100%;
  height: 100%;
  background: rgb(255 255 255 / 70%);
}
</style>
