import { EditUserType, SaveUserType, UserTableAPIType } from '@/types'
import http from '@/utils/http'
import { AppDispatch } from '..'
/**
 * 获取用户管理表格列表
 */
export const getUserListAPI = (data: UserTableAPIType): any => {
  return async (dispatch: AppDispatch) => {
    const res = await http.post('museum/user/page', data)
    if (res.code === 0) {
      const obj = {
        list: res.data.records,
        total: res.data.total
      }

      dispatch({ type: 'Z1/getList', payload: obj })
    }
  }
}

/**
 * 删除用户
 */
export const userRemoveAPI = (id: number) => {
  return http.post(`museum/user/del/${id}`)
}

/**
 * 修改用户信息
 */
export const userResetPwdAPI = (data: EditUserType) => {
  return http.post(`museum/user/resetPwd`, data)
}

/**
 * 新增用户
 */
export const userSaveAPI = (data: SaveUserType) => {
  return http.post('museum/user/addUser', data)
}

/**
 * 角色授权-获取当前用户菜单树
 */
export const Z1_APIgetAuthByUserId = (userId: number) => {
  return http.post(`museum/menu/menuselect/${userId}`)
}

/**
 * 角色授权-修改当前用户权限
 */
export const Z1_APIsetAuth = (data: any) => {
  return http.post('museum/user/changePermissions', data)
}
