<template>
  <div :class="$style.wrapHeight">
    <div :class="$style.rowHeight">
      <iam-audit-frame-tree
        ref="frametree"
        :key="treekey"
        :showbtns="showBtns"
        :frame-name="frameName"
        :selected-keys="selectCategory.length > 0 ? [selectCategory[0].props.id] : []"
        @treeSelect="treeSelect"
        @treeinit="treeinit"
        @createframe="createframe"
        @changeframe="changeframe"
        @checkedKeys="checkedKeys"
      ></iam-audit-frame-tree>
      <div :class="$style.rightcard">
        <a-card :class="$style.acard">
          <!-- 按钮区域 -->
          <div v-if="showBtns" :class="$style.btndiv">
            <a-dropdown>
              <a-menu slot="overlay" @click="handleMenuClick">
                <a-menu-item key="sx"> 审计事项 </a-menu-item>
                <a-menu-item key="mb"> 审计事项模板 </a-menu-item>
              </a-menu>
              <a-button type="primary"
                >从审计指引库导入<a-icon type="down" :class="$style.btnicon"
              /></a-button>
            </a-dropdown>

            <a-button type="primary" @click="importItem">批量导入</a-button>
            <!-- <a-button type="primary" @click="exportItem">导出</a-button> -->
            <a-button type="primary" @click="createCategory">新建分类</a-button>
            <a-button type="primary" @click="createMatter">新建事项</a-button>
            <a-button :disabled="selectCategory.length === 0" @click="deleteAll">删除</a-button>
          </div>
          <!-- 审计框架新建页面 -->
          <iam-audit-frame-create
            v-if="viewname === 'createframe'"
            :key="formkey"
            :showbtns="showBtns"
            :record-id="frameRecordId"
            :read-only="formreadonly"
            @cancelform="cancelform"
            @formsaved="formsaved"
          ></iam-audit-frame-create>
          <!-- 分类新建页面 -->
          <iam-audit-frame-category-create
            v-if="viewname === 'createcategory'"
            :key="formkey"
            :showbtns="showBtns"
            :frame-id="frameSelected.key + ''"
            :parent-id="selectCategory.length > 0 ? selectCategory[0].props.id + '' : ''"
            :record-id="parseFloat(categoryRecordId)"
            :read-only="formreadonly"
            @cancelform="cancelform"
            @formsaved="formsaved"
          ></iam-audit-frame-category-create>
          <!-- 右侧区域事项列表 -->
          <iam-audit-frame-item-list
            v-if="viewname === 'itemslist'"
            ref="itemTable"
            :key="listkey"
            :showbtns="showBtns"
            :frame-id="frameSelected.key + ''"
          ></iam-audit-frame-item-list>
          <!-- 右侧分配悬浮框 -->
          <div
            :class="$style.rightUserDiv"
            :style="{ width: rightDivWidth + 'px', height: !rightDivVisible ? '135px' : 'auto' }"
          >
            <div :class="$style.leftDiv">
              <div v-if="showBtns" :class="$style.firstDiv" @click="showMattersUser"
                ><a-icon type="team"
              /></div>
              <div @click="showMattersList"><a-icon type="unordered-list" /></div>
              <div v-if="showBtns" :class="$style.lastDiv" @click="deleteAllUserRel"
                ><a-icon type="delete"
              /></div>
            </div>

            <div :class="$style.rightDiv">
              <div :class="$style.rightTopDiv" :style="{ display: rightDivVisible ? '' : 'none' }">
                <div :class="$style.userTitle">备选人员</div>
                <div :class="$style.userBtn"><span>双击添加</span> <span>单击取消</span></div>
              </div>
              <div :class="$style.rightBottomDiv">
                <div
                  v-for="oneuser in userList"
                  :key="oneuser.a"
                  :class="$style.userIcon"
                  @dblclick="saveIamAuditFrameUserRel(oneuser)"
                  @click="deleteIamAuditFrameUserRel(oneuser)"
                >
                  <div :class="$style.userIconIcon">
                    <a-badge
                      :count="oneuser.userNumber"
                      :show-zero="true"
                      :number-style="{ backgroundColor: '#f1b55a' }"
                      :offset="[0, 3]"
                    >
                      <a-avatar
                        :size="40"
                        icon="user"
                        :src="
                          `api/mobile/v1/user-manager/userAvatar/${oneuser.auditorAccount}`
                            | sdResource
                        "
                        alt="avatar"
                      />
                    </a-badge>
                  </div>
                  <div :class="$style.userName">{{ oneuser.auditorName }}</div>
                </div>
              </div>
            </div>
          </div>
        </a-card>
      </div>
    </div>
    <!-- 选择审计事项模板组件 -->
    <iam-audit-import-matters-template
      :visible="visible.mb"
      @handleCancel="handleCancel"
      @mbhandleOk="mbhandleOk"
    ></iam-audit-import-matters-template>
    <!-- 选择审计事项模板组件 -->
    <iam-audit-import-matters
      :frame-id="frameSelected ? frameSelected.key : -1"
      :visible="visible.sx"
      @handleCancel="handleCancel"
      @sxhandleOk="sxhandleOk"
    ></iam-audit-import-matters>

    <iam-audit-export-modal
      :visible="visibleImportItem"
      @importSuccess="importSuccess"
    ></iam-audit-export-modal>
  </div>
</template>

<script>
import { getUserInfo } from '@/common/store-mixin'
import axios from '@/common/services/axios-instance'
import { Modal, Message } from 'ant-design-vue'
import download from '@/common/services/download'
import crossWindowWatcher from '@/common/services/cross-window-watcher'
import iamAuditFrameCreate from './iam-audit-frame-create.vue'
import iamAuditFrameCategoryCreate from './category/iam-audit-frame-category-create.vue'
import iamAuditImportMattersTemplate from './import/iam-audit-import-matters-template.vue'
import iamAuditImportMatters from './import/iam-audit-import-matters.vue'

import iamAuditExportModal from './import/iam-audit-export-modal.vue'
import iamAuditFrameItemList from './item/iam-audit-frame-item-list.vue'
import iamAuditFrameTree from './iam-audit-frame-tree.vue'
import components from './_import-components/iam-audit-frame-import'
import iamAuditFrameService from './iam-audit-frame-service'

export default {
  name: 'IamAuditFrame',
  metaInfo: {
    title: '审计框架',
  },
  components: {
    ...components,
    iamAuditFrameTree,
    iamAuditFrameCreate,
    iamAuditFrameCategoryCreate,
    iamAuditImportMattersTemplate,
    iamAuditImportMatters,
    iamAuditFrameItemList,
    iamAuditExportModal,
  },
  data() {
    return {
      treekey: 0,
      formkey: 0,
      listkey: 0,
      userkey: 0,
      frameRecordId: null, // 审计框架信息页面recordId null为新建否则为查看
      categoryRecordId: null, // 审计框架分类页面recordId null为新建否则为查看
      viewname: '',
      formreadonly: true, // 审计框架信息页面页面是否只读
      frameName: null, // 默认展示审计框架下拉框名称
      frameSelected: null, // 当前选择的下拉框信息
      selectCategory: [], // 左侧树选择的节点id
      visible: {
        mb: false, // 审计模板弹出窗显示
        sx: false, // 审计事项弹出窗显示
      },
      rightDivWidth: 40,
      rightDivVisible: false,
      userList: [],
      clickTimer: null,
      showBtns: false, // 是否显示功能性按钮
      visibleImportItem: false,
    }
  },
  watch: {
    frameSelected() {
      // 框架有变化时，获取项目成员
      this.getProjectUser()
    },
  },
  mounted() {
    // 获取当前项目组长及副组长
    axios({
      url: `api/xcoa-mobile/v1/page/wp/audit/project/iamAuditProject`,
      params: {
        id: this.$root.$route.query.projectId,
      },
    }).then((res) => {
      // 找到组长及副组长
      const userListJson = res.data.pageFormData.pageFieldInfos.find((item) => {
        return item.name === 'iamProjectUserList'
      })
      // 项目状态
      const itemStatus = res.data.pageFormData.pageFieldInfos.find((item) => {
        return item.name === 'itemStatus'
      })
      const userList = JSON.parse(userListJson.value)
      let isLeader = false
      userList.forEach((item) => {
        if ((item.userType === '01') | (item.userType === '05')) {
          if (item.userAccount === getUserInfo().account) {
            isLeader = true
          }
        }
      })
      // 判断是否已关闭或归档
      let isOver = false
      if ((itemStatus.value === '05') | (itemStatus === '07')) {
        isOver = true
      }
      this.showBtns = isLeader && !isOver
    })
  },
  methods: {
    // 获取项目成员
    getProjectUser() {
      // 获取项目成员
      const params = {
        projectId: this.$root.$route.query.projectId,
        frameId: this.frameSelected.key,
      }
      // 如果已经获取了成员则不重新获取
      if (this.userList.length > 0) {
        return
      }
      iamAuditFrameService.getProjectUsers(params).then((res) => {
        // 判断ID重复，如果重复只显示一个
        const userIdList = []
        res.data.forEach((item) => {
          if (userIdList.indexOf(item.auditorAccount) === -1) {
            userIdList.push(item.auditorAccount)
            this.userList.push(item)
          }
        })
      })
    },
    // 更新整个用户分配的事项数量
    updateAllUserItemNums() {
      // 获取项目成员
      const params = {
        projectId: this.$root.$route.query.projectId,
        frameId: this.frameSelected.key,
      }
      iamAuditFrameService.getProjectUsers(params).then((res) => {
        this.userList = []
        // 判断ID重复，如果重复只显示一个
        const userIdList = []
        res.data.forEach((item) => {
          if (userIdList.indexOf(item.auditorAccount) === -1) {
            userIdList.push(item.auditorAccount)
            this.userList.push(item)
          }
        })
      })
    },
    // 更新用户分配的事项数量
    updateUserItemNums(userAccount, type) {
      const userObj = this.userList.find((item) => {
        return item.auditorAccount === userAccount
      })
      const params = {
        projectId: this.$root.$route.query.projectId,
        frameId: this.frameSelected.key,
      }
      iamAuditFrameService.getProjectUsers(params).then((res) => {
        const resUserObj = res.data.find((item) => {
          return item.auditorAccount === userAccount
        })
        if (userObj) {
          if (type === 'add') {
            if (userObj.userNumber === resUserObj.userNumber) {
              Message.info('分配失败，请勿分配重复事项', 1)
            } else {
              Message.success('分配完成', 1)
            }
          } else if (type === 'delete') {
            if (userObj.userNumber === resUserObj.userNumber) {
              Message.info('取消分配失败，事项未分配给当前用户', 1)
            } else {
              Message.success('取消分配完成', 1)
            }
          }
          userObj.userNumber = resUserObj.userNumber
        }
        // 分配完之后去除选择
        this.selectCategory = []
        if (this.viewname === 'itemslist') {
          this.listkey++
        }
      })
    },
    treeSelect(selectkey, info) {
      // 如果点击的是根节点
      if (info.node.dataRef.props.isroot) {
        this.frameRecordId = info.node.dataRef.props.id + ''
        this.viewname = 'createframe'
        this.formkey++
      } else if (info.node.dataRef.props.isItem === false) {
        this.categoryRecordId = info.node.dataRef.props.id + ''
        this.viewname = 'createcategory'
        this.formkey++
      } else {
        const url =
          '/iam-audit-frame-item?recordId=' +
          info.node.dataRef.props.id +
          '&readonly=' +
          (this.showBtns ? '0' : '1') // 新页面要打开的路由地址
        crossWindowWatcher.waitForChanged(url).then((refreshFlag) => {
          if (refreshFlag) {
          }
        })
      }
    },
    // 初始化树信息时默认展示审计框架信息
    treeinit(initinfo) {
      this.frameRecordId = initinfo.key + ''
      // 存储下来
      this.frameSelected = initinfo
      this.showMattersList()
    },
    // 导入选项下拉框点击事件
    handleMenuClick(e) {
      if (this.selectCategory.length === 1) {
        this.showModal(e.key)
      } else {
        Message.info('请选择单个分类或者根节点', 1)
      }
    },
    // 新建审计框架
    createframe() {
      this.viewname = 'createframe'
      this.frameRecordId = null
      this.categoryRecordId = null
      this.formreadonly = false
      this.formkey++
    },
    // 删除审计框架
    deleteframe(ids) {
      return iamAuditFrameService.deleteframe(ids)
    },
    // 取消新建审计事项
    cancelform() {
      this.viewname = 'createframe'
      this.frameRecordId = this.frameSelected.key + ''
      this.formreadonly = true
      this.formkey++
    },
    // 表单保存事件
    formsaved(frameinfo) {
      if (frameinfo) {
        this.frameName = frameinfo.frameName
      } else {
        this.frameName = this.frameSelected.label
      }

      this.formreadonly = true
      this.viewname = 'createframe'
      this.treekey++
      this.formkey++
      this.listkey++
    },
    // 审计框架下拉框变化事件
    changeframe(value, option) {
      this.viewname = 'createframe'
      this.selectCategory = []
      this.frameSelected = value
      this.frameName = value.label
      this.frameRecordId = value.key.toString()
      this.treekey++
    },
    // 新建事项
    createMatter() {
      if (this.selectCategory.length === 1) {
        if (this.selectCategory[0].props.isItem === true) {
          Message.info('事项层级下不可新建事项', 1)
          return
        }
        if (this.selectCategory[0].props.isroot === true) {
          Message.info('根节点层级下不可新建事项', 1)
          return
        }
        const url =
          '/iam-audit-frame-item?catalogId=' +
          this.selectCategory[0].props.id +
          '&catalogName=' +
          this.selectCategory[0].text +
          '&frameId=' +
          this.frameSelected.key // 新页面要打开的路由地址
        crossWindowWatcher.waitForChanged(url).then((refreshFlag) => {
          if (refreshFlag) {
            // 这里写或者调刷新的方法
            this.treekey++
            this.listkey++
          }
        })
      } else {
        Message.info('请选择单个分类或者根节点', 1)
      }
    },
    // 创建分类方法
    createCategory() {
      if (this.selectCategory.length === 1) {
        if (this.selectCategory[0].props.isItem === true) {
          Message.info('事项层级下不可新建分类', 1)
          return
        }

        this.formreadonly = false
        this.categoryRecordId = null
        this.viewname = 'createcategory'
        this.formkey++
      } else {
        Message.info('请选择单个分类或者根节点', 1)
      }
    },
    // 删除分类
    deleteCategory(ids) {
      return iamAuditFrameService.deleteCategory(ids)
    },
    // 左侧树复选选择事件监听
    checkedKeys(allKeys, echecked) {
      this.selectCategory = echecked.map((item) => {
        // item.data.props.props.id = item.data.props.id
        return item.data.props
      })
    },
    // 展示弹窗
    showModal(type) {
      this.visible[type] = true
    },
    // 隐藏弹窗
    handleCancel() {
      this.visible = {
        mb: false,
        sx: false,
      }
    },
    // 审计模板确认
    mbhandleOk(templateInfo) {
      const params = {
        templateId: templateInfo[0].id,
        parentId: this.selectCategory[0].props.id,
        frameId: this.frameSelected.key,
      }
      // 调用导入接口
      iamAuditFrameService.copyIamAuditFrameFromTemplate(params).then((res) => {
        Message.success('导入成功', 1)
        this.treekey++
      })
      // 确认之后隐藏弹窗
      this.handleCancel()
    },
    // 选择事项确认
    sxhandleOk(sxinfo) {
      const iamAuditFrameParam = {
        iamTreeNodeList: sxinfo,
        parentId: this.selectCategory[0].props.id,
        frameId: this.frameSelected.key,
      }
      // 调用导入接口
      if (sxinfo && sxinfo[0].children.length < 1) {
        Message.error('请选择审计事项')
        return
      }
      iamAuditFrameService.copyIamAuditFrameFromItem(iamAuditFrameParam).then((res) => {
        Message.success('导入成功', 1)
        this.treekey++
      })
      // 确认之后隐藏弹窗
      this.handleCancel()
    },

    // 打开分配人员窗口
    showMattersUser() {
      this.rightDivVisible = !this.rightDivVisible
      if (this.rightDivVisible) {
        this.rightDivWidth = 366
      } else {
        this.rightDivWidth = 39
      }
    },
    // 展示项目事项
    showMattersList() {
      this.viewname = 'itemslist'
    },
    // 删除方法
    deleteAll() {
      const rootId = []
      const categoryId = []
      const itemId = []
      if (this.selectCategory.length > 0) {
        this.selectCategory.forEach((item) => {
          // 框架
          if (item.props.isroot) {
            rootId.push(item.props.id)
          }
          // 分类
          if (item.props.isItem === false) {
            categoryId.push(item.props.id)
          }
          // 事项
          if (item.props.isItem) {
            itemId.push(item.props.id)
          }
        })
      }
      const selectRows = this.$refs.itemTable?.getSelectedRows()
      if (selectRows && selectRows.length > 0) {
        selectRows.forEach((item) => {
          itemId.push(item.id)
        })
      }
      // 如果没有选择，则提示信息
      if (rootId.length === 0 && categoryId.length === 0 && itemId.length === 0) {
        Message.error('请选择需要删除的信息', 1)
        return
      }

      Modal.confirm({
        title: '您确定删除这项内容吗？',
        content: '删除数据后，就无法恢复初始的状态。',
        okText: '删除',
        okType: 'danger',
        onOk: () => {
          // 只有框架
          if (rootId.length !== 0 && categoryId.length === 0 && itemId.length === 0) {
            this.deleteframe(rootId.join('')).then((res) => {
              if (!res.data) {
                Message.info('审计框架下存在审计分类或审计事项，删除失败', 1)
              } else {
                Message.success('删除成功', 1)
                this.treekey++
                this.listkey++
                this.selectCategory = []
                this.updateAllUserItemNums()
              }
            })
          }
          // 只有分类
          else if (rootId.length === 0 && categoryId.length !== 0 && itemId.length === 0) {
            this.deleteCategory(categoryId).then((res) => {
              if (res.data === 'false1') {
                Message.info('审计分类下存在审计事项，删除失败', 1)
              } else if (res.data === 'false2') {
                Message.info('审计分类下存在审计子分类，删除失败', 1)
              } else {
                Message.success('删除成功', 1)
                this.treekey++
                this.listkey++
                this.selectCategory = []
                this.updateAllUserItemNums()
              }
            })
          }
          // 只有事项
          else if (rootId.length === 0 && categoryId.length === 0 && itemId.length !== 0) {
            iamAuditFrameService.checkDeleteMatters(itemId).then((res) => {
              if (!res.data) {
                Message.info('审计事项存在正在审批的工作底稿，删除失败', 1)
              } else {
                this.deleteMatters(itemId).then((res) => {
                  Message.success('删除成功', 1)
                  this.treekey++
                  this.listkey++
                  this.selectCategory = []
                  this.updateAllUserItemNums()
                })
              }
            })
          }
          // 框架、分类
          else if (rootId.length !== 0 && categoryId.length !== 0 && itemId.length === 0) {
            this.deleteframe(rootId.join('')).then((res) => {
              if (!res.data) {
                Message.info('审计框架下存在审计分类或审计事项，删除失败', 1)
              } else {
                this.deleteCategory(categoryId).then((res) => {
                  if (res.data === 'false1') {
                    Message.info('审计分类下存在审计事项，删除失败', 1)
                  } else if (res.data === 'false2') {
                    Message.info('审计分类下存在审计子分类，删除失败', 1)
                  } else {
                    Message.success('删除成功', 1)
                    this.treekey++
                    this.listkey++
                    this.selectCategory = []
                    this.updateAllUserItemNums()
                  }
                })
              }
            })
          }
          // 框架、事项
          else if (rootId.length !== 0 && categoryId.length === 0 && itemId.length !== 0) {
            this.deleteframe(rootId.join('')).then((res) => {
              if (!res.data) {
                Message.info('审计框架下存在审计分类或审计事项，删除失败', 1)
              } else {
                iamAuditFrameService.checkDeleteMatters(itemId).then((res) => {
                  if (!res.data) {
                    Message.info('审计事项存在正在审批的工作底稿，删除失败', 1)
                  } else {
                    this.deleteMatters(itemId).then((res) => {
                      Message.success('删除成功', 1)
                      this.treekey++
                      this.listkey++
                      this.selectCategory = []
                      this.updateAllUserItemNums()
                    })
                  }
                })
              }
            })
          }
          // 分类、事项
          else if (rootId.length === 0 && categoryId.length !== 0 && itemId.length !== 0) {
            this.deleteCategory(categoryId).then((res) => {
              if (res.data === 'false1') {
                Message.info('审计分类下存在审计事项，删除失败', 1)
              } else if (res.data === 'false2') {
                Message.info('审计分类下存在审计子分类，删除失败', 1)
              } else {
                iamAuditFrameService.checkDeleteMatters(itemId).then((res) => {
                  if (!res.data) {
                    Message.info('审计事项存在正在审批的工作底稿，删除失败', 1)
                  } else {
                    this.deleteMatters(itemId).then((res) => {
                      Message.success('删除成功', 1)
                      this.treekey++
                      this.listkey++
                      this.selectCategory = []
                      this.updateAllUserItemNums()
                    })
                  }
                })
              }
            })
          }
          // 框架分类事项
          else {
            this.deleteframe(rootId.join('')).then((res) => {
              if (!res.data) {
                Message.info('审计框架下存在审计分类或审计事项，删除失败', 1)
              } else {
                this.deleteCategory(categoryId).then((res) => {
                  if (res.data === 'false1') {
                    Message.info('审计分类下存在审计事项，删除失败', 1)
                  } else if (res.data === 'false2') {
                    Message.info('审计分类下存在审计子分类，删除失败', 1)
                  } else {
                    iamAuditFrameService.checkDeleteMatters(itemId).then((res) => {
                      if (!res.data) {
                        Message.info('审计事项存在正在审批的工作底稿，删除失败', 1)
                      } else {
                        this.deleteMatters(itemId).then((res) => {
                          Message.success('删除成功', 1)
                          this.treekey++
                          this.listkey++
                          this.selectCategory = []
                          this.updateAllUserItemNums()
                        })
                      }
                    })
                  }
                })
              }
            })
          }
        },
        onCancel: () => {},
      })
    },
    // 删除事项
    deleteMatters(ids) {
      return iamAuditFrameService.deleteMatters(ids)
    },
    // 删除所选的项目下所有事项的分配人员
    deleteAllUserRel() {
      const rootId = []
      const categoryId = []
      const itemId = []
      if (this.selectCategory.length > 0) {
        this.selectCategory.forEach((item) => {
          // 框架
          if (item.props.isroot) {
            rootId.push(item.props.id)
          }
          // 分类
          if (item.props.isItem === false) {
            categoryId.push(item.props.id)
          }
          // 事项
          if (item.props.isItem) {
            itemId.push(item.props.id)
          }
        })
      } else {
        Message.error('请在左侧树选择需要取消分配审计人员的信息', 1)
        return
      }
      Modal.confirm({
        content:
          '选择分类下所有的事项（或所选择事项）分配审计人员都会被取消,是否确认操作？(已经审批或者结束的工作底稿所在分类及事项不会被取消)',
        okText: '确定',
        okType: 'danger',
        onOk: () => {
          const params = {
            frame: rootId,
            catalog: categoryId,
            item: itemId,
          }
          iamAuditFrameService.deleteUserRels(params).then((res) => {
            Message.success('取消成功', 1)
            this.treekey++
            this.listkey++
            this.updateAllUserItemNums()
          })
        },
      })
    },
    // 双击分配事项
    saveIamAuditFrameUserRel(userinfo) {
      if (this.clickTimer) {
        window.clearTimeout(this.clickTimer)
        this.clickTimer = null
      }

      const itemId = []
      if (this.selectCategory.length > 0) {
        this.selectCategory.forEach((item) => {
          if (item.props.isItem) {
            itemId.push(item.props.id)
          }
        })
      }
      const selectRows = this.$refs.itemTable?.getSelectedRows()
      if (selectRows && selectRows.length > 0) {
        selectRows.forEach((item) => {
          itemId.push(item.id)
        })
      }
      if (itemId.length === 0) {
        Message.error('请选择审计事项', 1)
        return
      }
      const iamAuditFrameUserRelParam = {
        iamAuditFrameUserRelList: [],
      }

      itemId.forEach((item) => {
        iamAuditFrameUserRelParam.iamAuditFrameUserRelList.push({
          itemId: item,
          auditorId: userinfo.auditorId,
          auditorAccount: userinfo.auditorAccount,
          auditorName: userinfo.auditorName,
          frameId: this.frameSelected.key,
        })
      })
      iamAuditFrameService.saveIamAuditFrameUserRel(iamAuditFrameUserRelParam).then((res) => {
        this.treekey++
        // 获取项目成员
        this.updateUserItemNums(userinfo.auditorAccount, 'add')
      })
    },
    // 单击取消分配事项
    deleteIamAuditFrameUserRel(userinfo) {
      if (this.clickTimer) {
        window.clearTimeout(this.clickTimer)
        this.clickTimer = null
      }
      //  实际执行方法
      this.clickTimer = setTimeout(() => {
        const itemId = []
        if (this.selectCategory.length > 0) {
          this.selectCategory.forEach((item) => {
            itemId.push(item.props.id)
          })
        }
        const selectRows = this.$refs.itemTable?.getSelectedRows()
        if (selectRows && selectRows.length > 0) {
          selectRows.forEach((item) => {
            itemId.push(item.id)
          })
        }
        if (itemId.length === 0) {
          Message.error('请选择审计事项', 1)
          return
        }
        const iamAuditFrameUserRelParam = {
          iamAuditFrameUserRelList: [],
        }

        itemId.forEach((item) => {
          iamAuditFrameUserRelParam.iamAuditFrameUserRelList.push({
            itemId: item,
            auditorId: userinfo.auditorId,
            auditorAccount: userinfo.auditorAccount,
            auditorName: userinfo.auditorName,
            frameId: this.frameSelected.key,
          })
        })
        iamAuditFrameService.deleteIamAuditFrameUserRel(iamAuditFrameUserRelParam).then((res) => {
          this.treekey++
          // 获取项目成员
          this.updateUserItemNums(userinfo.auditorAccount, 'delete')
        })
      }, 600)
    },
    // 导出
    exportItem() {
      const rootId = this.$refs.frametree.framevalue.key
      const id = this.categoryRecordId

      iamAuditFrameService.exportItem(id, rootId).then((res) => {
        if (res.status === 200) {
          const url = URL.createObjectURL(res.data)
          const filename = res.headers['content-disposition']
          const fname = filename.substring(filename.indexOf('filename=') + 9, filename.length)
          download(url, decodeURI(fname))
        } else {
          Modal.warning({
            title: '提示',
            content: '导出报错，请联系管理员!',
          })
          return false
        }
      })
    },
    // 导入
    importItem() {
      // 选择事项分类
      this.visibleImportItem = true
      this.treekey++
    },
    // 导入成功刷新列表
    importSuccess() {
      this.$refs.itemTable.refresh()
    },
  },
}
</script>

<style module lang="scss">
@use '@/common/design' as *;
.wrap-height {
  height: 100%;
  .row-height {
    display: flex;
    flex: auto;
    height: 100%;
    .rightcard {
      flex: 1;
      width: calc(100% - 20%);
      height: 100%;
      .acard {
        min-height: 100%;
      }
      :global(.ant-card-body) {
        padding: 0;
      }
    }
  }
}
// 按钮样式
.btndiv {
  float: right;
  margin-bottom: 10px;
  button {
    margin-left: 10px;
  }
}
.btnicon {
  margin-left: 3px !important;
  font-size: 12px;
}
// 右侧悬浮框样式
.right-user-div {
  position: absolute;
  top: 150px;
  right: 0;
  z-index: 6;
  width: 366px;
  overflow: hidden;
  white-space: nowrap;
  user-select: none;
  user-select: none;
  user-select: none;
  background: #fff;
  transition: all 0.1s ease-out;
}
.left-div {
  float: left;
  width: 40px;
  div {
    height: 40px;
    padding-top: 5px;
    padding-left: 10px;
    font-size: 20px;
    color: #1890ff;
    cursor: pointer;
    background: #d5d5d5;
  }
  .first-div {
    color: #fff;
    background: #1890ff;
    border-radius: 3px 0 0 0;
  }
  .last-div {
    background: #efefef;
    border-radius: 0 0 0 3px;
  }
}
.right-div {
  margin-left: 40px;
  border: 1px solid #dbdbdb;
  .right-top-div {
    height: 40px;
    margin: 0 10px;
    line-height: 40px;
    border-bottom: 1px solid #e1e1e1;
    .user-title {
      float: left;
    }
    .user-btn {
      float: right;
      margin-right: 10px;
      font-size: 12px;
      color: #999;
      span {
        margin-left: 8px;
      }
    }
  }
  .right-bottom-div {
    width: 320px;
    // height: 105px;
    margin: 10px 5px 10px 5px;
    white-space: normal;
    .user-icon {
      display: inline-block;
      padding: 0 10px 10px 10px;
      margin: 0 9px 10px 9px;
      font-size: 13px;
      vertical-align: top;
      cursor: pointer;
      border-radius: 5px;
      .user-icon-icon {
        position: relative;
        margin: 20px 10px 5px 10px;
        text-align: center;
        .nums {
          position: absolute;
          top: -5px;
          right: -6px;
          z-index: 22;
          width: 19px;
          height: 19px;
          font-size: 1px;
          color: #fff;
          background: #f1b55a;
          border-radius: 15px;
        }
      }
      .user-name {
        width: 5em;
        text-align: center;
      }
    }
    .user-icon:hover {
      background: #ededed;
    }
  }
}
</style>
