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: '菜单系统模块_项目角色_查询数据_MESWORK'
    }
  })
}
// 根据角色查模块
export function getModule(role) {
  return request({
    url: '',
    method: 'post',
    data: {
      UserID: state.state.user.id,
      ModularID: router.currentRoute.path,
      type: '3',
      name: `select * from [dbo].[登录基础数据_二级菜单]  where 账号代码=${role} and 是否启用 = 1  order by id`
    }
  })
}
// 初始化一级菜单
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 [dbo].[登录基础数据_二级菜单] where pid = 0 and 是否启用 =1 and 账号代码 = 1`
    }
  })
}
// 初始化二级菜单
export function initSecondLevel() {
  return request({
    url: '',
    method: 'post',
    data: {
      UserID: state.state.user.id,
      ModularID: router.currentRoute.path,
      type: '3',
      name: `select a.id,a.title,a.pid,b.id,b.title as title1 from (select id,title,pid from [dbo].[登录基础数据_二级菜单] where pid <> 0 and 账号代码 = 1 and 是否启用 = 1 )as a 
left join (select id,title from [dbo].[登录基础数据_二级菜单] where pid = 0 and 账号代码 = 1 and 是否启用 = 1 )as b on a.pid = b.id order by b.id`
    }
  })
}

// 撤回分配模块
export function returnModule(id, num) {
  return request({
    url: '',
    method: 'post',
    data: {
      type: '2',
      name: `菜单管理_角色模块_删除数据`,
      param: `id=${id}&角色编号=${num}`
    }
  })
}
// 分配一级模块
export function giveFirstLevel(idGroup, num) {
  return request({
    url: '',
    method: 'post',
    data: {
      type: '2',
      name: `菜单管理_角色模块_一级_增加数据`,
      param: `一级模块id组=${idGroup}&角色编号=${num}`
    }
  })
}
// 分配二级模块
export function giveSecondLevel(idGroup, num, pid) {
  return request({
    url: '',
    method: 'post',
    data: {
      type: '2',
      name: `菜单管理_角色模块_二级_增加数据`,
      param: `二级模块id组=${idGroup}&角色编号=${num}&pid=${pid}`
    }
  })
}
// 新增一级菜单
export function submitAdd(name) {
  return request({
    url: '',
    method: 'post',
    data: {
      type: '2',
      name: `菜单管理_模块_一级_增加数据`,
      param: `模块名称=${name}`
    }
  })
}
