<template>
  <span>
    <audit-form-top-banner :handel-save-form="saveForm" @handelSaveForm="saveForm">
      <div class="title_sd-detail-form_common">数据分类授权</div>

      <table>
        <tr v-if="unit.length > 1">
          <td>
            <audit-advanced-group
              :expand="companyExpand"
              :expand-str="'companyExpand'"
              :group-label="'指定公司'"
              tablestyle="''"
              @changedClick="changedClick"
              ><template>
                <template>
                  <div :class="$style.wrapper">
                    <div v-show="companyExpand" :class="$style.btnselect">
                      <a-button type="link" :class="$style.batchselect" @click="companylSelect">
                        <a-icon type="check-circle" :theme="'filled'" />
                        添加
                      </a-button>
                    </div>
                  </div>
                </template>
                <XmChildTable
                  ref="cdata"
                  v-model="companyData"
                  :label="null"
                  :columns="companycolumns"
                  :fields="
                    [
                      {
                        caption: '序号',
                        name: 'sortNum',
                        dataType: 'sortNum',
                      },
                    ].concat(unit)
                  "
                  :addbuttonvisiable="false"
                >
                  <template v-slot:unitName="{ field, text, index, value }">
                    {{ text }}
                  </template>
                  <template v-slot:unitCode="{ field, text, index, value }">
                    {{ text }}
                  </template>
                  <template v-slot:empowerType="{ field, text, index, value }">
                    <audit-warrant-input
                      :ref="'cdata_empowerType_' + index"
                      :value="value[index]"
                      :index="index"
                      :field="field"
                      :data="'cdata'"
                      lx="type"
                      @change="setchange"
                    />
                  </template>
                  <template v-slot:startDate="{ field, text, index, value }">
                    <audit-warrant-input
                      :ref="'cdata_startDate_' + index"
                      :value="value[index]"
                      :index="index"
                      :field="field"
                      :data="'cdata'"
                      lx="stime"
                      @change="setchange"
                    />
                  </template>
                  <template v-slot:endDate="{ field, text, index, value }">
                    <audit-warrant-input
                      :ref="'cdata_endDate_' + index"
                      :value="value[index]"
                      :index="index"
                      :field="field"
                      :data="'cdata'"
                      lx="etime"
                      @change="setchange"
                    />
                  </template> </XmChildTable
              ></template>
            </audit-advanced-group> </td
        ></tr>
      </table>

      <table
        ><tr
          ><td style="border:none">
            <audit-advanced-group
              :expand="maintainExpand"
              :expand-str="'maintainExpand'"
              :group-label="'数据分类列表'"
              tablestyle="''"
              @changedClick="changedClick"
            >
              <!-- 添加 -->
              <template>
                <div :class="$style.wrapper">
                  <div :class="$style.btnselect">
                    <a-button type="link" :class="$style.batchselect" @click="flRelSelect">
                      <a-icon type="check-circle" :theme="'filled'" />
                      添加
                    </a-button>
                  </div>
                </div>
              </template>
              <template>
                <XmChildTable
                  ref="classIndexData"
                  v-model="maintaindata"
                  :label="null"
                  :columns="columns"
                  :fields="classifyFileds"
                  :addbuttonvisiable="false"
                  @deleted="deletedClassList"
                >
                  <template v-slot:categoryName="{ field, text, index, value }">
                    {{ text }}
                  </template>
                  <template v-slot:categoryId="{ field, text, index, value }">
                    {{ text }}
                  </template>
                  <template v-slot:categoryDesc="{ field, text, index, value }">
                    {{ text }}
                  </template>
                </XmChildTable>
              </template>
            </audit-advanced-group>
          </td></tr
        ></table
      >

      <!--
      <SdTable
        v-if="maintainExpand && maintaindata.length > 0"
        ref="maintaintable"
        :row-key="(record, index) => index"
        :loading="false"
        class="maintaintable"
        :columns="columns"
        :data-source="maintaindata"
        :pagination="false"
        :bordered="true"
        :row-selection="{
          getCheckboxProps(record) {
            return {
              props: { disabled: !showSelection(record) },
            }
          },
          selectedRowKeys: selectedRowKeys,
          onChange: onSelectChange,
        }"
      /> -->

      <table>
        <tr>
          <td>
            <audit-advanced-group
              :expand="classShow"
              :expand-str="'classShow'"
              :group-label="'审搜索引'"
              tablestyle="''"
              @changedClick="changedClick"
              ><template>
                <template>
                  <div :class="$style.wrapper">
                    <div :class="$style.btnselect">
                      <a-button type="link" :class="$style.batchselect" @click="inedxRelSelect">
                        <a-icon type="check-circle" :theme="'filled'" />
                        添加
                      </a-button>
                    </div>
                  </div>
                </template>
                <XmChildTable
                  ref="classIndexData"
                  v-model="classIndexData"
                  :label="null"
                  :columns="indexColumns"
                  :fields="classIndexFileds"
                  :addbuttonvisiable="false"
                >
                  <template v-slot:indexName="{ field, text, index, value }">
                    {{ text }}
                  </template>
                  <template v-slot:id="{ field, text, index, value }">
                    {{ text }}
                  </template>
                  <template v-slot:indexRemark="{ field, text, index, value }">
                    {{ text }}
                  </template>
                </XmChildTable>
              </template>
            </audit-advanced-group>
          </td></tr
        >
      </table>

      <!-- <table>
        <tr v-if="unit.length > 1">
          <td>
            <audit-advanced-group
              :expand="unitExpand"
              :expand-str="'unitExpand'"
              :group-label="'授权单位'"
              tablestyle="''"
              @changedClick="changedClick"
              ><template>
                <template>
                  <div :class="$style.wrapper">
                    <div v-show="unitExpand" :class="$style.btnselect">
                      <a-button type="link" :class="$style.batchselect" @click="dwRelSelect">
                        <a-icon type="check-circle" :theme="'filled'" />
                        添加
                      </a-button>
                    </div>
                  </div>
                </template>
                <XmChildTable
                  ref="udata"
                  v-model="unitdata"
                  :label="null"
                  :columns="unitcolumns"
                  :fields="
                    [
                      {
                        caption: '序号',
                        name: 'sortNum',
                        dataType: 'sortNum',
                      },
                    ].concat(unit)
                  "
                  :addbuttonvisiable="false"
                >
                  <template v-slot:unitName="{ field, text, index, value }">
                    {{ text }}
                  </template>
                  <template v-slot:unitCode="{ field, text, index, value }">
                    {{ text }}
                  </template>
                  <template v-slot:empowerType="{ field, text, index, value }">
                    <audit-warrant-input
                      :ref="'udata_empowerType_' + index"
                      :value="value[index]"
                      :index="index"
                      :field="field"
                      lx="type"
                      @change="setchange"
                    />
                  </template>
                  <template v-slot:startDate="{ field, text, index, value }">
                    <audit-warrant-input
                      :ref="'udata_startDate_' + index"
                      :value="value[index]"
                      :index="index"
                      :field="field"
                      lx="stime"
                      @change="setchange"
                    />
                  </template>
                  <template v-slot:endDate="{ field, text, index, value }">
                    <audit-warrant-input
                      :ref="'udata_endDate_' + index"
                      :value="value[index]"
                      :index="index"
                      :field="field"
                      lx="etime"
                      @change="setchange"
                    />
                  </template> </XmChildTable
              ></template>
            </audit-advanced-group> </td
        ></tr>
      </table> -->

      <table>
        <tr v-if="personal.length > 1">
          <td
            ><audit-advanced-group
              :expand="personalExpand"
              :expand-str="'personalExpand'"
              :group-label="'授权人员'"
              tablestyle="''"
              @changedClick="changedClick"
              ><template>
                <template>
                  <div :class="$style.wrapper">
                    <div v-show="personalExpand" :class="$style.btnselect">
                      <a-button type="link" :class="$style.batchselect" @click="pRelSelect">
                        <a-icon type="check-circle" :theme="'filled'" />
                        添加
                      </a-button>
                    </div>
                  </div>
                </template>
                <XmChildTable
                  ref="pdata"
                  v-model="personaldata"
                  :label="null"
                  :columns="personalcolumns"
                  :fields="
                    [
                      {
                        caption: '序号',
                        name: 'sortNum',
                        dataType: 'sortNum',
                      },
                    ].concat(personal)
                  "
                  :addbuttonvisiable="false"
                >
                  <template v-slot:userName="{ field, text, index, value }">
                    {{ text }}
                  </template>
                  <template v-slot:userUnit="{ field, text, index, value }">
                    {{ text }}
                  </template>
                  <template v-slot:userId="{ field, text, index, value }">
                    {{ text }}
                  </template>
                  <template v-slot:empowerType="{ field, text, index, value }">
                    <audit-warrant-input-p
                      :ref="'pdata_empowerType_' + index"
                      :data="'pdata'"
                      :value="value[index]"
                      :index="index"
                      :field="field"
                      lx="type"
                      @change="setchange"
                    />
                  </template>
                  <template v-slot:startDate="{ field, text, index, value }">
                    <audit-warrant-input-p
                      :ref="'pdata_startDate_' + index"
                      :data="'pdata'"
                      :value="value[index]"
                      :index="index"
                      :field="field"
                      lx="stime"
                      @change="setchange"
                    />
                  </template>
                  <template v-slot:endDate="{ field, text, index, value }">
                    <audit-warrant-input-p
                      :ref="'pdata_endDate_' + index"
                      :data="'pdata'"
                      :value="value[index]"
                      :index="index"
                      :field="field"
                      lx="etime"
                      @change="setchange"
                    />
                  </template> </XmChildTable></template
            ></audit-advanced-group> </td
        ></tr>
      </table>

      <table>
        <tr v-if="projectTable.length > 1">
          <td
            ><audit-advanced-group
              :expand="projectExpand"
              :expand-str="'projectExpand'"
              :group-label="'项目授权'"
              tablestyle="''"
              @changedClick="changedClick"
              ><template>
                <template>
                  <div :class="$style.wrapper">
                    <div v-show="projectExpand" :class="$style.btnselect">
                      <a-button type="link" :class="$style.batchselect" @click="projectShow = true">
                        <a-icon type="check-circle" :theme="'filled'" />
                        添加
                      </a-button>
                    </div>
                  </div>
                </template>
                <XmChildTable
                  ref="prodata"
                  v-model="projectData"
                  :label="null"
                  :columns="projectColums"
                  :fields="
                    [
                      {
                        caption: '序号',
                        name: 'sortNum',
                        dataType: 'sortNum',
                      },
                    ].concat(projectTable)
                  "
                  :addbuttonvisiable="false"
                >
                  <template v-slot:projectName="{ field, text, index, value }">
                    {{ text }}
                  </template>
                  <template v-slot:projectUnit="{ field, text, index, value }">
                    {{ text }}
                  </template>
                  <template v-slot:empowerType="{ field, text, index, value }">
                    <audit-warrant-input
                      :ref="'prodata_empowerType_' + index"
                      :value="value[index]"
                      :index="index"
                      :data="'prodata'"
                      :field="field"
                      lx="type"
                      @change="setchange"
                    />
                  </template>
                  <template v-slot:startDate="{ field, text, index, value }">
                    <audit-warrant-input
                      :ref="'prodata_startDate_' + index"
                      :value="value[index]"
                      :index="index"
                      :field="field"
                      :data="'prodata'"
                      lx="stime"
                      @change="setchange"
                    />
                  </template>
                  <template v-slot:endDate="{ field, text, index, value }">
                    <audit-warrant-input
                      :ref="'prodata_endDate_' + index"
                      :value="value[index]"
                      :index="index"
                      :field="field"
                      :data="'prodata'"
                      lx="etime"
                      @change="setchange"
                    />
                  </template>
                </XmChildTable> </template
            ></audit-advanced-group> </td
        ></tr>
      </table>

      <table>
        <tr v-if="roleTable.length > 1">
          <td
            ><audit-advanced-group
              :expand="roleExpand"
              :expand-str="'roleExpand'"
              :group-label="'授权角色'"
              tablestyle="''"
              @changedClick="changedClick"
              ><template>
                <template>
                  <div :class="$style.wrapper">
                    <div v-show="roleExpand" :class="$style.btnselect">
                      <a-button type="link" :class="$style.batchselect" @click="roleShow = true">
                        <a-icon type="check-circle" :theme="'filled'" />
                        添加
                      </a-button>
                    </div>
                  </div>
                </template>
                <XmChildTable
                  ref="rdata"
                  v-model="roleData"
                  :label="null"
                  :columns="roleColumns"
                  :fields="
                    [
                      {
                        caption: '序号',
                        name: 'sortNum',
                        dataType: 'sortNum',
                      },
                    ].concat(roleTable)
                  "
                  :addbuttonvisiable="false"
                >
                  <template v-slot:roleName="{ field, text, index, value }">
                    {{ text }}
                  </template>
                  <template v-slot:empowerType="{ field, text, index, value }">
                    <audit-warrant-input
                      :ref="'rdata_empowerType_' + index"
                      :value="value[index]"
                      :index="index"
                      :data="'rdata'"
                      :field="field"
                      lx="type"
                      @change="setchange"
                    />
                  </template>
                  <template v-slot:startDate="{ field, text, index, value }">
                    <audit-warrant-input
                      :ref="'rdata_startDate_' + index"
                      :value="value[index]"
                      :index="index"
                      :field="field"
                      :data="'rdata'"
                      lx="stime"
                      @change="setchange"
                    />
                  </template>
                  <template v-slot:endDate="{ field, text, index, value }">
                    <audit-warrant-input
                      :ref="'rdata_endDate_' + index"
                      :value="value[index]"
                      :index="index"
                      :field="field"
                      :data="'rdata'"
                      lx="etime"
                      @change="setchange"
                    />
                  </template>
                </XmChildTable> </template
            ></audit-advanced-group> </td
        ></tr>
      </table>

      <div v-show="false">
        <SdGroupPicker
          ref="dwRelSelect"
          v-model="mainSendUnit"
          :single="false"
          :read-only="false"
          :root-node="rootNodeData"
          @change="changeunit"
        />
      </div>

      <div v-show="false">
        <SdGroupPicker
          ref="cRelSelect"
          v-model="companyUnit"
          :single="false"
          :read-only="false"
          :root-node="rootNodeData"
          @change="changecompany"
        />
      </div>

      <div v-show="false">
        <SdUserPicker
          ref="pRelSelect"
          v-model="mainSendPersonal"
          :single="false"
          :read-only="false"
          :root-node="rootNodeData"
          @change="changep"
        />
      </div>
    </audit-form-top-banner>
    <roleModal v-model="roleShow" @selectRoleList="changeRole" />
    <projectModal v-model="projectShow" @selectProject="changeProject" />
    <AuditClassIndexTable
      ref="indexSelect"
      :visible="indexTableShow"
      :class-data="maintaindata"
      @listMxSelected="listMxSelected"
    />
    <auditClassTable
      :select-type="'radio'"
      :visible="flTableShow"
      @listMxSelected="classListMxSelected"
    >
    </auditClassTable>
  </span>
</template>

<script>
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 auditAdvancedGroupMixins from '../../components/audit-advanced-group-mixins'
import auditWarrantInput from './audit-warrant-input.vue'
import auditWarrantInputP from '../dataMarket/audit-warrant-input.vue'
import auditMaintainService from './data-config'
import SdGroupPicker from '@/common/components/sd-group-picker.vue'
import SdUserPicker from '@/common/components/sd-user-picker.vue'
import XmChildTable from '../../components/xm-child-table.vue'
import roleModal from './role-modal.vue'
import projectModal from './project-modal.vue'
import moment from 'moment'
import AuditClassIndexTable from '../dataUphold/audit-class-index-table.vue'
import auditClassTable from './audit-class-table.vue'
import { getUserInfo } from '@/common/store-mixin'
export default {
  name: 'AuditDataFrom',
  metaInfo: {
    title: '数据分类授权',
  },
  components: {
    SdGroupPicker,
    SdUserPicker,
    XmChildTable,
    auditFormTopBanner,
    auditAdvancedGroup,
    auditWarrantInput,
    roleModal,
    projectModal,
    AuditClassIndexTable,
    auditClassTable,
    auditWarrantInputP,
  },
  mixins: [auditAdvancedGroupMixins],
  data() {
    return {
      mainSendUnit: [],
      companyUnit: [],
      mainSendPersonal: [],
      mainSendRole: [],
      selectedRowKeys: [],
      selectid: '',
      maintaindata: [],
      unitdata: [],
      personaldata: [],
      maintainExpand: true,
      unitExpand: true,
      personalExpand: true,
      roleExpand: true,
      projectExpand: true,
      personal: [],
      unit: [],
      indexTableShow: false,
      columns: [
        {
          title: '序号',
          dataIndex: 'sortNum',
          key: 'sortNum',
          customRender: (text, record, index) => `${index + 1}`,
          width: '80px',
        },
        {
          title: '分类名称',
          dataIndex: 'categoryName',
          key: 'categoryName',
          width: '30%',
        },
        {
          title: '分类编号',
          dataIndex: 'categoryId',
          key: 'categoryId',
          width: '30%',
        },
        {
          title: '分类描述',
          dataIndex: 'categoryDesc',
          key: 'categoryDesc',
          width: '30%',
        },
        {
          dataIndex: 'indexId',
          sdHidden: true,
        },
      ],
      unitcolumns: [
        {
          title: '序号',
          dataIndex: 'sortNum',
          customRender: (text, record, index) => `${index + 1}`,
          width: '80px',
        },
        {
          title: '单位编号',
          dataIndex: 'unitCode',
          sdHidden: false,
        },
        {
          title: '单位名称',
          dataIndex: 'unitName',
          sdHidden: false,
        },
        {
          title: '授权类型',
          dataIndex: 'empowerType',
          sdHidden: false,
        },
        {
          title: '开始日期',
          dataIndex: 'startDate',
          sdHidden: false,
        },
        {
          title: '结束日期',
          dataIndex: 'endDate',
          sdHidden: false,
        },
        {
          dataIndex: 'id',
          sdHidden: true,
        },
        {
          dataIndex: 'unitOpt',
          sdHidden: true,
        },
        {
          dataIndex: 'unitId',
          sdHidden: true,
        },
        {
          dataIndex: 'selectOrgId',
          sdHidden: true,
        },
        {
          dataIndex: 'belongedOrgId',
          sdHidden: true,
        },
        {
          dataIndex: 'docType',
          sdHidden: true,
        },
        {
          dataIndex: 'maintainId',
          sdHidden: true,
        },
        {
          dataIndex: 'applyId',
          sdHidden: true,
        },
        {
          dataIndex: 'indexId',
          sdHidden: true,
        },
      ],
      personalcolumns: [
        {
          title: '序号',
          dataIndex: 'sortNum',
          customRender: (text, record, index) => `${index + 1}`,
          width: '80px',
        },
        {
          title: '用户名',
          dataIndex: 'userName',
          sdHidden: false,
        },
        {
          title: '所属单位',
          dataIndex: 'userUnit',
          sdHidden: false,
        },
        {
          title: '用户工号',
          dataIndex: 'userId',
          sdHidden: false,
        },
        {
          title: '授权类型',
          dataIndex: 'empowerType',
          sdHidden: false,
        },
        {
          title: '开始日期',
          dataIndex: 'startDate',
          sdHidden: false,
        },
        {
          title: '结束日期',
          dataIndex: 'endDate',
          sdHidden: false,
        },
        {
          dataIndex: 'id',
          sdHidden: true,
        },
        {
          dataIndex: 'userId',
          sdHidden: true,
        },
        {
          dataIndex: 'userOpt',
          sdHidden: true,
        },
        {
          dataIndex: 'selectOrgId',
          sdHidden: true,
        },
        {
          dataIndex: 'belongedOrgId',
          sdHidden: true,
        },
        {
          dataIndex: 'docType',
          sdHidden: true,
        },
        {
          dataIndex: 'maintainId',
          sdHidden: true,
        },
        {
          dataIndex: 'applyId',
          sdHidden: true,
        },
        {
          dataIndex: 'indexId',
          sdHidden: true,
        },
      ],
      roleColumns: [
        {
          title: '序号',
          dataIndex: 'sortNum',
          customRender: (text, record, index) => `${index + 1}`,
          width: '80px',
        },
        {
          title: '授权类型',
          dataIndex: 'empowerType',
          sdHidden: false,
        },
        {
          title: '开始日期',
          dataIndex: 'startDate',
          sdHidden: false,
        },
        {
          title: '结束日期',
          dataIndex: 'endDate',
          sdHidden: false,
        },
        {
          dataIndex: 'id',
          sdHidden: true,
        },
        {
          dataIndex: 'roleId',
          sdHidden: true,
        },
        {
          dataIndex: 'selectOrgId',
          sdHidden: true,
        },
        {
          dataIndex: 'belongedOrgId',
          sdHidden: true,
        },
        {
          dataIndex: 'docType',
          sdHidden: true,
        },
        {
          dataIndex: 'maintainId',
          sdHidden: true,
        },
        {
          dataIndex: 'applyId',
          sdHidden: true,
        },
        {
          dataIndex: 'roleOpt',
          sdHidden: true,
        },
        {
          dataIndex: 'indexId',
          sdHidden: true,
        },
      ],
      projectColums: [
        {
          title: '序号',
          dataIndex: 'sortNum',
          customRender: (text, record, index) => `${index + 1}`,
          width: '80px',
        },
        {
          title: '授权类型',
          dataIndex: 'empowerType',
          sdHidden: false,
        },

        {
          title: '开始日期',
          dataIndex: 'startDate',
          sdHidden: false,
        },
        {
          title: '结束日期',
          dataIndex: 'endDate',
          sdHidden: false,
        },
        {
          dataIndex: 'id',
          sdHidden: true,
        },
        {
          dataIndex: 'roleId',
          sdHidden: true,
        },
        {
          dataIndex: 'selectOrgId',
          sdHidden: true,
        },
        {
          dataIndex: 'belongedOrgId',
          sdHidden: true,
        },
        {
          dataIndex: 'docType',
          sdHidden: true,
        },
        {
          dataIndex: 'maintainId',
          sdHidden: true,
        },
        {
          dataIndex: 'applyId',
          sdHidden: true,
        },
        {
          dataIndex: 'roleOpt',
          sdHidden: true,
        },
        {
          dataIndex: 'projectOpt',
          sdHidden: true,
        },
        {
          dataIndex: 'projectId',
          sdHidden: true,
        },
        {
          dataIndex: 'indexId',
          sdHidden: true,
        },
      ],
      roleData: [],
      roleTable: [],
      roleShow: false,
      projectShow: false,
      projectData: [],
      projectTable: [],
      companyExpand: true,
      companyData: [],
      companycolumns: [
        {
          title: '序号',
          dataIndex: 'sortNum',
          customRender: (text, record, index) => `${index + 1}`,
          width: '80px',
        },
        {
          title: '公司名称',
          dataIndex: 'unitName',
          sdHidden: false,
        },
        {
          title: '公司编号',
          dataIndex: 'unitCode',
          sdHidden: false,
        },
        {
          title: '授权类型',
          dataIndex: 'empowerType',
          sdHidden: true,
        },
        {
          title: '开始日期',
          dataIndex: 'startDate',
          sdHidden: true,
        },
        {
          title: '结束日期',
          dataIndex: 'endDate',
          sdHidden: true,
        },
        {
          dataIndex: 'id',
          sdHidden: true,
        },
        {
          dataIndex: 'unitOpt',
          sdHidden: true,
        },
        {
          dataIndex: 'unitId',
          sdHidden: true,
        },
        {
          dataIndex: 'selectOrgId',
          sdHidden: true,
        },
        {
          dataIndex: 'belongedOrgId',
          sdHidden: true,
        },
        {
          dataIndex: 'docType',
          sdHidden: true,
        },
        {
          dataIndex: 'maintainId',
          sdHidden: true,
        },
        {
          dataIndex: 'applyId',
          sdHidden: true,
        },
        {
          dataIndex: 'indexId',
          sdHidden: true,
        },
      ],
      // 分类字段 分类名称 编号 描述
      classifyFileds: [
        {
          caption: '序号',
          name: 'sortNum',
          dataType: 'sortNum',
        },
        {
          // 分类名称
          caption: '分类名称',
          name: 'categoryName',
          dataType: 'string',
        },
        {
          // 分类编号
          caption: '分类编号',
          name: 'categoryId',
          dataType: 'string',
        },
        {
          // 分类描述
          caption: '分类描述',
          name: 'categoryDesc',
          dataType: 'string',
        },
        {
          dataIndex: 'indexId',
          name: 'indexId',
          dataType: 'string',
          sdHidden: true,
        },
      ],

      classIndexFileds: [
        {
          caption: '序号',
          name: 'sortNum',
          dataType: 'sortNum',
        },
        {
          caption: '业务名称',
          name: 'indexName',
          dataType: 'string',
        },
        {
          caption: '业务编号',
          name: 'id',
          dataType: 'string',
        },
        {
          caption: '系统来源名称',
          name: 'indexRemark',
          dataType: 'string',
        },
        {
          dataIndex: 'indexId',
          name: 'indexId',
          dataType: 'string',
          sdHidden: true,
        },
      ],
      classIndexData: [],
      classShow: true,
      flTableShow: false,
      indexColumns: [
        // 序号 ,业务名称 业务编号
        {
          title: '序号',
          dataIndex: 'sortNum',
          customRender: (text, record, index) => `${index + 1}`,
          width: '80px',
        },
        {
          title: '业务名称',
          dataIndex: 'indexName',
        },
        {
          title: '业务编号',
          dataIndex: 'id',
        },
        {
          title: '系统来源名称',
          dataIndex: 'indexRemark',
        },
        {
          dataIndex: 'indexId',
          sdHidden: true,
        },
      ],
      rootNodeData: null,
    }
  },
  created() {
    if (this.$route.query.selectid) {
      this.selectid = this.$route.query.selectid
      this.getmxselect(this.selectid)
      // 获取人员和单位 field
      this.getfields()
    }
  },
  mounted() {
    const userInfo = getUserInfo()
    auditMaintainService.getCompany(userInfo.account).then((res) => {
      this.rootNodeData = {
        code: res.data.id,
        name: res.data.name,
      }
      const roles = this.$store.state.sd.common.userInfo.default.roles
      const isExport = roles.map((val) => val.code).includes('G-1_DATA_AUDIT_RULE')
      if (isExport) {
        this.rootNodeData = {
          code: '28951',
          name: '国家电力投资集团有限公司',
        }
      }
    })
  },
  methods: {
    deletedClassList() {
      const ids = this.maintaindata.map((item) => item.categoryId)
      this.classIndexData = this.classIndexData.filter((item) => ids.includes(item.categoryId))
    },
    setchange(value, field, index, lx, data) {
      this.$refs[data].$refs[field.name + '_' + index][0].setFieldValue(field.name, value)
      if (data === 'pdata') {
        this.personaldata[index][field.name] = value
      } else if (data === 'rdata') {
        this.roleData[index][field.name] = value
      } else if (data === 'prodata') {
        this.projectData[index][field.name] = value
      }
      if (lx === 'type') {
        // 设置 时间两个条件
        if (value === '1') {
          this.$refs[data + '_startDate_' + index].disabled = true
          this.$refs[data + '_endDate_' + index].disabled = true
          this.$refs[data + '_endDate_' + index].rules = [
            { required: false, trigger: ['change', 'blur'] },
          ]
          this.$refs[data + '_startDate_' + index].rules = [
            { required: false, trigger: ['change', 'blur'] },
          ]
        } else {
          this.$refs[data + '_startDate_' + index].disabled = false
          this.$refs[data + '_endDate_' + index].disabled = false
          this.$refs[data + '_endDate_' + index].rules = [
            { required: true, trigger: ['change', 'blur'] },
          ]
          this.$refs[data + '_startDate_' + index].rules = [
            { required: true, trigger: ['change', 'blur'] },
          ]
        }
        if (value === '2') {
          this.$refs[data + '_startDate_' + index].disabled = true
          this.$refs[data + '_endDate_' + index].disabled = true
          this.$refs[data + '_endDate_' + index].rules = [
            { required: false, trigger: ['change', 'blur'] },
          ]
          this.$refs[data + '_startDate_' + index].rules = [
            { required: false, trigger: ['change', 'blur'] },
          ]
          // this.$refs[data + '_endDate_' + index].model.startDate = moment().endOf
          this.$refs[data + '_startDate_' + index].model.startDate = moment()
          this.$refs[data + '_endDate_' + index].model.endDate = moment().endOf('year')
        }
        // { label: '近一个月', value: '3' },
        // { label: '近三个月', value: '4' },
        // { label: '近六个月', value: '5' },
        if (value === '3') {
          this.$refs[data + '_startDate_' + index].disabled = true
          this.$refs[data + '_endDate_' + index].disabled = true
          this.$refs[data + '_endDate_' + index].rules = [
            { required: false, trigger: ['change', 'blur'] },
          ]
          this.$refs[data + '_startDate_' + index].rules = [
            { required: false, trigger: ['change', 'blur'] },
          ]
          this.$refs[data + '_startDate_' + index].model.startDate = moment()
          // 加一个月
          this.$refs[data + '_endDate_' + index].model.endDate = moment().add(1, 'months')
        }
        if (value === '4') {
          this.$refs[data + '_startDate_' + index].disabled = true
          this.$refs[data + '_endDate_' + index].disabled = true
          this.$refs[data + '_endDate_' + index].rules = [
            { required: false, trigger: ['change', 'blur'] },
          ]
          this.$refs[data + '_startDate_' + index].rules = [
            { required: false, trigger: ['change', 'blur'] },
          ]
          this.$refs[data + '_startDate_' + index].model.startDate = moment()
          this.$refs[data + '_endDate_' + index].model.endDate = moment().add(3, 'months')
        }
        if (value === '5') {
          this.$refs[data + '_startDate_' + index].disabled = true
          this.$refs[data + '_endDate_' + index].disabled = true
          this.$refs[data + '_endDate_' + index].rules = [
            { required: false, trigger: ['change', 'blur'] },
          ]
          this.$refs[data + '_startDate_' + index].rules = [
            { required: false, trigger: ['change', 'blur'] },
          ]
          this.$refs[data + '_startDate_' + index].model.startDate = moment()
          this.$refs[data + '_endDate_' + index].model.endDate = moment().add(6, 'months')
        }
      } else if (lx === 'stime') {
        // 设置 开始时间
        this.$refs[data + '_endDate_' + index].time = new Date(value).getTime()
      } else {
        this.$refs[data + '_startDate_' + index].time = new Date(value).getTime()
      }
    },
    changeunit(values) {
      let iamAuditDwMxs = []
      iamAuditDwMxs = this.unitdata
      values.forEach((element) => {
        if (iamAuditDwMxs.findIndex((dw) => dw.unitId === element.code) === -1) {
          const mmc = {}
          mmc.unitName = element.name
          mmc.unitCode = element.code
          mmc.unitId = element.id
          iamAuditDwMxs.push(mmc)
        }
      })
      this.unitdata = iamAuditDwMxs
    },
    changep(values) {
      let iamAuditPMxs = []
      iamAuditPMxs = this.personaldata
      values.forEach((element) => {
        if (iamAuditPMxs.findIndex((dw) => dw.userId === element.code) === -1) {
          const mmc = {}
          mmc.userName = element.name
          mmc.userId = element.code
          axios({
            url: 'api/xcoa-mobile/v1/iammodelmaintain/findGroupByAccount?account=' + element.code,
            method: 'get',
          }).then((res) => {
            mmc.userUnit = res.data.name
            iamAuditPMxs.push(mmc)
          })
        }
      })
      this.personaldata = iamAuditPMxs
    },
    // 选择申请单位
    dwRelSelect() {
      // 选择申请单位
      setTimeout(() => {
        this.$refs.dwRelSelect.openPicker()
      }, 0)
    },
    pRelSelect() {
      // 选择申请单位
      setTimeout(() => {
        this.$refs.pRelSelect.openPicker()
      }, 0)
    },
    roleSelect() {
      // 选择申请角色
      setTimeout(() => {
        this.$refs.roleSelect.openPicker()
      }, 0)
    },
    companylSelect() {
      // 选择申请单位
      setTimeout(() => {
        this.$refs.cRelSelect.openPicker()
      }, 0)
    },
    flRelSelect() {
      this.flTableShow = true
    },
    // 选择索引
    inedxRelSelect() {
      this.indexTableShow = true
    },
    saveForm() {
      const pdata = []
      const rdata = []
      const prodata = []
      const cdata = []
      // 至少选择一个分类
      if (this.maintaindata.length === 0) {
        Message.error('请至少选择一个分类')
        return
      }

      this.personaldata.forEach((item) => {
        let sl = null
        let el = null
        if (item.empowerType === '0') {
          if (item.startDate !== undefined) {
            const s = new Date(item.startDate)
            const e = new Date(item.endDate)
            sl = s.getTime()
            el = e.getTime()
          }
        }
        if (item.empowerType === '2') {
          sl = new Date(moment()).getTime()
          el = new Date(moment().endOf('year')).getTime()
        }
        // 3 4 5
        if (item.empowerType === '3') {
          sl = new Date(moment()).getTime()
          el = new Date(moment().add(1, 'months')).getTime()
        }
        if (item.empowerType === '4') {
          sl = new Date(moment()).getTime()
          el = new Date(moment().add(3, 'months')).getTime()
        }
        if (item.empowerType === '5') {
          sl = new Date(moment()).getTime()
          el = new Date(moment().add(6, 'months')).getTime()
        }
        pdata.push({
          docType: 'date',
          empowerType: item.empowerType,
          startDate: sl,
          endDate: el,
          userId: item.userId,
          userUnit: item.userUnit,
          userName: item.userName,
        })
      })
      this.roleData.forEach((item) => {
        let sl = null
        let el = null
        if (item.empowerType === '0') {
          if (item.startDate !== undefined) {
            const s = new Date(item.startDate)
            const e = new Date(item.endDate)
            sl = s.getTime()
            el = e.getTime()
          }
        }
        if (item.empowerType === '2') {
          sl = new Date(moment()).getTime()
          el = new Date(moment().endOf('year')).getTime()
        }
        rdata.push({
          docType: 'date',
          empowerType: item.empowerType,
          startDate: sl,
          endDate: el,
          roleId: item.roleId,
          roleName: item.roleName,
        })
      })
      this.projectData.forEach((item) => {
        let sl = null
        let el = null
        if (item.empowerType === '0') {
          if (item.startDate !== undefined) {
            const s = new Date(item.startDate)
            const e = new Date(item.endDate)
            sl = s.getTime()
            el = e.getTime()
          }
        }
        if (item.empowerType === '2') {
          sl = new Date(moment()).getTime()
          el = new Date(moment().endOf('year')).getTime()
        }
        prodata.push({
          docType: 'date',
          empowerType: item.empowerType,
          startDate: sl,
          endDate: el,
          projectId: item.projectId,
          projectName: item.projectName,
        })
      })
      this.companyData.forEach((item) => {
        let sl = null
        let el = null
        if (item.empowerType === '2') {
          sl = new Date(moment()).getTime()
          el = new Date(moment().endOf('year')).getTime()
        }
        cdata.push({
          docType: 'date',
          empowerType: item.empowerType,
          startDate: sl,
          endDate: el,
          unitCode: item.unitCode,
          unitName: item.unitName,
          unitId: item.unitId,
        })
      })

      this.$refs.pdata.valid().then((res) => {
        if (res) {
          this.$refs.rdata.valid().then((res) => {
            if (res) {
              this.$refs.prodata.valid().then((res) => {
                if (res) {
                  if (
                    pdata.length === 0 &&
                    prodata.length === 0 &&
                    rdata.length === 0 &&
                    cdata.length === 0 &&
                    this.classIndexData.length === 0
                  ) {
                    Modal.warning({
                      title: '提示',
                      content: '请至少选择一个授权项!',
                    })
                    return false
                  }
                  const params = {
                    iamDataCategoryEntities: this.maintaindata,
                    iamLicenseUnitEntities: [],
                    iamLicensePeopleEntities: pdata,
                    iamLicenseProjectEntities: prodata,
                    iamLicenseRoleEntities: rdata,
                    iamAppointUnitEntities: cdata,
                    iamSearchCategoryidIndexnameEntities: this.classIndexData,
                  }
                  auditMaintainService.saveIamAuditMaintain(params).then((res) => {
                    if (res) {
                      Message.success('保存成功', 1).then((res) => {
                        this.close(true)
                      })
                    }
                  })
                }
              })
            }
          })
        }
      })
    },
    close(flag) {
      crossWindowWatcher.notifyChange(this.$route.fullPath, flag)
      window.close()
    },
    showSelection() {
      return true
    },
    onSelectChange(selectedRowKeys) {
      this.selectedRowKeys = selectedRowKeys
    },
    // 获取table字段信息
    getfields() {
      axios({
        url: 'api/xcoa-mobile/v1/page/wp/audit/maintain/iamLicenseRole',
        method: 'get',
      }).then((res) => {
        this.roleTable = res.data.pageFormData.pageFieldInfos
        this.roleTable.find((item) => item.name === 'empowerType').attr.mandatory = 'false'
      })
      axios({
        url: 'api/xcoa-mobile/v1/page/wp/audit/maintain/iamLicensePeople',
        method: 'get',
      }).then((res) => {
        this.personal = res.data.pageFormData.pageFieldInfos
      })
      axios({
        url: 'api/xcoa-mobile/v1/page/wp/audit/maintain/iamLicenseUnit',
        method: 'get',
      }).then((res) => {
        this.unit = res.data.pageFormData.pageFieldInfos
        this.unit.find((item) => item.name === 'empowerType').attr.mandatory = 'false'
      })
      axios({
        url: 'api/xcoa-mobile/v1/page/wp/audit/maintain/iamLicenseProject',
        method: 'get',
      }).then((res) => {
        this.projectTable = res.data.pageFormData.pageFieldInfos
        this.projectTable.find((item) => item.name === 'empowerType').attr.mandatory = 'false'
      })
    },
    getmxselect(ids) {
      const arrid = ids.split(',')
      arrid.forEach((id) => {
        auditMaintainService.findIamAuditMaintain(id).then((data) => {
          this.maintaindata.push(data)
        })
      })
    },
    changeRole(values) {
      let iamAuditDwMxs = []
      iamAuditDwMxs = this.roleData
      values.forEach((element) => {
        if (iamAuditDwMxs.findIndex((dw) => dw.roleId === element.id) === -1) {
          const mmc = {}
          mmc.roleName = element.name
          mmc.roleId = element.id
          iamAuditDwMxs.push(mmc)
        }
      })
      this.roleData = iamAuditDwMxs
    },
    changeProject(values) {
      let iamAuditDwMxs = []
      iamAuditDwMxs = this.projectData
      values.forEach((element) => {
        if (iamAuditDwMxs.findIndex((dw) => dw.projectId === element.id) === -1) {
          const mmc = {}
          mmc.projectName = element.projectTitle
          mmc.projectId = element.id
          mmc.projectUnit = element.leadUnitName
          iamAuditDwMxs.push(mmc)
        }
      })
      this.projectData = iamAuditDwMxs
    },
    changecompany(values) {
      let iamAuditDwMxs = []
      iamAuditDwMxs = this.companyData
      values.forEach((element) => {
        if (iamAuditDwMxs.findIndex((dw) => dw.unitId === element.code) === -1) {
          const mmc = {}
          mmc.unitName = element.name
          mmc.unitCode = element.code
          mmc.unitId = element.id
          iamAuditDwMxs.push(mmc)
        }
      })
      this.companyData = iamAuditDwMxs
    },
    listMxSelected(keys, keyinfos) {
      let iamAuditDwMxs = []
      iamAuditDwMxs = this.classIndexData
      const ids = this.classIndexData.map((item) => parseInt(item.id))
      keyinfos.forEach((element) => {
        if (ids.indexOf(parseInt(element.id)) === -1) {
          element.empowerType = null
          element.startDate = null
          element.endDate = null
          iamAuditDwMxs.push(element)
        }
      })
      this.classIndexData = iamAuditDwMxs
    },
    classListMxSelected(keys, keyinfos) {
      const iamAuditMxs = this.maintaindata
      const onSelect = this.maintaindata.map((item) => parseInt(item.id))
      keyinfos.map((item) => {
        if (onSelect.indexOf(item.id) === -1) {
          // 判断当前模型ID是否存在存在则不添加
          const mmc = {}
          mmc.categoryName = item.categoryName
          mmc.categoryId = item.categoryId
          mmc.categoryDesc = item.categoryDesc
          mmc.id = item.id
          iamAuditMxs.push(mmc)
        }
      })
      this.maintaindata = iamAuditMxs
      // 清空审搜数据
      // this.classIndexData = []
    },
  },
}
</script>

<style module lang="scss">
@use '@/common/design' as *;
.btnselect {
  position: relative;
  top: 4px;
  right: 80px;
  float: right;
  padding: 4px 0;
  .batchselect {
    z-index: 100;
    margin-left: 10px;
  }
}
:global(.maintaintable) {
  :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>
