import request from '@/utils/request'
import state from '@/store'
import router from '@/router'

// 初始化角色
export function getRole() {
  return request({
    url: '',
    method: 'post',
    data: {
      UserID: state.state.user.id,
      ModularID: router.currentRoute.path,
      type: '1',
      name: '菜单系统模块_项目角色_查询数据_new'
    }
  })
}
// 根据角色查模块
export function getModule(role) {
  return request({
    url: '',
    method: 'post',
    data: {
      UserID: state.state.user.id,
      ModularID: router.currentRoute.path,
      type: '3',
      name: `select * from 基础表_角色模块信息 inner join 基础表_模块信息 on 基础表_角色模块信息.id = 基础表_模块信息.id where 角色编号=${role} and 是否禁用 = 0 order by 角色模块顺序`
    }
  })
}
// 初始化一级菜单
export function initFisrtLevel() {
  return request({
    url: '',
    method: 'post',
    data: {
      UserID: state.state.user.id,
      ModularID: router.currentRoute.path,
      type: '3',
      name: `select id,title from 基础表_模块信息 where [path] = '/' and 是否禁用 = 0`
    }
  })
}
// 初始化二级菜单
export function initSecondLevel() {
  return request({
    url: '',
    method: 'post',
    data: {
      UserID: state.state.user.id,
      ModularID: router.currentRoute.path,
      type: '3',
      name: `select id,title from 基础表_模块信息 where [path] <> '/' and 是否禁用 = 0`
    }
  })
}
// 撤回分配模块
export function returnModule(id, num) {
  return request({
    url: '',
    method: 'post',
    data: {
      UserID: state.state.user.id,
      ModularID: router.currentRoute.path,
      type: '2',
      name: `菜单管理_角色模块_删除数据`,
      param: `id=${id}&角色编号=${num}`
    }
  })
}
// 上移模块
export function upModule(id, num) {
  return request({
    url: '',
    method: 'post',
    data: {
      UserID: state.state.user.id,
      ModularID: router.currentRoute.path,
      type: '2',
      name: `菜单管理_角色模块_上移数据`,
      param: `id=${id}&角色编号=${num}`
    }
  })
}
// 上移模块验证
export function searchUpModule(id, num) {
  return request({
    url: '',
    method: 'post',
    data: {
      UserID: state.state.user.id,
      ModularID: router.currentRoute.path,
      type: '1',
      name: `菜单管理_角色模块_上移数据_验证`,
      param: `id=${id}&角色编号=${num}`
    }
  })
}
// 下移模块
export function downModule(id, num) {
  return request({
    url: '',
    method: 'post',
    data: {
      UserID: state.state.user.id,
      ModularID: router.currentRoute.path,
      type: '2',
      name: `菜单管理_角色模块_下移数据`,
      param: `id=${id}&角色编号=${num}`
    }
  })
}
// 下移模块验证
export function searchDownModule(id, num) {
  return request({
    url: '',
    method: 'post',
    data: {
      UserID: state.state.user.id,
      ModularID: router.currentRoute.path,
      type: '1',
      name: `菜单管理_角色模块_下移数据_验证`,
      param: `id=${id}&角色编号=${num}`
    }
  })
}
// 分配一级模块
export function giveFirstLevel(idGroup, num) {
  return request({
    url: '',
    method: 'post',
    data: {
      UserID: state.state.user.id,
      ModularID: router.currentRoute.path,
      type: '2',
      name: `菜单管理_角色模块_一级_增加数据`,
      param: `一级模块id组=${idGroup}&角色编号=${num}`
    }
  })
}
// 分配一级模块
export function giveSecondLevel(idGroup, num, pid) {
  return request({
    url: '',
    method: 'post',
    data: {
      UserID: state.state.user.id,
      ModularID: router.currentRoute.path,
      type: '2',
      name: `菜单管理_角色模块_二级_增加数据`,
      param: `二级模块id组=${idGroup}&角色编号=${num}&pid=${pid}`
    }
  })
}
// 新增一级菜单
export function submitAdd(name) {
  return request({
    url: '',
    method: 'post',
    data: {
      UserID: state.state.user.id,
      ModularID: router.currentRoute.path,
      type: '2',
      name: `菜单管理_模块_一级_增加数据`,
      param: `模块名称=${name}`
    }
  })
}
// 查询二级模块分给那些角色
export function getRoleTitle() {
  return request({
    url: '',
    method: 'post',
    data: {
      UserID: state.state.user.id,
      ModularID: router.currentRoute.path,
      type: '3',
      name: ` select distinct title from
              基础表_模块信息 inner join 基础表_角色模块信息 on 基础表_角色模块信息.id = 基础表_模块信息.id
              inner join 菜单系统模块_项目角色 on 基础表_角色模块信息.角色编号 = 菜单系统模块_项目角色.角色编号
              order by title`
    }
  })
}
export function getRoleNameasd(name) {
  return request({
    url: '',
    method: 'post',
    data: {
      UserID: state.state.user.id,
      ModularID: router.currentRoute.path,
      type: '3',
      name: ` select distinct 角色功能 from
              基础表_模块信息 inner join 基础表_角色模块信息 on 基础表_角色模块信息.id = 基础表_模块信息.id
              inner join 菜单系统模块_项目角色 on 基础表_角色模块信息.角色编号 = 菜单系统模块_项目角色.角色编号
              where title='${name}'`
    }
  })
}
