// 自动生成的文件，请勿修改
import routerService from '@/common/services/router-service'
import asyncComponent from '@/common/services/async-component'
import flowService from '@/webflow/flow-service'
import formService from '@/webform/form-service'
import SdTable from '@/common/components/sd-table.vue'
import routerReady from '@/common/router-ready'
import axios from '@/common/services/axios-instance'
import todoListService from '@/todo/todo-list-service'
import { message } from '@/common/one-ui'

// 隐藏系统内关联文件页签
routerReady((router) => {
  router.beforeEach((to, from, next) => {
    // 如果是从自查离开，则去掉隐藏按钮样式样式
    if (from.fullPath.includes('cpm-check-self') || from.fullPath.includes('cpm-check-plan')) {
      const div = document.querySelector('.button_author_div')
      const parentDiv = div?.parentElement
      parentDiv?.removeChild(div)
    }
    import('@/application-manage/sd-task-list.vue').then(({ default: sdTaskList }) => {
      // @ts-ignore
      sdTaskList.methods.openTask = (record) => {
        if (record.instId === null) {
          message.warning('请先分配联系人', 3)
          return
        }
        if (!record.openLink) {
          record.openLink = '/api/framework/v1/task-form-process/done-pages'
        }

        todoListService.openTaskItem(record)
      }
    })

    // 首页或登录页不重定向，防止重复跳转
    if (to.path === '/' || to.path === '/sd-login') {
      next()
      return false
    }
    // 隐藏系统内关联文件页签
    import('@/webflow/sd-webflow.vue').then((sdWebflow) => {
      // @ts-ignore
      sdWebflow.default.props.removedTabs = {
        type: Array,
        default: () => ['sdRelatedDoc'],
      }
    })
    next()
  })
})

// @ts-ignore
const oldColumnsComputed = SdTable.computed.columnsComputed
// @ts-ignore
SdTable.computed.columnsComputed = function () {
  const obj = oldColumnsComputed
    .bind(this)()
    .find((i) => i.title === '序号')
  if (
    obj ||
    this.$route?.path === '/risk-criteria-form' ||
    (this.$route?.path.indexOf('/sd-task-list') === -1 &&
      this.$route?.path.indexOf('/sd-business-list') === -1 &&
      this.$route?.path.indexOf('/cpm-project') === -1 &&
      this.$route?.path.indexOf('/law-dispute-search') === -1)
  ) {
    return [...oldColumnsComputed.bind(this)()]
  } else {
    const returnColumns = [...oldColumnsComputed.bind(this)()]
    if (returnColumns[0].scopedSlots?.customRender === 'id') {
      returnColumns.splice(1, 0, {
        dataIndex: 'xmindex',
        title: '序号',
        // @ts-ignore
        customRender: (text, record, index) => `${index + 1}`,
        width: '65px',
        show: true,
      })
      return returnColumns
    }
    return [
      {
        dataIndex: 'xmindex',
        title: '序号',
        // @ts-ignore
        customRender: (text, record, index) => `${index + 1}`,
        width: '65px',
        show: true,
      },
      ...oldColumnsComputed.bind(this)(),
    ]
  }
}
// 整改检查方案
flowService.addFlowForm(
  'onl:5d82a6c0eb3949fb9994156e4eeac6e1',
  asyncComponent(
    () => import(/* webpackChunkName: "product-iam-cpm-form" */ './project/check-plan/cpm-check-plan-form.vue')
  )
)
// 整改检查通知
flowService.addFlowForm(
  'onl:395bd21f5bd74dae9d9451cfa24d9a05',
  asyncComponent(
    () => import(/* webpackChunkName: "product-iam-cpm-form" */ './project/check-notice/cpm-check-notice-form.vue')
  )
)
// 问题整改反馈
flowService.addFlowForm(
  'onl:a5222825c6594c24b9a0b5c302edbfa2',
  asyncComponent(
    () => import(/* webpackChunkName: "product-iam-cpm-form" */ './improve/feedback/cpm-improve-feedback-form.vue')
  )
)

// 合规举报
flowService.addFlowForm(
  'onl:19a222eb058041af8a4a866d34078496',
  asyncComponent(
    () => import(/* webpackChunkName: "product-iam-cpm-form" */ './accusation/cpm-accusation-form.vue')
  )
)

// 问题确认单明细
routerService.routeInFrame('cpm-confirm-detail', {
  component:asyncComponent(
    () => import(/* webpackChunkName: "product-iam-cpm" */ './project/confirm/cpm-confirm-detail-form.vue')
  ),
})
// 问题整改清单录入
routerService.routeInFrame('cpm-improve-rect', {
  component:asyncComponent(
    () => import(/* webpackChunkName: "product-iam-cpm" */ './improve/rectProblem/cpm-improve-rect-problem-form.vue')
  ),
})

// 问题确认单
flowService.addFlowForm(
  'onl:fd31f3fb56224b7aa368d33ab4ea6519',
  asyncComponent(
    () => import(/* webpackChunkName: "product-iam-cpm-form" */ './project/confirm/cpm-confirm-form.vue')
  )
)

// 问题整改要求
flowService.addFlowForm(
  'onl:7db756cfc7544a2bb5b12b2f310bac08',
  asyncComponent(
    () => import(/* webpackChunkName: "product-iam-cpm-form" */ './improve/require/audit-cpm-improve-require-form.vue')
  )
)

// 合规项目
routerService.routeInFrame('cpm-project-list', {
  component:asyncComponent(
    () => import(/* webpackChunkName: "product-iam-cpm" */ './project/cpm-project-list.vue')
  ),
})

// 合规检查立项
flowService.addFlowForm(
  'onl:8d8b353ab83b461a9f2b3a8e04894f71',
  asyncComponent(
    () => import(/* webpackChunkName: "product-iam-cpm-form" */ './project/cpm-project-check.vue')
  )
)

// 整改提醒
routerService.routeInFrame('cpm-remind-config', {
  component:asyncComponent(
    () => import(/* webpackChunkName: "product-iam-cpm" */ './improve/remind/cpm-improve-remind-config.vue')
  ),
})

// 工作底稿
flowService.addFlowForm(
  'onl:4d40a24f7eae43bba231b025ebf44f95',
  asyncComponent(
    () => import(/* webpackChunkName: "product-iam-cpm-form" */ './project/work-paper/cpm-work-paper-form.vue')
  )
)

// 内控-测试
routerService.route('/cpm-project/', {
  component:asyncComponent(
    () => import(/* webpackChunkName: "product-iam-cpm" */ './project/cpm-project.vue')
  ),
  children: [
    {
      path: 'cpm-check-plan',
      components: {
        rightfrm: asyncComponent(() => import('../../../src/application-manage/sd-task-list.vue')),
      },
      props: (route) => ({
        customValues: route.query.customValues,
        formListId: route.query.formListId,
        moduleId: route.query.moduleId,
        projectId: route.query.projectId,
        groupId: route.query.groupId,
      }),
      // @ts-ignore
      beforeEnter: (to, from, next) => {
        const mainIni = setInterval(() => {
          const mainDiv = document.querySelector('.header_cpm-project_product')
          if (mainDiv) {
            const div = document.createElement('div')
            div.className = 'button_author_div'
            div.style.display = 'none'
            const style = document.createElement('style')
            style.innerHTML = `.header_sd-data-table_common {
                  display:none
                }`
            div.appendChild(style)
            mainDiv.appendChild(div)
            let projectId = to.query.groupId
            if (projectId.toString() === '1') {
              projectId = to.query.projectId
            }
            axios({
              method: 'get',
              url: `api/xcoa-mobile/v1/cpm-project-member/isProjectLeader?projectId=${projectId}`,
            }).then((res) => {
              // 如果不是组长，则隐藏新建按钮
              if (!res.data) {
                const btnIni = setInterval(() => {
                  if (document.querySelectorAll('.header_sd-data-table_common button').length > 0) {
                    style.innerHTML = `.header_sd-data-table_common  .ant-btn-primary{
                    display:none
                  }`
                    clearInterval(btnIni)
                  }
                })
              } else {
                style.innerHTML = ''
              }
            })
            clearInterval(mainIni)
          }
        }, 100)

        next()
      },
    },
    {
      path: 'cpm-check-notice',
      components: {
        rightfrm: asyncComponent(() => import('../../../src/application-manage/sd-task-list.vue')),
      },
      props: (route) => ({
        customValues: route.query.customValues,
        formListId: route.query.formListId,
        moduleId: route.query.moduleId,
        projectId: route.query.projectId,
        groupId: route.query.groupId,
      }),
      // @ts-ignore
      beforeEnter: (to, from, next) => {
        const mainIni = setInterval(() => {
          const mainDiv = document.querySelector('.header_cpm-project_product')
          if (mainDiv) {
            const div = document.createElement('div')
            div.className = 'button_author_div'
            div.style.display = 'none'
            const style = document.createElement('style')
            style.innerHTML = `.header_sd-data-table_common {
                  display:none
                }`
            div.appendChild(style)
            mainDiv.appendChild(div)
            let projectId = to.query.groupId
            if (projectId.toString() === '1') {
              projectId = to.query.projectId
            }
            axios({
              method: 'get',
              url: `api/xcoa-mobile/v1/cpm-project-member/isProjectLeader?projectId=${projectId}`,
            }).then((res) => {
              // 如果不是组长，则隐藏新建按钮
              if (!res.data) {
                const btnIni = setInterval(() => {
                  if (document.querySelectorAll('.header_sd-data-table_common button').length > 0) {
                    style.innerHTML = `.header_sd-data-table_common  .ant-btn-primary{
                    display:none
                  }`
                    clearInterval(btnIni)
                  }
                })
              } else {
                style.innerHTML = ''
              }
            })
            clearInterval(mainIni)
          }
        }, 100)

        next()
      },
    },
    {
      path: 'cpm-check-self',
      components: {
        rightfrm: asyncComponent(() => import('../../../src/application-manage/sd-task-list.vue')),
      },
      props: (route) => ({
        customValues: route.query.customValues,
        formListId: route.query.formListId,
        moduleId: route.query.moduleId,
        projectId: route.query.projectId,
        groupId: route.query.groupId,
      }),
      // @ts-ignore
      beforeEnter: (to, from, next) => {
        const mainIni = setInterval(() => {
          const mainDiv = document.querySelector('.header_cpm-project_product')
          if (mainDiv) {
            const div = document.createElement('div')
            div.className = 'button_author_div'
            div.style.display = 'none'
            const style = document.createElement('style')
            style.innerHTML = `.header_sd-data-table_common {
              display:none
            }`
            div.appendChild(style)
            mainDiv.appendChild(div)
            let projectId = to.query.groupId
            if (projectId.toString() === '1') {
              projectId = to.query.projectId
            }
            axios({
              method: 'get',
              url: `api/xcoa-mobile/v1/cpm-project-member/isProjectLeader?projectId=${projectId}`,
            }).then((res) => {
              // 如果是组长，则去掉隐藏按钮的样式
              if (res.data) {
                const btnIni = setInterval(() => {
                  if (document.querySelectorAll('.header_sd-data-table_common button').length > 0) {
                    style.innerHTML = `.header_sd-data-table_common .ant-btn-primary{
                      display:none
                    }
                    .header_sd-data-table_common button[disabled='disabled']{
                      display:none
                    }`
                    document
                      .querySelectorAll('.header_sd-data-table_common button')
                      .forEach((item) => {
                        if (item.innerHTML.replace(/\s/g, '').includes('删除')) {
                          item.setAttribute('style', 'display:none')
                        }
                      })
                    clearInterval(btnIni)
                  }
                })
              } else {
                const btnIni = setInterval(() => {
                  if (document.querySelectorAll('.header_sd-data-table_common button').length > 0) {
                    style.innerHTML = `.header_sd-data-table_common button{
                      display:none
                    }
                    .header_sd-data-table_common button[disabled='disabled']{
                      display:none
                    }`
                    document
                      .querySelectorAll('.header_sd-data-table_common button')
                      .forEach((item) => {
                        if (item.innerHTML.replace(/\s/g, '').includes('删除')) {
                          item.setAttribute('style', 'display:none')
                        }
                      })
                    clearInterval(btnIni)
                  }
                })
              }
            })
            clearInterval(mainIni)
          }
        }, 100)
        next()
      },
    },
    {
      path: 'cpm-work-papre',
      components: {
        rightfrm: asyncComponent(() => import('../../../src/application-manage/sd-task-list.vue')),
      },
      props: (route) => ({
        customValues: route.query.customValues,
        formListId: route.query.formListId,
        moduleId: route.query.moduleId,
        projectId: route.query.projectId,
        groupId: route.query.groupId,
      }),
      beforeEnter: (to, from, next) => {
        const mainIni = setInterval(() => {
          const mainDiv = document.querySelector('.header_cpm-project_product')
          if (mainDiv) {
            const div = mainDiv.getElementsByClassName('button_author_div')
            if (div && div.length > 0) {
              for (var s = 0; s < div.length; s++) {
                document
                  .querySelector('.header_cpm-project_product')
                  .getElementsByClassName('button_author_div')
                  [s]?.remove()
              }
            }
            document.querySelectorAll('.header_sd-data-table_common button').forEach((item) => {
              if (item.innerHTML.replace(/\s/g, '').includes('删除')) {
                item.setAttribute('style', '')
              }
            })
            clearInterval(mainIni)
          }
        }, 100)
        next()
      },
    },
    {
      path: 'cpm-work-report',
      components: {
        rightfrm: asyncComponent(() => import('../../../src/application-manage/sd-task-list.vue')),
      },
      props: (route) => ({
        customValues: route.query.customValues,
        formListId: route.query.formListId,
        moduleId: route.query.moduleId,
        projectId: route.query.projectId,
        groupId: route.query.groupId,
      }),
      beforeEnter: (to, from, next) => {
        const mainIni = setInterval(() => {
          const mainDiv = document.querySelector('.header_cpm-project_product')
          if (mainDiv) {
            const div = mainDiv.getElementsByClassName('button_author_div')
            if (div && div.length > 0) {
              for (var s = 0; s < div.length; s++) {
                document
                  .querySelector('.header_cpm-project_product')
                  .getElementsByClassName('button_author_div')
                  [s]?.remove()
              }
            }
            document.querySelectorAll('.header_sd-data-table_common button').forEach((item) => {
              if (item.innerHTML.replace(/\s/g, '').includes('删除')) {
                item.setAttribute('style', '')
              }
            })
            clearInterval(mainIni)
          }
        }, 100)
        next()
      },
    },
    {
      path: 'cpm-confirm-list',
      components: {
        rightfrm: asyncComponent(() => import('./project/confirm/cpm-confirm-list.vue')),
      },
      props: (route) => ({
        customValues: route.query.customValues,
        formListId: route.query.formListId,
        moduleId: route.query.moduleId,
        projectId: route.query.projectId,
        groupId: route.query.groupId,
      }),
      beforeEnter: (to, from, next) => {
        const mainIni = setInterval(() => {
          const mainDiv = document.querySelector('.header_cpm-project_product')
          if (mainDiv) {
            const div = mainDiv.getElementsByClassName('button_author_div')
            if (div && div.length > 0) {
              for (var s = 0; s < div.length; s++) {
                document
                  .querySelector('.header_cpm-project_product')
                  .getElementsByClassName('button_author_div')
                  [s]?.remove()
              }
            }
            document.querySelectorAll('.header_sd-data-table_common button').forEach((item) => {
              if (item.innerHTML.replace(/\s/g, '').includes('删除')) {
                item.setAttribute('style', '')
              }
            })
            clearInterval(mainIni)
          }
        }, 100)
        next()
      },
    },
    {
      path: 'cpm-check-user',
      component: asyncComponent(() => import('./project/user/audit-cpm-project-user.vue')),
      props: (route) => ({
        pageId: route.query.pageId,
        projectId: route.query.projectId,
      }),
    },
    {
      path: 'cpm-check-group',
      component: asyncComponent(() => import('./project/group/audit-cpm-project-group.vue')),
      props: (route) => ({
        pageId: route.query.pageId,
        projectId: route.query.projectId,
      }),
    },
  ],
})

// 制度审查
flowService.addFlowForm(
  'onl:a68deaea1d024a439ff0ffecd1068830',
  asyncComponent(
    () => import(/* webpackChunkName: "product-iam-cpm-form" */ './check/cpm-rule-check.vue')
  )
)

// 合同审查
flowService.addFlowForm(
  'onl:cfa055669fbe4afbafaefebdc4fdad70',
  asyncComponent(
    () => import(/* webpackChunkName: "product-iam-cpm-form" */ './check/cpm-contract-check.vue')
  )
)
// 重大决策审查
flowService.addFlowForm(
  'onl:930ec02130ab4d8798e23ffa32216e05',
  asyncComponent(
    () => import(/* webpackChunkName: "product-iam-cpm-form" */ './policycheck/cpm-policy-check.vue')
  )
)
// 合规检查报告
flowService.addFlowForm(
  'onl:e1e85d865d984f0383f238a5e0d11ab6',
  asyncComponent(
    () => import(/* webpackChunkName: "product-iam-cpm-form" */ './project/report/cpm-project-report-form.vue')
  )
)

// 领导专题学习
routerService.routeInFrame('cpm-leader-study', {
  component:asyncComponent(
    () => import(/* webpackChunkName: "product-iam-cpm" */ './cultural/cpm-leader-study-form.vue')
  ),
})

// 委员会专题纪要
routerService.routeInFrame('cpm-committee', {
  component:asyncComponent(
    () => import(/* webpackChunkName: "product-iam-cpm" */ './cultural/cpm-committee-form.vue')
  ),
})

// 合规培训
flowService.addFlowForm(
  'onl:fdb6b6b593ba432b8e5932da76c0910d',
  asyncComponent(
    () => import(/* webpackChunkName: "product-iam-cpm-form" */ './cultural/cpm-train-form.vue')
  )
)

// 宣传管理
flowService.addFlowForm(
  'onl:d531f98f303444a58e892e46b86c4ed9',
  asyncComponent(
    () => import(/* webpackChunkName: "product-iam-cpm-form" */ './cultural/cpm-billboard-form.vue')
  )
)
console.warn('路由 cpm-confirm-detail 不符合命名规则，应该以 iam 开头')
console.warn('路由 cpm-improve-rect 不符合命名规则，应该以 iam 开头')
console.warn('路由 cpm-project-list 不符合命名规则，应该以 iam 开头')
console.warn('路由 cpm-remind-config 不符合命名规则，应该以 iam 开头')
console.warn('路由 cpm-leader-study 不符合命名规则，应该以 iam 开头')
console.warn('路由 cpm-committee 不符合命名规则，应该以 iam 开头')