import request from '@/utils/request'
import { praseStrEmpty } from "@/utils/common";

// 查询用户列表
export function listUser(query) {
  return request({
    url: '/company/user/list',
    method: 'get',
    params: query
  })
}
// 查询企微用户列表
export function qwList(query) {
  return request({
    url: '/company/user/qwList',
    method: 'get',
    params: query
  })
}
// 查询企微用户列表
export function myQwList(query) {
  return request({
    url: '/company/user/myQwList',
    method: 'get',
    params: query
  })
}
export function getList(query) {
  return request({
    url: '/company/user/getList',
    method: 'get',
    params: query
  })
}
export function getUserList() {
  return request({
    url: '/company/user/getUserList',
    method: 'get'
  })
}
export function getQwUserList() {
  return request({
    url: '/company/user/getQwUserList',
    method: 'get'
  })
}
export function getQwAllUserList(id) {
  return request({
    url: '/company/user/getQwAllUserList/'+id,
    method: 'get'
  })
}


export function getQwMyUserList(id) {
  return request({
    url: '/company/user/getQwMyUserList/'+id,
    method: 'get'
  })
}

export function getQwDeptUserList(id) {
  return request({
    url: '/company/user/getQwDeptUserList/'+id,
    method: 'get'
  })
}



export function getUserListByDeptId(query) {
  return request({
    url: '/company/user/getUserListByDeptId',
    method: 'get',
    params: query
  })
}

export function getUserListByDeptIdToQwId(query) {
  return request({
    url: '/company/user/getUserListByDeptIdToQwId',
    method: 'get',
    params: query
  })
}


export function getAddressBookList(query) {
  return request({
    url: '/company/user/getAddressBookList',
    method: 'get',
    params: query
  })
}



// 查询用户详细
export function getUser(userId) {
  return request({
    url: '/company/user/' + praseStrEmpty(userId),
    method: 'get'
  })
}

// 新增用户
export function addUser(data) {
  return request({
    url: '/company/user',
    method: 'post',
    data: data
  })
}

//创建二维码
export function addCodeUrl(data) {
  return request({
    url: '/company/user/addCodeUrl',
    method: 'post',
    data: data
  })
}


// 修改用户
export function updateUser(data) {
  return request({
    url: '/company/user',
    method: 'put',
    data: data
  })
}

// 删除用户
export function delUser(userIds) {
  return request({
    url: '/company/user/' + userIds,
    method: 'delete'
  })
}

// 导出用户
export function exportUser(query) {
  return request({
    url: '/company/user/export',
    method: 'get',
    params: query
  })
}

// 用户密码重置
export function resetUserPwd(userId, password) {
  const data = {
    userId,
    password
  }
  return request({
    url: '/company/user/resetPwd',
    method: 'put',
    data: data
  })
}

// 用户状态修改
export function changeUserStatus(userId, status) {
  const data = {
    userId,
    status
  }
  return request({
    url: '/company/user/changeStatus',
    method: 'put',
    data: data
  })
}

// 查询用户个人信息
export function getUserProfile() {
  return request({
    url: '/company/user/profile',
    method: 'get'
  })
}

//获取销售绑定的用户列表
export function getSaleBindUserList(query) {
  return request({
    url: '/company/user/getFsUserBySaleId',
    method: 'get',
    params: query
  })
}

//绑定销售会员关系
export function bindSaleAndFsUser(data) {
  return request({
    url: '/company/user/bindSaleAndFsUser',
    method: 'post',
    data: data
  })
}

//解绑销售会员关系
export function unbindSaleAndFsUser(data) {
  return request({
    url: '/company/user/unbindSaleAndFsUser',
    method: 'post',
    data
  });
}


// 修改用户个人信息
export function updateUserProfile(data) {
  return request({
    url: '/company/user/profile',
    method: 'put',
    data: data
  })
}

// 用户密码重置
export function updateUserPwd(oldPassword, newPassword) {
  const data = {
    oldPassword,
    newPassword
  }
  return request({
    url: '/company/user/profile/updatePwd',
    method: 'put',
    params: data
  })
}

// 用户头像上传
export function uploadAvatar(data) {
  return request({
    url: '/company/user/profile/avatar',
    method: 'post',
    data: data
  })
}

// 下载用户导入模板
export function importTemplate() {
  return request({
    url: '/company/user/importTemplate',
    method: 'get'
  })
}

export function getSelectUserList(query) {
  return request({
    url: '/company/user/getSelectUserList',
    method: 'get',
    params: query
  })
}

/**
* 获取地区
*/
export function getCitysAreaList(query) {
  return request({
    url: '/company/user/getCitysAreaList',
    method: 'get',
    params: query
  })
}

/**
* 批量修改 销售的所属区域(临时的)
*/
export function updateCompanyUserAreaList(data) {
  return request({
    url: '/company/user/updateCompanyUserAreaList',
    method: 'post',
    data: data
  })
}

// 根据名称模糊查询用户列表
export function getCompanyUserListLikeName(params) {
  return request({
    url: '/company/user/getCompanyUserListLikeName',
    method: 'get',
    params: params
  })
}

// 根据名模糊查询用户列表
export function getCompanyUserListLikeNameByDept(params) {
  return request({
    url: '/company/user/getCompanyUserListLikeNameDept',
    method: 'get',
    params: params
  })
}


// 查询企业员工信息列表
export function listCompanyUser(query) {
  return request({
    url: '/company/user/list',
    method: 'get',
    params: query
  })
}

// 查询企业员工信息列表
export function getCompanyUserList(query) {
  return request({
    url: '/company/user/getCompanyUserList',
    method: 'get',
    params: query
  })
}

//生成域名
export function generateSubDomain(query){
  return request({
    url: '/company/user/generateSubDomain',
    method: 'get',
    params: query
  })
}

// 设置是否需要单独注册会员
export function setIsRegisterMember(status, data) {
  return request({
    url: '/company/user/setRegister',
    method: 'put',
    params: status,
    data: data
  })
}

// 开关是否允许所有方式注册会员
export function isAllowedAllRegister(status, data) {
  return request({
    url: '/company/user/allowedAllRegister',
    method: 'put',
    params: status,
    data: data
  })
}

// 绑定医生
export function bindDoctorId(data) {
  return request({
    url: '/company/user/bindDoctorId',
    method: 'post',
    data: data
  })
}

//解绑医生
export function unBindDoctorId(userId) {
  return request({
    url: '/company/user/unBindDoctorId/'+userId,
    method: 'get'
  })
}

//批量修改用户的角色
export function updateBatchUserRoles(data) {
  return request({
    url: '/company/user/updateBatchUserRoles',
    method: 'post',
    data: data
  })
}

// 根据手机号码查询fs_user（完全匹配）
export function queryFsUserByPhone(phone) {
  return request({
    url: '/company/user/fsUser/queryByPhone',
    method: 'get',
    params: { phone: phone }
  })
}

// 批量绑定用户到员工
export function batchBindCompanyUserId(data) {
  return request({
    url: '/company/user/batchBindCompanyUserId',
    method: 'post',
    data: data
  })
}

// 查询已绑定的用户
export function getBoundUsers(companyUserId) {
  return request({
    url: '/company/user/getBoundUsers/' + companyUserId,
    method: 'get'
  })
}

export function unBind(userId) {
  return request({
    url: '/company/user/unBind',
    method: 'post',
    data: { userId: userId }
  })
}

// 查询销售行为分析数据
export function selectCompanyUserInfo(userId) {
  return request({
    url: '/company/user/selectCompanyUserInfo/' + userId,
    method: 'get'
  })
}

// 重新分析销售行为数据
export function analyseCompanyUserInfo(userId) {
  return request({
    url: '/company/user/analyseCompanyUserInfo/' + userId,
    method: 'get'
  })
}

// 上传声纹
export function addVoicePrintUrl(data) {
  return request({
    url: '/company/user/addVoicePrintUrl',
    method: 'post',
    data: data
  })
}
