<template>
  <div :class="[$style.wrapHeight, $style.processlist]">
    <div :class="$style.rowHeight">
      <risk-category-tree
        ref="riskCategoryTree"
        :key="key"
        show-line
        top-node-text="风险库"
        :is-select-dep="true"
        manager-type="view"
        :history="this.$route.query.history ? true : false"
        :hisv="this.$route.query.history ? this.$route.query.version : null"
        :hisorg="this.$route.query.history ? this.$route.query.orgId : null"
        :hisorgn="this.$route.query.history ? this.$route.query.orgName : null"
        @treeSelect="treeSelect"
        @depChanged="depChanged"
        @getManagedHorg="getManagedHorg"
      ></risk-category-tree>

      <div :class="$style.rightcard">
        <a-card>
          <!-- 高级搜索组件 -->
          <audit-advanced-query
            :expand="expand"
            :search-data="formData"
            :ref-name="searchform"
            :search-style="{ height: '210px', left: '20px', top: '57px' }"
            :search-fun="handleSearch"
            @searchedClick="searchedClick"
            @resetForm="resetForm"
          >
            <template>
              <a-col :span="12">
                <a-form-model-item label="风险事项编号" prop="eventCode">
                  <a-input v-model="formData.eventCode" allow-clear />
                </a-form-model-item>
              </a-col>
              <a-col :span="12">
                <a-form-model-item :label="'风险事项名称'" prop="eventName">
                  <a-input v-model="formData.eventName" allow-clear />
                </a-form-model-item>
              </a-col>
              <a-col :span="12">
                <a-form-model-item
                  :label="'状\u2002\u2002\u2002\u2002\u2002\u2002\u2002\u2002态'"
                  prop="status"
                >
                  <sd-select v-model="formData.status" :options="status" />
                </a-form-model-item>
              </a-col>
            </template>
          </audit-advanced-query>
          <sd-data-table-ex
            :key="key"
            ref="riskEvent"
            :data-url="`api/xcoa-mobile/v1/riskevent/findIcMtxMeasures`"
            :editnode="true"
            form-id="riskEvent"
            page-id="risk/event/riskEvent"
            :columns="columns"
            :actions="actions"
            show-selection
            :show-advance-query="true"
            :filter-expressions="expressions"
            :search-fields="['eventName']"
            :custom-delete-fun="deleteRows"
            @searchbtnClick="searchbtnClick"
          >
            <div slot="islink" slot-scope="text, record">
              <a :title="text" @click="rowClick(record)">{{ text }}</a>
            </div>
          </sd-data-table-ex>
          <risk-event-export-modal
            :visible="visible"
            @import="fnimportresult"
          ></risk-event-export-modal>
        </a-card>
        <sd-detail-modal
          ref="versionform"
          :record-id="versionId ? versionId : null"
          :read-only="vfreadonly"
          page-id="risk/version/riskLibraryVersion"
          :modal-props="{ width: 1200 }"
          @save="msave"
          @actionBtnClick="actionBtnClick"
        >
          <template v-slot="{ model, fields }">
            <table>
              <colgroup>
                <col style="width: 20%;" />
                <col style="width: 30%;" />
                <col style="width: 20%;" />
                <col style="width: 30%;" />
              </colgroup>
              <tr v-show="!vfreadonly"
                ><td class="ant-form-item-label ant-form-item-label">
                  <label title="操作类型" class=""> 操作类型 </label>
                </td>
                <a-radio-group
                  v-model="versiontype"
                  :disabled="versionId ? false : true"
                  @change="changeversiontype"
                >
                  <a-radio :value="'修改当前版本'">修改当前版本 </a-radio>
                  <a-radio :value="'新增新版本'">新增新版本 </a-radio>
                </a-radio-group></tr
              >
              <tr
                ><sd-form-item-td
                  name="belongUnitName"
                  :input-props="{ defaultValue: orgName, disabled: true }"
                ></sd-form-item-td
                ><sd-form-item-td v-if="initDateSelect(model)" name="year">
                  <a-select
                    v-model="model.year"
                    :disabled="versiontype === '修改当前版本' ? true : false"
                  >
                    <a-select-option v-for="year in yearArry" :key="year + ''">
                      {{ year }}
                    </a-select-option>
                  </a-select>
                </sd-form-item-td></tr
              >
              <tr v-show="false"
                ><sd-form-item-td
                  name="belongUnitCode"
                  :input-props="{ defaultValue: orgId.toString() }"
                ></sd-form-item-td>
                <sd-form-item-td
                  name="belongUnitId"
                  :input-props="{ defaultValue: orgId }"
                ></sd-form-item-td>
              </tr>

              <tr v-show="false"
                ><sd-form-item-td
                  name="auditOrgId"
                  :input-props="{ defaultValue: orgId }"
                ></sd-form-item-td>
                <sd-form-item-td name="modifyDeptId"></sd-form-item-td>
              </tr>
              <tr v-show="false"
                ><sd-form-item-td name="modifyDeptCode"></sd-form-item-td>
                <sd-form-item-td name="modifyDeptName"></sd-form-item-td>
              </tr>

              <tr
                ><sd-form-item-td name="versionCode">
                  <template>
                    <span>{{ model.versionCode }}</span>
                  </template> </sd-form-item-td
                ><sd-form-item-td name="versionType"
                  ><template>
                    <span>当前版本</span>
                  </template>
                </sd-form-item-td>
              </tr>
              <tr
                ><sd-form-item-td
                  :col-span="3"
                  name="riskLibraryType"
                  component="a-select"
                  :input-props="{
                    disabled: versiontype === '修改当前版本' || !zsgsflag ? true : false,
                  }"
                ></sd-form-item-td>
              </tr>
              <tr
                ><sd-form-item-td :colspan="3" name="riskLibraryDesc">
                  <a-textarea v-model="model.riskLibraryDesc" :rows="3" /> </sd-form-item-td
              ></tr>
              <tr
                ><sd-form-item-td name="creatorName"></sd-form-item-td
                ><sd-form-item-td name="creationTime"></sd-form-item-td></tr
            ></table>
          </template>
        </sd-detail-modal>
        <sd-detail-modal
          ref="catalogform"
          :read-only="true"
          :record-id="catarecordId"
          page-id="risk/category/riskCategory"
          :modal-props="{ width: 1200 }"
        >
          <template v-slot="{ model, fields }">
            <sd-form-item name="categoryCode" />
            <sd-form-item name="categoryName" />
            <sd-form-item name="categoryDesc">
              <a-textarea v-model="model.categoryDesc" :rows="3" />
            </sd-form-item>
            <sd-form-item name="isEnd" />
            <sd-form-item name="sortNum" />
          </template>
        </sd-detail-modal>
      </div>
    </div>
  </div>
</template>

<script>
import PageService from '@/common/services/page-service'
import { Modal, message } from 'ant-design-vue'
import axios from '@/common/services/axios-instance'
import download from '@/common/services/download'
import crossWindowWatcher from '@/common/services/cross-window-watcher'
import openAsTrustId from '@/common/services/open-as-trust-id'
import TableColumnTypes from '@/common/services/table-column-types'
import auditAdvancedQuery from '../../../components/audit-advanced-query.vue'
import auditAdvancedQueryMixins from '../../../components/audit-advanced-query-mixins'
import auditAdvancedGroupMixins from '../../../components/audit-advanced-group-mixins'
import auditPermissionTreeService from '../../../components/audit-permission-tree-service'
import CommonService from '../../../core/api/common-service'
import riskCategoryTree from '../category/risk-category-tree'
import RiskService from '../risk-service'
import riskEventExportModal from './risk-event-export-modal'
import components from './_import-components/risk-event-list-import'
export default {
  name: 'RiskEventList',
  metaInfo: {
    title: '风控矩阵',
  },
  components: {
    ...components,
    riskCategoryTree,
    auditAdvancedQuery,
    riskEventExportModal,
  },
  mixins: [auditAdvancedQueryMixins, auditAdvancedGroupMixins],
  data() {
    return {
      formId: 'riskEvent',
      orgId: null,
      orgName: '',
      yearArry: [],
      editnode: true, // 列表是否可以新建
      key: 0,
      treeData: [],
      searchform: 'searchform',
      formData: {
        eventName: '',
        eventCode: '',
        status: '',
      },
      columns: [
        {
          title: '序号',
          dataIndex: 'sortNum',
          customRender: (text, record, index) => `${index + 1}`,
          width: '80px',
          defaultSortOrder: 'asc',
        },
        {
          title: '风险事项名称',
          dataIndex: 'eventName',
          width: '150px',
          scopedSlots: { customRender: 'islink' },
        },
        {
          title: '风险事项编号',
          dataIndex: 'eventCode',
          width: '150px',
        },

        {
          title: '风险源',
          dataIndex: 'riskSource',
        },
        {
          title: '风险等级',
          dataIndex: 'riskLevel',
        },
        {
          title: '状态',
          dataIndex: 'status',
        },
        {
          title: '创建人员',
          dataIndex: 'creatorName',
        },
        {
          title: '创建日期',
          dataIndex: 'creationTime',
          sdRender: TableColumnTypes.date,
        },
      ],
      actions: [],
      actionsf: [
        {
          label: '版本设置',
          id: 'versionset',
          permission: null,
          class: 'ant-btn-primary',
          callback: () => {
            this.vfreadonly = false
            this.createversion()
          },
          index: 8,
        },
      ],
      actionss: [
        {
          label: '版本查看',
          id: 'versionsee',
          permission: null,
          class: 'ant-btn-primary',
          callback: () => {
            // const url = '/sd-frame/mtx-version-list' // 新页面要打开的路由地址
            // openAsTrustId(url, null)
            this.vfreadonly = true
            this.createversion()
          },
          index: 7,
        },
        {
          label: '分类查看',
          id: 'catalogview',
          // permission: 'iamAuditMatters-catalog',
          permission: null,
          callback: () => {
            this.opencatalog()
          },
          index: 6,
        },
        {
          label: '分类配置',
          id: 'auditMattersCatalog',
          // permission: 'iamAuditMatters-catalog',
          permission: null,
          callback: () => {
            const url =
              '/sd-frame/risk-category-list?versionId=' +
              this.versionId +
              '&history=1&orgId=' +
              this.orgId +
              '&orgName=' +
              this.orgName // 新页面要打开的路由地址
            openAsTrustId(url, null)
            // window.open(url, '_blank')
          },
          index: 5,
        },
        {
          label: '删除',
          id: 'delete',
          permission: null,
          class: 'batch',
          callback: this.deleteRows,
          index: 3,
        },
        {
          label: '导入', // 导入和新建权限一致 by zhangtt 2023-2-23
          id: 'importItem',
          // permission: 'iamAuditMatters-import',
          permission: null,
          callback: this.importItem, // 纯前端操作，不需要权限控制
          index: 2,
        },
        {
          label: '导出',
          id: 'exportItem',
          // permission: 'iamAuditMatters-export',
          permission: null,
          callback: this.exportItem, // 纯前端操作，不需要权限控制
          index: 1,
        },
      ],
      actionsn: [
        {
          label: '新建',
          id: 'new',
          // type: TableActionTypes.primary, // 新建按钮，不需要回调，自动处理
          class: 'ant-btn-primary',
          // permission: 'iamAuditMatters-create', // 纯前端操作，不需要权限控制//只有最后一个结束分类的节点才可以新建事项
          permission: null,
          callback: this.createRiskEvent,
          index: 4,
        },
      ],
      actionsview: [
        {
          label: '版本查看',
          id: 'versionsee',
          permission: null,
          class: 'ant-btn-primary',
          callback: () => {
            // const url = '/sd-frame/mtx-version-list' // 新页面要打开的路由地址
            // openAsTrustId(url, null)
            this.vfreadonly = true
            this.createversion()
          },
          index: 7,
        },
        {
          label: '导出',
          id: 'exportItem',
          // permission: 'iamAuditMatters-export',
          permission: null,
          callback: this.exportItem, // 纯前端操作，不需要权限控制
          index: 1,
        },
      ],
      expressions: [
        { dataType: 'str', name: 'isRoot', op: 'eq', stringValue: 'true' },
        {
          dataType: 'long',
          name: 'riskCategoryId',
          op: 'eq',
          longValue: 0,
        },
        { dataType: 'long', name: 'versionId', op: 'eq', longValue: this.versionId },
      ],
      catalogId: null,
      catalogName: '',
      auditMattersPath: '',
      visible: false,
      versionId: null,
      history: this.$route.query.history ? this.$route.query.history : null,
      vfreadonly: false,
      versiontype: '新增新版本',
      flag: false,
      levels: [],
      status: [
        // { id: '0', name: '全部' },
        // { id: '1', name: '启用' },
        // { id: '2', name: '废弃' },
      ],
      // frequencys: [],
      // ways: [],
      orgPermission: [],
      catarecordId: null,
      formflag: true,
      zsgslist: [], // 直属公司列表
      zsgsflag: false,
      riskLibraryTypecsz: '',
    }
  },
  mounted() {
    // 初始化数据字典信息
    this.initDictionaryInfo()
  },
  methods: {
    changeversiontype() {
      if (this.versionId && this.versionId !== '') {
        if (this.versiontype === '新增新版本') {
          this.$refs.versionform.setFieldValue('riskLibraryType', 'ownRiskLibrary')
        } else {
          this.$refs.versionform.setFieldValue('riskLibraryType', this.riskLibraryTypecsz)
        }
      }
    },
    getManagedHorg(data) {
      this.orgPermission = data
    },
    initDictionaryInfo() {
      const params = {
        moduleId: 'iamOrg2',
      }
      auditPermissionTreeService.getCategoryTree(0, params).then((res) => {
        if (res.data.length > 0) {
          this.zsgslist = res.data
        }
      })
      CommonService.getDictValues('RISK_STATUS').then((res) => {
        this.status = res
      })
    },
    msave() {
      this.$refs.versionform.validateFields().then((res) => {
        if (res) {
          message.success('保存成功')
        }
      })
    },
    actionBtnClick(evt, btn) {
      evt.waitUntil(
        new Promise((resolve, reject) => {
          if (btn && btn.buttonId === 'save') {
            this.$refs.versionform.validateFields().then((res) => {
              if (res) {
                if (this.$refs.versionform.getFieldValue('id') !== undefined) {
                  if (this.versiontype === '新增新版本') {
                    this.$refs.versionform.setFieldValue('id', null)
                  }
                }
                evt.preventDefault()
                this.$refs.versionform.save().then((res) => {
                  message.success('保存成功')
                  this.getnewversion()
                  this.Closed()
                })
              }
            })
          } else {
            this.Closed()
          }
        })
      )
    },
    initDateSelect(model) {
      if (this.formflag) {
        this.formflag = false
        const nowYear = new Date().getFullYear()
        if (!this.flag) {
          this.yearArry.push(nowYear)
          for (let i = 1; i < 6; i++) {
            this.yearArry.push(nowYear - i)
          }
          for (let i = 1; i < 11; i++) {
            this.yearArry.push(nowYear + i)
          }
          this.yearArry.sort()
          this.flag = true
        }
        if (model.year === undefined) {
          model.year = nowYear + ''
        }
        this.zsgsflag = false
        // 判断当前是否有版本
        if (!this.versionId) {
          model.versionType = 'currentVersion'
          this.versiontype = '新增新版本'
          // 判断是否是直属
          if (
            this.zsgslist.length > 0 &&
            this.zsgslist.findIndex((i) => i.id === this.orgId) > -1
          ) {
            this.zsgsflag = true
          } else {
            model.riskLibraryType = 'ownRiskLibrary'
          }
          this.riskLibraryTypecsz = ''
        } else {
          this.versiontype = '修改当前版本'
          this.riskLibraryTypecsz = model.riskLibraryType
        }
      }
      return true
    },
    getnewversion() {
      const orgId = this.$refs.riskCategoryTree.depvalue
      // this.actions = []
      const editflag = this.geteditpermission()
      if (this.history) {
        this.versionId = this.$route.query.version
        this.actions.splice(0, this.actions.length)
        this.actionsview.forEach((i) => {
          this.actions.push(i)
        })
      } else {
        this.actions.splice(0, this.actions.length)
        if (editflag) {
          this.actionsf.forEach((i) => {
            this.actions.push(i)
          })
        }
        RiskService.getversion(this.orgId).then((res) => {
          if (res.data.id) {
            this.versionId = res.data.id
            if (editflag) {
              this.actionss.forEach((i) => {
                this.actions.push(i)
              })
            } else {
              this.actionsview.forEach((i) => {
                this.actions.push(i)
              })
            }
            this.versiontype = '修改当前版本'
          } else {
            this.versionId = null
            this.versiontype = '新增新版本'
          }
          // 异步接口调用完，按钮排序
          this.actions.sort((a, b) => b.index - a.index)
        })
      }
      this.actions.sort((a, b) => b.index - a.index)
    },
    geteditpermission() {
      let editflag = false
      if (this.orgPermission.editNodes) {
        // 判断机构部门
        const orgId = this.$refs.riskCategoryTree.depvalue
        if (orgId) {
          const key = this.orgPermission.editNodes.findIndex((i) => i.id === orgId)
          if (key > -1) {
            editflag = true
          }
        }
      }
      return editflag
    },
    Saved() {
      message.success('保存成功')
      this.$refs.versionform.hide()
    },
    Closed() {
      this.$refs.versionform.hide()
      // this.$refs.versionform.resetFields()
    },
    createversion() {
      this.$refs.versionform.show()
      this.formflag = true
      // 日期下拉框初始化
      // this.initDateSelect()
    },
    opencatalog() {
      if (this.$refs.riskCategoryTree.defaultSelectedKeys > 0) {
        this.catarecordId = this.$refs.riskCategoryTree.defaultSelectedKeys[0]
        this.$refs.catalogform.show()
      } else {
        Modal.info({
          content: '请选择分类节点',
        })
      }
    },
    // viewversion() {},
    // 选择上级分类后给对应的域赋值
    // fnTreePicker(value) {
    //   if (value.length > 0) {
    //     this.$refs.dataTable.getDetailModal().setFieldValue('catalogId', value[0].id)
    //     this.$refs.dataTable.getDetailModal().setFieldValue('catalogName', value[0].name)
    //   } else {
    //     this.$refs.dataTable.getDetailModal().setFieldValue('catalogId', '')
    //     this.$refs.dataTable.getDetailModal().setFieldValue('catalogName', '')
    //     this.$refs.dataTable.getDetailModal().setFieldValue('auditMattersPath', '')
    //   }
    // },

    treeSelect(selectedKeys, info) {
      this.auditMattersPath = null
      // 判断当前节点有编辑权限还是差看权限
      const editflag = this.geteditpermission()
      if (!editflag) {
        const flagimport = this.actions.findIndex((i) => i.id === 'importItem') // 导入按钮
        if (flagimport !== -1) {
          this.actions.splice(flagimport, 1) // 去除导入按钮
        }
      }
      // 父级id
      if (info != null && info.selectedNodes.length > 0) {
        this.parentId = Number(info.selectedNodes[0].data.props.id)
        this.parentName = info.selectedNodes[0].data.props.text // 父级名称
        this.catalogId = Number(info.selectedNodes[0].data.props.id)
        this.catalogName = info.selectedNodes[0].data.props.text // 父级名称
        this.editnode = info.selectedNodes[0].data.props.edit
        if (info.selectedNodes[0].data.props.props) {
          if (info.selectedNodes[0].data.props.props.catalogPath) {
            this.auditMattersPath =
              info.selectedNodes[0].data.props.props.catalogPath + ',' + this.parentId
          } else {
            this.auditMattersPath = this.parentId
          }
        }
        // 判断是否显示新建按钮 actionsn 先去掉按钮中的新建然后再判断加上
        const flag = this.actions.findIndex((i) => i.id === 'new')
        if (
          info.selectedNodes[0].data.props.props &&
          info.selectedNodes[0].data.props.props.isEnd === '1'
        ) {
          // 末位节点有新建按钮
          if (flag === -1 && editflag) {
            this.actionsn.forEach((i) => {
              this.actions.push(i)
            })
          }
          if (!editflag && flag > -1) {
            this.actions.splice(flag, 1)
            // const flagimport = this.actions.findIndex((i) => i.id === 'importItem') // 导入按钮
            // this.actions.splice(flagimport, 1) // 去除导入按钮  add by zhangtt 2023-2-23
          }
        } else {
          // 无新建按钮
          if (flag > -1) {
            this.actions.splice(flag, 1)
            // const flagimport = this.actions.findIndex((i) => i.id === 'importItem') // 导入按钮
            // this.actions.splice(flagimport, 1) // 去除导入按钮  add by zhangtt 2023-2-23
          }
        }
      } else {
        if (selectedKeys.id) {
          this.parentId = Number(selectedKeys.id)
          this.parentName = selectedKeys.text // 父级名称
        }
      }
      const orgId = this.$refs.riskCategoryTree.depvalue
      // 判断当前节点是否为根节点
      this.expressions.forEach((item) => {
        if (item.name === 'riskCategoryId') {
          // item.name = 'mtxPrcId'
          item.longValue = this.catalogId
        } else if (item.name === 'versionId') {
          item.longValue = this.$refs.riskCategoryTree.versionId
        } else if (item.name === 'isRoot') {
          if (this.catalogId === -1) {
            item.stringValue = true
          } else {
            item.stringValue = false
          }
        }
      })
      this.actions.sort((a, b) => b.index - a.index)
      this.expressions = [...this.expressions]
    },

    // 重置
    resetForm() {
      this.formData.status = null
    },
    handleSearch() {
      this.expressions = []
      if (this.catalogId === -1) {
        this.expressions.push({ dataType: 'str', name: 'isRoot', op: 'eq', stringValue: 'true' })
      } else {
        this.expressions.push({ dataType: 'str', name: 'isRoot', op: 'eq', stringValue: 'false' })
      }
      this.expressions.push({
        dataType: 'long',
        name: 'riskCategoryId',
        op: 'eq',
        longValue: this.catalogId,
      })

      this.expressions.push({
        dataType: 'long',
        name: 'versionId',
        op: 'eq',
        longValue: this.versionId,
      })
      // 审计事项名称
      if (this.formData.eventCode) {
        this.expressions.push({
          dataType: 'str',
          name: 'eventCode',
          op: 'like',
          stringValue: '%' + this.formData.eventCode + '%',
        })
      }
      // 审计事项编号
      if (this.formData.eventName) {
        this.expressions.push({
          dataType: 'str',
          name: 'eventName',
          op: 'like',
          stringValue: '%' + this.formData.eventName + '%',
        })
      }
      if (this.formData.status && this.formData.status[0].id !== '0') {
        this.expressions.push({
          dataType: 'str',
          name: 'status',
          op: 'eq',
          stringValue: this.formData.status[0].id,
        })
      }
      this.expressions = [...this.expressions]
    },
    // 新建、详情打开新页面
    rowClick(record) {
      // 判断当前节点有编辑权限还是差看权限
      const editflag = this.geteditpermission()
      let url =
        '/risk-event-form?record=' + record.id + '&orgName=' + this.$refs.riskCategoryTree.depName // 新页面要打开的路由地址
      if (editflag) {
      } else {
        url = url + '&mode=' + 'VIEW'
      }

      crossWindowWatcher.waitForChanged(url).then((refreshFlag) => {
        if (refreshFlag) {
          this.refresh()
        }
      })
      // const res = crossWindowWatcher.waitForChanged(url)
    },
    // 部门下拉框选择事件
    depChanged(value, info) {
      this.orgId = this.$refs.riskCategoryTree.depvalue // 选中的值
      this.orgName = this.$refs.riskCategoryTree.depName
      this.getnewversion()
    },
    // 新建保存回调刷新树
    onRecordSaved() {
      this.key = this.key + 1
    },
    // 删除回调
    onRecordsDeleted() {
      message.success('删除成功')
      this.key = this.key + 1
      this.refresh()
    },
    deleteRows() {
      const ids = this.$refs.riskEvent.getSelectedRowKeys()
      if (ids.length === 0) {
        Modal.info({
          content: '请选择需要删除的文件',
        })
        return
      }
      Modal.confirm({
        title: '您确定删除这项内容吗？',
        content: '删除数据后，就无法恢复初始的状态。',
        okText: '删除',
        cancelText: '取消',
        okType: 'danger',
        onOk: () => {
          // this.loading = true
          const params = {
            ids: ids.join(','),
          }
          PageService.delete(params, this.formId).then((res) => {
            if (res.status === 200) {
              message.success({ content: '删除成功！' }, 1).then(() => {
                this.refresh()
              })
            }
          })
        },
        onCancel: () => {},
      })
    },

    createRiskEvent() {
      const rootId = this.$refs.riskCategoryTree.depvalue
      if (this.catalogId != null && this.catalogId !== rootId) {
        const url =
          '/risk-event-form?catalogId=' +
          this.catalogId +
          '&catalogName=' +
          this.catalogName +
          '&versionId=' +
          this.versionId +
          '&orgId=' +
          this.$refs.riskCategoryTree.depvalue +
          '&orgName=' +
          this.$refs.riskCategoryTree.depName
        // 新页面要打开的路由地址
        crossWindowWatcher.waitForChanged(url).then((refreshFlag) => {
          if (refreshFlag) {
            // 这里写或者调刷新的方法
            this.refresh()
          }
        })
      } else {
        if (this.catalogId === rootId) {
          Modal.confirm({
            title: '注意',
            content: '不能在根节点下新建审计事项',
            okText: '确定',
            okType: 'danger',
          })
        } else {
          Modal.confirm({
            title: '请先选择审计事项分类',
            content: '请先选择审计事项分类。',
            okText: '确定',
            okType: 'danger',
          })
        }
      }
    },
    // 导出
    exportItem() {
      const id = this.catalogId
      const versionId = this.versionId

      RiskService.exportItem(id, versionId).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.visible = true
    },
    refresh() {
      this.$refs.riskEvent.clearSelection()
      this.$refs.riskEvent.refresh()
    },

    processReq(req) {
      const url = req.url
      const expre = req.data.expressions
      req.data.expressions = expre
      return req
    },
    fnimportresult(flag) {
      if (flag) {
        const option = this.$refs.riskCategoryTree.depOptions.findIndex(
          (i) => i.value === this.$refs.riskCategoryTree.depvalue
        )
        const data = {
          ...this.$refs.riskCategoryTree.depOptions[option],
          data: {
            props: {
              text: this.$refs.riskCategoryTree.depOptions[option].text,
              edit: this.$refs.riskCategoryTree.depOptions[option].edit,
            },
          },
        }
        this.$refs.riskCategoryTree.changedep(this.$refs.riskCategoryTree.depvalue, data)
        this.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%;
    }
  }
}
:global(.rightcard_mtx-process-list_product) {
  :global(.ant-btn) {
  }
}
.processlist {
  :global(.projectlist .ant-table-empty .ant-table-body) {
    overflow-x: hidden !important;
  }

  // :global(.ant-table-placeholder) {
  //   width: auto;
  // }
}
</style>
