import http from '@/utils/http'
import { AppDispatch } from '@/store'
import { SaveUserType } from '@/pages/Isystem/I7user/data'
/**
 * 获取用户管理表格列表
 */
export const getUserListAPI = (data: any, back?: () => void): any => {
  return async (dispatch: AppDispatch) => {
    const res = await http.post('sys/user/list', data)
    if (res.code === 0) {
      const obj = {
        list: res.data.records,
        total: res.data.total
      }

      dispatch({ type: 'I7user/getList', payload: obj })
      back && back()
    }
  }
}

/**
 * 删除用户
 */
export const userRemoveAPI = (id: number) => {
  return http.get(`cms/flow/remove/${id}`)
}

/**
 * 重置密码
 */
export const userPassResetAPI = (id: number) => {
  return http.get(`sys/user/resetPass/${id}`)
}

/**
 * 新增/修改用户信息
 */
export const userSaveAPI = (data: SaveUserType) => {
  return http.post('sys/user/save', data)
}

/**
 * 通过id获取角色详情
 */
export const getUserInfoByIdAPI = (id: number) => {
  return http.get(`sys/user/detail/${id}`)
}

/**
 * 角色授权-获取 初始页面获取
 */
export const I7_APIgetAuthBase = () => {
  return http.get('sys/user/perm/getTree')
}
