<template>
  <div :class="[$style.wrapHeight, $style.processlist]">
    <div :class="$style.rowHeight">
      <mtx-process-catalog-tree
        ref="icmatrixCatalogTree"
        :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"
      ></mtx-process-catalog-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="measureName">
                  <a-input v-model="formData.measureName" allow-clear />
                </a-form-model-item>
              </a-col>
              <a-col :span="12">
                <a-form-model-item :label="'\u2002\u2002\u2002\u2002控制级别'" prop="controlLevel">
                  <sd-select v-model="formData.controlLevel" :options="levels" />
                </a-form-model-item>
              </a-col>
              <a-col :span="12">
                <a-form-model-item :label="'\u2002\u2002\u2002\u2002控制类型'" prop="controlType">
                  <sd-select v-model="formData.controlType" :options="types" />
                </a-form-model-item>
              </a-col>
              <a-col :span="12">
                <a-form-model-item label="控制发生频率" prop="controlFrequency">
                  <sd-select v-model="formData.controlFrequency" :options="frequencys" />
                </a-form-model-item>
              </a-col>
              <a-col :span="12">
                <a-form-model-item :label="'\u2002\u2002\u2002\u2002控制方式'" prop="controlWay">
                  <sd-select v-model="formData.controlWay" :options="ways" />
                </a-form-model-item>
              </a-col>
            </template>
          </audit-advanced-query>
          <sd-data-table-ex
            :key="key"
            ref="icMtxMeasure"
            :data-url="`api/xcoa-mobile/v1/icmtxmeasure/findIcMtxMeasures`"
            :editnode="true"
            form-id="icMtxMeasure"
            page-id="ic/measure/icMtxMeasure"
            :columns="columns"
            :actions="actions"
            show-selection
            :show-advance-query="true"
            :filter-expressions="expressions"
            :search-fields="['measureName']"
            :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>
          <mtx-process-export-modal
            :visible="visible"
            @import="fnimportresult"
          ></mtx-process-export-modal>
        </a-card>
        <sd-detail-modal
          ref="versionform"
          :record-id="versionId ? versionId : null"
          :read-only="vfreadonly"
          page-id="ic/version/icMtxVersion"
          :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="versiontypeChange"
                >
                  <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-if="!vfreadonly"
                    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"></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"></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="matrixType"
                  component="a-select"
                  :input-props="{
                    disabled: versiontype === '修改当前版本' || !zsgsflag ? true : false,
                  }"
                ></sd-form-item-td>
              </tr>
              <tr
                ><sd-form-item-td :colspan="3" name="matrixDesc">
                  <a-textarea v-if="!vfreadonly" v-model="model.matrixDesc" :rows="3" />
                  <span v-else>{{ model.matrixDesc }}</span>
                </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="ic/process/icMtxProcess"
          :modal-props="{ width: 1200 }"
        >
          <template v-slot="{ model, fields }">
            <sd-form-item name="prcCode">{{ model.prcCode }}</sd-form-item>
            <sd-form-item name="prcName">{{ model.prcName }}</sd-form-item>
            <sd-form-item name="prcDesc">
              {{ model.prcDesc }}
            </sd-form-item>
            <sd-form-item name="isEnd">{{
              getDisplayVaule(fields.isEnd, model.isEnd)
            }}</sd-form-item>
            <sd-form-item name="attachment">
              <template v-slot:read-and-edit="{ editable }">
                <sd-attachment
                  v-model="model.attachment"
                  :group-id="JSON.parse(fields.attachment.value).value"
                  :read-only="true"
                />
              </template>
            </sd-form-item>
            <sd-form-item name="sortNum">{{ model.sortNum }}</sd-form-item>
          </template>
        </sd-detail-modal>
      </div>
    </div>
  </div>
</template>

<script>
import PageService from '@/common/services/page-service'
import { Modal, message } from 'ant-design-vue'
import { getComponentSpec } from '@/common/components/sd-form'
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 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 mtxProcessExportModal from './mtx-process-export-modal'
import mtxProcessCatalogTree from './mtx-process-catalog-tree'
import MtxProcessService from './mtx-process-service'
import components from './_import-components/mtx-process-list-import'
export default {
  name: 'MtxProcessList',
  metaInfo: {
    title: '内控矩阵',
  },
  components: {
    ...components,
    mtxProcessCatalogTree,
    auditAdvancedQuery,
    mtxProcessExportModal,
  },
  mixins: [auditAdvancedQueryMixins, auditAdvancedGroupMixins],
  data() {
    return {
      formId: 'icMtxMeasure',
      orgId: null,
      orgName: '',
      yearArry: [],
      editnode: true, // 列表是否可以新建
      key: 0,
      treeData: [],
      searchform: 'searchform',
      formData: {
        measureName: '',
        controlLevel: '',
        controlType: '',
        controlFrequency: '',
        controlWay: '',
      },
      columns: [
        {
          title: '序号',
          customRender: (text, record, index) => `${index + 1}`,
          width: '80px',
        },
        {
          title: '控制措施名称',
          dataIndex: 'measureName',
          scopedSlots: { customRender: 'islink' },
        },
        {
          title: '控制措施编号',
          dataIndex: 'measureCode',
        },
        {
          title: '控制级别',
          dataIndex: 'controlLevel',
          width: '90px',
        },
        {
          title: '控制类型',
          dataIndex: 'controlType',
          width: '90px',
        },
        {
          title: '控制方式',
          dataIndex: 'controlWay',
          width: '90px',
        },
        {
          title: '责任部门',
          dataIndex: 'dutyDeptName',
          width: '90px',
        },
        {
          title: '责任岗位',
          dataIndex: 'responPosition',
          width: '90px',
        },
      ],
      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/mtx-process-catalog?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: '导入',
          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.createMtxmeasure,
          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: 'catalogview',
          // permission: 'iamAuditMatters-catalog',
          permission: null,
          callback: () => {
            this.opencatalog()
          },
          index: 6,
        },
        {
          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: 'mtxPrcId',
          op: 'eq',
          longValue: 0,
        },
        { dataType: 'long', name: 'mtxVersionId', 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: [],
      types: [],
      frequencys: [],
      ways: [],
      orgPermission: [],
      catarecordId: null,
      formflag: true,
      zsgslist: [], // 直属公司列表
      zsgsflag: false,
      historyYear: null, // 历史年份
    }
  },
  mounted() {
    // 初始化数据字典信息
    this.initDictionaryInfo()
  },
  methods: {
    // 操作类型修改时候
    versiontypeChange(val) {
      if (val.target.value === '新增新版本') {
        this.historyYear = this.$refs.versionform.getFieldValue('year')
      } else {
        this.$refs.versionform.setFieldValue('year', this.historyYear)
      }
    },
    getDisplayVaule(field, text) {
      if (getComponentSpec(field).getDisplayValue) {
        if (typeof text !== 'undefined' && text !== null) {
          const value = getComponentSpec(field).parseBackendValue?.(text) || text
          return getComponentSpec(field).getDisplayValue(value)
        } else {
          return ''
        }
      }
      return text
    },
    getManagedHorg(data) {
      this.orgPermission = data
    },
    initDictionaryInfo() {
      axios({
        url: 'api/xcoa-mobile/v1/iam-law/dictionary?key=CONTROL_LEVEL',
        method: 'get',
      }).then((res) => {
        if (res.status === 200) {
          this.levels = res.data
        }
      })
      axios({
        url: 'api/xcoa-mobile/v1/iam-law/dictionary?key=CONTROL_TYPE',
        method: 'get',
      }).then((res) => {
        if (res.status === 200) {
          this.types = res.data
        }
      })
      axios({
        url: 'api/xcoa-mobile/v1/iam-law/dictionary?key=CONTROL_FREQUENCY',
        method: 'get',
      }).then((res) => {
        if (res.status === 200) {
          this.frequencys = res.data
        }
      })
      axios({
        url: 'api/xcoa-mobile/v1/iam-law/dictionary?key=CONTROL_WAY',
        method: 'get',
      }).then((res) => {
        if (res.status === 200) {
          this.ways = res.data
        }
      })
      const params = {
        moduleId: 'iamOrg2',
      }
      auditPermissionTreeService.getCategoryTree(0, params).then((res) => {
        if (res.data.length > 0) {
          this.zsgslist = res.data
        }
      })
    },
    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 {
                  message.error('保存失败')
                }
              })
              .catch(() => {
                evt.preventDefault()
                return false
              })
              // 最终通知内部按钮，所有处理已完成
              .finally(resolve)
          } 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.matrixType = 'own Matrix'
          }
        } else {
          this.versiontype = '修改当前版本'
        }
        // setTimeout(() => {
        //   if (this.$refs.versionform?.$refs.detailForm?.$refs.form?.model?.year === undefined) {
        //     this.$refs.versionform.$refs.detailForm.$refs.form.model.year = nowYear + ''
        //   }
        //   // 判断当前是否有版本
        //   if (!this.versionId) {
        //     this.$refs.versionform.$refs.detailForm.$refs.form.model.versionType = 'currentVersion'
        //     this.versiontype = '新增新版本'
        //   } else {
        //     this.versiontype = '修改当前版本'
        //   }
        // }, 1000)
      }
      return true

      // this.$refs.versionform.detailForm.setFieldValue('year', nowYear + '')
    },
    getnewversion() {
      const orgId = this.$refs.icmatrixCatalogTree.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)
          })
        }
        MtxProcessService.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)
    },
    geteditpermission() {
      let editflag = false
      if (this.orgPermission.editNodes) {
        // 判断机构部门
        const orgId = this.$refs.icmatrixCatalogTree.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.icmatrixCatalogTree.defaultSelectedKeys > 0) {
        this.catarecordId = this.$refs.icmatrixCatalogTree.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()
      // 父级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)
          }
        } else {
          // 无新建按钮
          if (flag > -1) {
            this.actions.splice(flag, 1)
          }
        }
      } else {
        if (selectedKeys.id) {
          this.parentId = Number(selectedKeys.id)
          this.parentName = selectedKeys.text // 父级名称
        }
      }
      const orgId = this.$refs.icmatrixCatalogTree.depvalue
      // 判断当前节点是否为根节点
      this.expressions.forEach((item) => {
        if (item.name === 'mtxPrcId') {
          // item.name = 'mtxPrcId'
          item.longValue = this.catalogId
        } else if (item.name === 'mtxVersionId') {
          item.longValue = this.$refs.icmatrixCatalogTree.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.controlLevel = null
      this.formData.controlType = null
      this.formData.controlFrequency = null
      this.formData.controlWay = 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: 'mtxPrcId',
        op: 'eq',
        longValue: this.catalogId,
      })

      this.expressions.push({
        dataType: 'long',
        name: 'mtxVersionId',
        op: 'eq',
        longValue: this.versionId,
      })
      // 审计事项名称
      if (this.formData.measureName) {
        this.expressions.push({
          dataType: 'str',
          name: 'measureName',
          op: 'like',
          stringValue: '%' + this.formData.measureName + '%',
        })
      }
      // 审计事项编号
      if (this.formData.controlLevel) {
        this.expressions.push({
          dataType: 'str',
          name: 'controlLevel',
          op: 'eq',
          stringValue: this.formData.controlLevel[0].id,
        })
      }
      if (this.formData.controlType) {
        this.expressions.push({
          dataType: 'str',
          name: 'controlType',
          op: 'eq',
          stringValue: this.formData.controlType[0].id,
        })
      }
      if (this.formData.controlFrequency) {
        this.expressions.push({
          dataType: 'str',
          name: 'controlFrequency',
          op: 'eq',
          stringValue: this.formData.controlFrequency[0].id,
        })
      }
      if (this.formData.controlWay) {
        this.expressions.push({
          dataType: 'str',
          name: 'controlWay',
          op: 'eq',
          stringValue: this.formData.controlWay[0].id,
        })
      }
      this.expressions = [...this.expressions]
    },
    // 新建、详情打开新页面
    rowClick(record) {
      // 判断当前节点有编辑权限还是差看权限
      const editflag = this.geteditpermission()
      let url =
        '/mtx-measure-form?record=' +
        record.id +
        '&orgName=' +
        this.$refs.icmatrixCatalogTree.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.icmatrixCatalogTree.depvalue // 选中的值
      this.orgName = this.$refs.icmatrixCatalogTree.depName
      this.getnewversion()
    },
    // 新建保存回调刷新树
    onRecordSaved() {
      this.key = this.key + 1
    },
    // 删除回调
    onRecordsDeleted() {
      message.success('删除成功')
      this.key = this.key + 1
      this.refresh()
    },
    deleteRows() {
      // const selectedRowKeys = this.$refs.icMtxMeasure.getSelectedRowKeys()
      const ids = this.$refs.icMtxMeasure.getSelectedRowKeys()
      if (ids.length === 0) {
        Modal.info({
          content: '请选择需要删除的文件',
        })
        return
      }

      // return new Promise((resolve) => {
      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.$refs.icMtxMeasure.clearSelection()
                this.$refs.icMtxMeasure.refresh()
                this.refresh()
              })
            }
          })
        },
        onCancel: () => {},
      })
    },

    createMtxmeasure() {
      const rootId = this.$refs.icmatrixCatalogTree.depvalue
      if (this.catalogId != null && this.catalogId !== rootId) {
        const url =
          '/mtx-measure-form?catalogId=' +
          this.catalogId +
          '&catalogName=' +
          this.catalogName +
          '&versionId=' +
          this.versionId +
          '&orgId=' +
          this.$refs.icmatrixCatalogTree.depvalue +
          '&orgName=' +
          this.$refs.icmatrixCatalogTree.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 rootId = this.$refs.icmatrixCatalogTree.depvalue
      const id = this.catalogId
      const versionId = this.versionId

      MtxProcessService.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.icMtxMeasure.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.icmatrixCatalogTree.depOptions.findIndex(
          (i) => i.value === this.$refs.icmatrixCatalogTree.depvalue
        )
        const data = {
          ...this.$refs.icmatrixCatalogTree.depOptions[option],
          data: {
            props: {
              text: this.$refs.icmatrixCatalogTree.depOptions[option].text,
              edit: this.$refs.icmatrixCatalogTree.depOptions[option].edit,
            },
          },
        }
        this.$refs.icmatrixCatalogTree.changedep(this.$refs.icmatrixCatalogTree.depvalue, data)
        this.$refs.icMtxMeasure.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>
