<template>
  <div ref="functionList" class="summary-archive-content">
<!--    <div class="summary-archive-content-card" :style="{ height: chartHeight }">-->
      <!-- 查询、导出 -->
      <a-card>
        <div class="functionList-from">
          <a-form layout="vertical">
            <a-row :gutter="24">
              <!-- 结构 -->
              <a-col :xl="8" :lg="8" :md="12" :sm="24" :xs="24">
                <a-form-item :label="$t('summary-Archive.function-list.structure')">
                  <!-- 勾选模式选择 -->
                  <span class="radio-group-class">
                    <a-radio-group @change="radioChange" :default-value="1" size="small">
                      <a-radio :value="2" class="level-radio">
                        <a-tooltip>
                          <template slot="title">
                            {{ $t('summary-archive.function.same-level-check') }}
                          </template>
                          {{ $t('summary-archive.function.same-level-check') }}
                        </a-tooltip>
                      </a-radio>
                      <a-radio :value="3" class="level-radio">
                        <a-tooltip>
                          <template slot="title">
                            {{ $t('summary-archive.function.check-with-same-superior') }}
                          </template>
                          {{ $t('summary-archive.function.check-with-same-superior') }}
                        </a-tooltip>
                      </a-radio>
                      <a-radio :value="1" class="level-radio">
                        <a-tooltip>
                          <template slot="title">
                            {{ $t('summary-archive.function.unlimited') }}
                          </template>
                          {{ $t('summary-archive.function.unlimited') }}
                        </a-tooltip>
                      </a-radio>
                    </a-radio-group>
                  </span>
                  <!-- 结构节点树下拉选 -->
                  <a-tree-select ref="leftTree" v-model="searchParams.struId" treeCheckable treeCheckStrictly
                    :dropdown-style="{ maxHeight: '400px', overflow: 'auto' }"
                    :placeholder="$t('summary-Archive.function-list.please-select-a-structure')" allow-clear show-search
                    :showArrow="true" tree-default-expand-all :replaceFields="replaceFields"
                    :filterTreeNode="filterTreeNode" :tree-data="treeData" @select="selectBtn" @change="treeSelectChange">
                    <template #title="{ value: val, title }">
                      <template>{{ title }}</template>
                    </template>
                  </a-tree-select>
                </a-form-item>
              </a-col>
              <!-- 是否显示特性 默认为否-->
              <a-col :xl="6" :lg="8" :md="12" :sm="24" :xs="24">
                <a-form-item :label="$t('summary-Archive.function-list.whether-to-display-features')">
                  <a-select :default-value="0" v-model="searchParams.isShowFeature"
                    :placeholder="$t('global-constant.please-select') + $t('summary-Archive.function-list.whether-to-display-features')"
                    allow-clear>
                    <!-- 是 -->
                    <a-select-option :value="1">
                      {{ $t('global-constant.flag-status.yes') }}
                    </a-select-option>
                    <!-- 否 -->
                    <a-select-option :value="0">
                      {{ $t('global-constant.flag-status.no') }}
                    </a-select-option>
                  </a-select>
                </a-form-item>
              </a-col>
              <a-col :xl='10' :lg='8' :md='24' :sm='24' :xs='24'>
                <a-form-item class='tr' :label="'\xa0'">
                  <a-button type="primary"  @click="search">
                    {{ $t("global-btn.search") }}
                  </a-button>
                </a-form-item>
              </a-col>
            </a-row>
          </a-form>
        </div>
      </a-card>
      <!-- 表格 -->
      <a-card style="border-radius:10px 10px 0px 0px">
        <template slot="extra">
          <a-row class='tr'>
            <a-button type="primary" @click="excelExport">
              {{ $t("global-btn.export") }}
            </a-button>
          </a-row>
        </template>
        <div :style="{ height: chartHeight }">
          <a-table ref="tableRef" :key="tableKey" :data-source="tableData" :columns="tableColumns"
            :rowKey="(row, index) => { return row.key; }" bordered size="small" :loading="tableLoading"
            @change="tableChange" :pagination="pagination" :scroll="{ x: tableWidth, y: tableHeightValue }"
            :expandable="{ rows: true, childrenColumnName: 'children' }" @expand="expandRows" :expandIconColumnIndex="1"
            :expand-row-keys="expandedRowKeys" defaultExpandAllRows :components='components'>
            <!-- 序号 -->
            <template slot="index" slot-scope="text, record, index">
              <span :title="text"> {{ (pagination.current - 1) * pagination.pageSize + index + 1 }} </span>
            </template>
            <!-- 功能种类 -->
            <template slot="functionType" slot-scope="text, record">
              <span :title="text"> {{ functionTypeMap[record.functionType] }} </span>
            </template>
          </a-table>
        </div>
      </a-card>
    </div>
</template>

<script>

import { arrayToTree } from "@/utils/tree";
import VueDraggableResizable from "vue-draggable-resizable";

export default {
  name: "FunctionList",
  components: {
    VueDraggableResizable
  },
  data() {
    // 表格拖拽
    this.components = {
      header: {
        cell: (h, props, children) => {
          const { key, ...restProps } = props;
          // 此处的this.columns 是定义的table的表头属性变量
          const col = this.tableColumns.find((col) => {
            const k = col.dataIndex || col.key;
            return k === key;
          });
          if (!col || !col.width) {
            return h('th', { ...restProps }, [...children]);
          }
          const dragProps = {
            key: col.dataIndex || col.key,
            class: 'table-draggable-handle',
            attrs: {
              w: 10,
              x: col.width,
              z: 1,
              axis: 'x',
              draggable: true,
              resizable: false
            },
            on: {
              dragging: (x, y) => {
                col.width = Math.max(x, 35);
              }
            }
          };
          const drag = h('vue-draggable-resizable', { ...dragProps });
          return h('th', { ...restProps, class: 'resize-table-th' }, [...children, drag]);
        }
      }
    };
    return {
      // 表格总宽度
      tableWidth: 0,
      // 表格各列宽度总和
      columnsWidth: 0,
      tableKey: 0,
      // 当前选中的层级
      deepCurrent: '',
      // 同级勾选是否启动
      checkIdShow: false,
      // 同父级勾选是否启动
      sameSuperCheckFlag: false,
      // 判断是勾选还是删除
      checkedEvent: false,
      // 完全受控数据
      currentChecked: [],
      // 节点下拉选原始数据
      struNodeList: [],
      // 当前选中节点的父节点
      currentPid: '',
      /** 统计每一个struId重复了多少次 用来做单元格合并显示 */
      structIdCountMap: {},
      /** 统计每一个functionId重复了多少次 用来做单元格合并显示 */
      functionIdCountMap: {},
      /** 表格数据 */
      tableData: [],
      /** 表格列头 */
      tableColumns: [
        // 序号
        {
          title: () => this.$t("summary-Archive.function-list.serial-number"),
          width: 100,
          align: "center",
          scopedSlots: { customRender: "index" }
        },
        // 产品名称（结构名称）
        {
          title: () => this.$t("summary-Archive.function-list.product-name"),
          width: 300,
          align: "center",
          key: "struName",
          dataIndex: "struName",
          ellipsis: true,
          // 如果struId相同，则合并单元格，只显示一个产品名称
          customRender: (value, row) => {
            const obj = {
              children: value,
              attrs: {},
            };
            if (row.structShowFlag) {
              obj.attrs.rowSpan = this.structIdCountMap.get(row.struId);
            } else if (row.structShowFlag === false) {
              obj.attrs.rowSpan = 0;
            }
            return obj;
          },
        },
        // 功能
        {
          title: () => this.$t("summary-Archive.function-list.function"),
          width: 350,
          align: "center",
          key: "functionName",
          dataIndex: "functionName",
          ellipsis: true,
          // 如果functionId相同，则合并单元格，只显示一个功能名称
          customRender: (value, row) => {
            const obj = {
              children: value,
              attrs: {},
            };
            if (row.functionShowFlag) {
              obj.attrs.rowSpan = this.functionIdCountMap.get(row.functionId);
            } else if (row.functionShowFlag === false) {
              obj.attrs.rowSpan = 0;
            }
            return obj;
          },
        },
        // 要求
        {
          title: () => this.$t("summary-Archive.function-list.require"),
          width: 300,
          align: "center",
          key: "reqName",
          dataIndex: "reqName",
          ellipsis: true
        },
        // 规格值
        {
          title: () => this.$t("summary-Archive.function-list.specification-value"),
          width: 350,
          align: "center",
          key: "standardValue",
          dataIndex: "standardValue",
          ellipsis: true
        },
        // 功能种类
        {
          title: () => this.$t("summary-Archive.function-list.function-category"),
          width: 200,
          align: "center",
          key: "functionType",
          dataIndex: "functionType",
          scopedSlots: { customRender: "functionType" }
        }
      ],
      /** 表格分页 */
      pagination: {
        // 当前页数
        current: 1,
        // 每页条数
        pageSize: 10,
        // 用于显示数据总量和当前数据顺序
        showTotal: total => this.$t("global-constant.table.show-total", [total]),
        // 是否可以改变 pageSize
        showSizeChanger: true,
        // 指定每页可以显示多少条
        pageSizeOptions: ["10", "20", "50", "100", "200"],
        // pageSize 变化的回调
        onShowSizeChange: (current, pageSize) => (this.pageSize = pageSize),
        // 总条数
        total: 0
      },
      /** 表格Loading */
      tableLoading: false,
      /** 树数据 */
      treeData: [],
      /** 替换 treeNode 中 title,key,children,value 字段为 treeData 中对应的字段 */
      replaceFields: {
        children: "children",
        label: "name",
        key: "id",
        value: "id"
      },
      /** 检索条件 */
      searchParams: {
        /** FMEA标识 */
        fmeaId: this.$store.getters.rfmeaId,
        struId: undefined,
        /** 是否显示特性 */
        isShowFeature: 0,
        /** 分页 */
        pageCurrent: 1,
        pageSize: 10
      },
      /** 接收整理完毕的结构树勾选的结构id */
      structIds: [],
      /** 未整理过的备用tableData */
      standbyTableData: [],
      /** 功能种类Map */
      functionTypeMap: {
        '02': this.$t('global-dict.function'),
        '04': this.$t('global-dict.product-features')
      },
      expandedRowKeys: [],
      /** 表格高度 */
      tableHeightValue: window.innerHeight - 370,
      chartHeight: window.innerHeight - 125 + 'px'
    };
  },
  watch: {
    tableColumns: {
      handler() {
        this.$nextTick(() => {
          // 获取表格的总宽度
          this.handleResize();
          // 计算 width 属性的总和
          this.getColumnWidthTotal();
          // 动态修改fixe属性
          this.changeFixed();
        });
      },
      deep: true,
      immediate: true
    },
    tableWidth: {
      handler() {
        this.$nextTick(() => {
          // 获取表格的总宽度
          this.handleResize();
          // 计算 width 属性的总和
          this.getColumnWidthTotal();
          // 动态修改fixe属性
          this.changeFixed();
        });
      },
      deep: true,
      immediate: true
    }
  },
  mounted() {
    this.getTreeSelect();
    this.list();
    window.onresize = () => {
      this.chartHeight = window.innerHeight - 125 + 'px';
      this.tableHeightValue = window.innerHeight - 370;
    };
  },

  // 剔除页面窗体大小变化得监听事件
  beforeDestroy() {
    window.removeEventListener('resize', this.handleResize);
  },

  methods: {
    // 获取表格的总宽度
    handleResize() {
      this.tableWidth = this.$refs.tableRef !== undefined ? this.$refs.tableRef.$el.offsetWidth : 1;
    },
    // 计算表格各列宽度总和
    getColumnWidthTotal() {
      this.columnsWidth = this.tableColumns.reduce((sum, column) => sum + column.width, 0);
    },
    // 动态修改fixe的属性以便表格样式不出现空白列,并平和各列与表格的总宽度
    changeFixed() {
      if (this.columnsWidth <= this.tableWidth) {
        // 遍历 Columns 数组，将有 fixed 属性的元素的 fixed 值设置为 false（当有固定列时，列宽总和小于表格总宽度时会串行）
        this.tableColumns.forEach((column) => {
          if (column.fixed) {
            column.fixed = false;
          }
        });
        // 获取除最后一列以外其他列的宽度总和
        let otherColumnsWidth = this.tableColumns.slice(0, -1).reduce((total, column) => {
          return total + column.width;
        }, 0);
        // 将最后一列的宽度设置为剩余宽度，避免页面表头与内容显示串行
        this.tableColumns[this.tableColumns.length - 1].width = this.tableWidth - otherColumnsWidth;
      } else {
        // 恢复固定列原始定位属性
        this.tableColumns[0].fixed = 'left';
        // this.tableColumns[1].fixed='left';
        // this.tableColumns[this.tableColumns.length - 1].fixed='right';
        // 恢复最后一列原始宽度
        this.tableColumns[this.tableColumns.length - 1].width = 350;
      }
    },

    /**
     * 输入项筛选
     * @param inputValue
     * @param treeNode
     */
    filterTreeNode(inputValue, treeNode) {
      return treeNode.data.props.name.includes(inputValue);
    },

    /**
     * 搜索
     */
    search() {
      this.pagination.current = 1;
      this.list();
    },

    /**
     * 获取Tree下拉
     */
    getTreeSelect() {
      let _that = this;
      _that.$api.getLeftTree({ fmeaId: _that.$store.getters.rfmeaId }).then(res => {
        if (res.flag) {
          _that.struNodeList = res.data.mfmeaStruTreeModels;
          let targetNode = res.data.mfmeaStruTreeModels.filter(item => {
            return item.pid === "00000000000000000000000000000000";
          })[0];
          // 数组转Tree
          _that.treeData = arrayToTree(targetNode, res.data.mfmeaStruTreeModels);
        } else {
          _that.$message.error(res.message, 1);
        }
      }).catch(error => {
        _that.$message.error(error.response.data.message, 1);
      });
    },

    /**
     * Excel导出
     */
    excelExport() {
      // 结构id处理
      let tempData = [];
      if (this.searchParams.struId && this.searchParams.struId.length > 0) {
        this.searchParams.struId.forEach(item => {
          tempData.push(item.value);
        })
      }
      let rfmeaId = this.$store.getters.rfmeaId;
      let struIds = tempData || "";
      let showFeature = this.searchParams.isShowFeature;
      let url =
        this.$api.baseUrl +
        "/DFMEA/rdfmFunctionList/export?fmeaId=" +
        rfmeaId +
        "&struIds=" +
        struIds +
        "&showFeature=" +
        showFeature;
      window.open(url);
    },

    /**
     * 整理搜索数据
     * @param val
     */
    buildSearchData(val) {
      if (val !== undefined && val.length > 0) {
        this.structIds = [];
        val.forEach(item => {
          this.structIds.push(item.value);
        });
      } else {
        this.structIds = [];
      }
    },

    /**
     * 整理表格数据
     * 构造合并单元格数据和展开折叠数据
     * @param val
     * @param expand
     * @returns {({structId: number, functionId: number, functionName: string, structName: string, standerValue: string, requireName: string, functionType: string}|{structId: number, functionId: number, functionName: string, structName: string, standerValue: string, requireName: string, functionType: string}|{structId: number, functionId: number, functionName: string, structName: string, standerValue: string, requireName: string, functionType: string}|{structId: number, functionId: number, functionName: string, structName: string, standerValue: string, requireName: string, functionType: string}|{structId: number, functionId: number, functionName: string, structName: string, standerValue: string, requireName: string, functionType: string})[]}
     */
    buildTableData(val, expand) {
      // 给表格数据每一行加上key字段，方便之后进行表格单元格合并和展开折叠
      if (val.length > 0) {
        let index = 0;
        val.forEach(item => {
          index += 1;
          item.key = index;
        });
      }
      // 备用的tableData，表格展开折叠初始化时，需要用到
      this.standbyTableData = val;

      // 统计structId重复次数
      let structIdCountMap = new Map();
      // 统计functionId重复次数
      let functionIdCountMap = new Map();

      /**
       * 循环表格每一行数据，统计structId和functionId重复次数
       * 并在每个structId和functionId第一次出现的行，添加字段showFlag，置为true，表示合并时，显示这一行
       * 其他重复的structId和functionId的行，添加字段showFlag，置为false，表示合并时，隐藏这一行
       * isExpand同理，表示是否是被展开折叠的行
       */
      val.forEach(item => {

        let structId = item.struId;
        let functionId = item.functionId ? item.functionId : null;

        // 统计structId并整理
        if (structIdCountMap.has(structId)) {
          structIdCountMap.set(structId, structIdCountMap.get(structId) + 1);
          // 当点击展开时，才合并，否则赋值为null
          item.structShowFlag = expand === false ? null : false;
          // 作为被展开折叠点击行的children
          item.isExpand = false;
          this.expandedRowKeys.push(item.key);
        } else {
          structIdCountMap.set(structId, 1);
          item.structShowFlag = expand === false ? null : true;
          item.isExpand = true;
          item.children = [];
        }

        // 统计functionId并整理
        if (functionId) {
          if (functionIdCountMap.has(functionId)) {
            functionIdCountMap.set(functionId, functionIdCountMap.get(functionId) + 1);
            item.functionShowFlag = expand === false ? null : false;
          } else {
            functionIdCountMap.set(functionId, 1);
            item.functionShowFlag = expand === false ? null : true;
          }
        } else {
          item.functionShowFlag = null
        }
      });
      this.structIdCountMap = structIdCountMap;
      this.functionIdCountMap = functionIdCountMap;
      return val;
    },

    /**
     * 表格行折叠展开事件
     * @param isExpand
     * @param record
     */
    expandRows(isExpand, record) {
      // 初始化，折叠
      if (isExpand === false && record === null) {
        let buildData = this.buildTableData(this.standbyTableData, false);
        let children = [];

        buildData.forEach(item => {
          if (!item.isExpand) {
            children.push(item);
          }
        });

        buildData = buildData.filter(item => item.isExpand === true);

        buildData.forEach(item => {
          if (item.isExpand) {
            item.children = children.filter(child => child.struId === item.struId);
          }
        });
        this.tableData = buildData;
      }

      // 初始化，展开
      if (isExpand && record === null) {
        this.tableData = this.buildTableData(this.tableData, true);
      }

      // 点击折叠时，构造children列
      if (isExpand === false && record !== null) {
        // 找到与点击行相同structId但不包括点击行的数据
        let foldData = (this.tableData.filter(item => item.struId === record.struId)).slice(1);
        foldData.forEach(item => {
          item.structShowFlag = null;
          item.functionShowFlag = null;
        });
        // 设置折叠数据
        record.children = foldData;
        record.structShowFlag = null;
        record.functionShowFlag = null;
        this.tableData = this.tableData.map(item => {
          return item.key === record.key ? record : item;
        });

        // 删除被折叠数据
        let afterDeleteData = this.tableData;
        foldData.forEach(item => {
          afterDeleteData = afterDeleteData.filter(afterDelete => afterDelete.key !== item.key);
        });
        this.tableData = afterDeleteData;
      }

      // 点击展开时，合并单元格
      if (isExpand && record !== null) {
        // 先取出该行的children，再把该行的children置空
        let children = record.children;
        record.children = [];
        // 设置结构合并数据
        record.structShowFlag = true;
        // 用于判断该结构的功能是否合并
        let functionShowList = [record, ...children];

        let functionIdCountMap = new Map();
        // 设置功能是否合并
        functionShowList.forEach(item => {

          let functionId = item.functionId ? item.functionId : null;

          if (functionId) {
            if (functionIdCountMap.has(functionId)) {
              functionIdCountMap.set(functionId, functionIdCountMap.get(functionId) + 1);
              item.functionShowFlag = false;
            } else {
              functionIdCountMap.set(functionId, 1);
              item.functionShowFlag = true;
            }
          } else {
            item.functionShowFlag = null
          }
        });

        // 替换元素
        this.tableData = this.tableData.map(item => {
          return item.key === record.key ? functionShowList[0] : item;
        });

        children = functionShowList.slice(1);

        // 插入元素的索引
        let insertIndex = -1;

        for (let i = 0; i < this.tableData.length; i++) {
          if (this.tableData[i].key === record.key) {
            insertIndex = i + 1; // 在找到的对象后面插入，所以索引加1
            break;
          }
        }

        // 再将该行的children，插入tableData中。
        if (insertIndex !== -1) {
          children.forEach(item => {
            item.structShowFlag = false;
            this.tableData.splice(insertIndex, 0, item);
            insertIndex += 1;
          });
        }
      }
    },

    /**
     * 列表
     */
    list() {
      let _that = this;
      _that.tableLoading = true;
      _that.buildSearchData(_that.searchParams.struId);
      let data = {
        fmeaId: _that.searchParams.fmeaId,
        struIds: _that.structIds,
        showFeature: _that.searchParams.isShowFeature,
        pagination: {
          pageCurrent: _that.pagination.current,
          pageSize: _that.pagination.pageSize
        }
      };
      _that.$api.getFunctionList(data).then(res => {
        if (res.flag) {
          _that.tableData = JSON.parse(JSON.stringify(res.data.data)) || [];
          _that.expandRows(true, null);
          _that.pagination.current = res.data.pageNo;
          _that.pagination.pageSize = res.data.pageSize;
          _that.pagination.total = res.data.total;
          _that.tableKey = _that.pagination.current;
        } else {
          _that.$message.error(res.message);
        }
      }).finally(() => {
        _that.tableLoading = false;
      });
    },
    /**
     * Tree下拉选择事件时
     * @param value
     * @param option
     */
    treeSelectChange(value, option) {
      this.searchParams.struId = value;
      let checkList = [];
      let checkIds = [];
      if (this.sameSuperCheckFlag == true) {
        //当同级勾选按钮打开，并且是勾选添加时
        if (this.checkedEvent == true) {
          this.struNodeList.forEach(item => {
            if (item.deep == this.deepCurrent && item.pid == this.currentPid) checkList.push(item);
          });
          checkList.forEach(item => {
            let ids = {
              lable: item.name,
              value: item.id,
            }
            checkIds.push(ids);
          });
          let result = checkIds.concat(this.searchParams.struId);
          let arrayResult = result.filter((currentValue, currentIndex, selfArr) => {
            return selfArr.findIndex(item => item.value === currentValue.value) === currentIndex;
          });
          this.searchParams.struId = arrayResult;
          // 暂存选中数据，取消勾选时使用
          this.currentChecked = arrayResult;
        } else {
          //当同级勾选按钮打开，并且是勾选取消时
          // 对比数组，找到当前勾选的层级
          let arr1 = this.currentChecked.filter(item => {
            return !this.searchParams.struId.find(prop => {
              return prop.value == item.value
            })
          });
          let currentUnCheckedNode = this.struNodeList.filter(item => {
            return item.id === arr1[0].value;
          })
          this.deepCurrent = currentUnCheckedNode[0] ? currentUnCheckedNode[0].deep : undefined;
          this.currentPid = currentUnCheckedNode[0] ? (currentUnCheckedNode[0].pid ? currentUnCheckedNode[0].pid : undefined) : undefined;
          //根据当前勾选的层级，找到所有相同的层级
          this.struNodeList.forEach(item => {
            if (item.deep == this.deepCurrent && item.pid == this.currentPid) checkList.push(item);
          });
          checkList.forEach(item => {
            let ids = {
              lable: item.name,
              value: item.id,
            }
            checkIds.push(ids);
          });
          //把找到相同数据的层级从勾选的数据中删除
          const result = this.searchParams.struId.filter((itemA) => {
            return !checkIds.some((itemB) => itemA.value == itemB.value);
          })
          this.searchParams.struId = result;
          this.currentChecked = result;
        }
      } else if (this.checkIdShow == true) {
        //当同级勾选按钮打开，并且是勾选添加时
        if (this.checkedEvent == true) {
          this.struNodeList.forEach(item => {
            if (item.deep == this.deepCurrent) checkList.push(item);
          });
          checkList.forEach(item => {
            let ids = {
              lable: item.name,
              value: item.id,
            }
            checkIds.push(ids);
          });
          let result = checkIds.concat(this.searchParams.struId);
          let arrayResult = result.filter((currentValue, currentIndex, selfArr) => {
            return selfArr.findIndex(item => item.value === currentValue.value) === currentIndex;
          });
          this.searchParams.struId = arrayResult;
          // 暂存选中数据，取消勾选时使用
          this.currentChecked = arrayResult;
        } else {
          //当同级勾选按钮打开，并且是勾选取消时
          // 对比数组，找到当前勾选的层级
          let arr1 = this.currentChecked.filter(item => {
            return !this.searchParams.struId.find(prop => {
              return prop.value == item.value
            })
          });
          let currentUnCheckedNode = this.struNodeList.filter(item => {
            return item.id === arr1[0].value;
          })
          this.deepCurrent = currentUnCheckedNode[0] ? currentUnCheckedNode[0].deep : undefined;
          //根据当前勾选的层级，找到所有相同的层级
          this.struNodeList.forEach(item => {
            if (item.deep == this.deepCurrent) checkList.push(item);
          });
          checkList.forEach(item => {
            let ids = {
              lable: item.name,
              value: item.id,
            }
            checkIds.push(ids);
          });
          //把找到相同数据的层级从勾选的数据中删除
          const result = this.searchParams.struId.filter((itemA) => {
            return !checkIds.some((itemB) => itemA.value == itemB.value);
          })
          this.searchParams.struId = result;
          this.currentChecked = result;
        }
      } else {
        this.searchParams.struId = value;
      }
      this.checkedEvent = false;
    },
    /**
     * 表格点击分页中数字触发的方法
     * @param pagination
     */
    tableChange(pagination) {
      this.pagination.current = pagination.current;
      this.pagination.pageSize = pagination.pageSize;
      this.searchParams.pageCurrent = pagination.current;
      this.searchParams.pageSize = pagination.pageSize;
      this.list();
    },
    /**
     * 单选框改变事件
     */
    radioChange(e) {
      let radio = e.target.value;
      if (radio === 1) {
        this.checkIdShow = false;
        this.sameSuperCheckFlag = false;
      } else if (radio === 2) {
        this.checkIdShow = true;
        this.sameSuperCheckFlag = false;
      } else if (radio === 3) {
        this.checkIdShow = false;
        this.sameSuperCheckFlag = true;
      }
    },
    /**
     * tree 完全受控  选中
     * @param even
     * @param evenT
     * @param evenTR
     */
    selectBtn(even, evenT, evenTR) {
      this.checkedEvent = true; //判断是勾选添加还是删除
      this.currentChecked = evenTR.checkedNodes;
      let i = evenTR.checkedNodes.length - 1;
      this.deepCurrent = evenTR.checkedNodes[i].data.props.deep;
      this.currentPid = evenTR.checkedNodes[i].data.props.pid;
    }
  }
};
</script>

<style lang="less" scoped>
.page {
  height: calc(80vh);
  overflow: auto;
}

/deep/ .ant-table-fixed-header .ant-table-scroll .ant-table-header {
  overflow: hidden !important;
  margin-bottom: 0 !important;
  padding-right: 8px;
  background: rgb(250, 250, 250);
}

/deep/ .radio-group-class {
  float: right;
  margin-top: -30px;
}
</style>
