import request from '@/utils/request'

const BASE_API = process.env.VUE_APP_BASIC_API
// const MOCK_BASE_API = 'http://yapi.cusc.com:3000/mock/28/'

/**
 * 分页查询经销商
 * @yapi http://yapi.cusc.com:3000/project/28/interface/api/7268
 */
export const queryUserEnterpriseDistributor = (data) => {
  return request({
    url: `${BASE_API}userEnterprise/distributor/page`,
    data
  })
}

/**
 * 新增经销商
 * @yapi http://yapi.cusc.com:3000/project/28/interface/api/7260
 */
export const addUserEnterpriseDistributor = data => {
  return request({
    url: `${BASE_API}userEnterprise/distributor/add`,
    data
  })
}

/**
 * 切换经销商管理员
 * @yapi http://yapi.cusc.com:3000/project/28/interface/api/7264
 */
export const changeUserEnterpriseDistributor = data => {
  return request({
    url: `${BASE_API}userEnterprise/distributor/changeAdmin`,
    data
  })
}

/**
 * 更新经销商
 * @yapi http://yapi.cusc.com:3000/project/28/interface/api/7272
 */
export const updateUserEnterpriseDistributor = data => {
  return request({
    url: `${BASE_API}userEnterprise/distributor/update`,
    data
  })
}

/**
 * 禁用经销商
 * @yapi http://yapi.cusc.com:3000/project/28/interface/api/8296
 */
export const frozenUserEnterpriseDistributor = data => {
  return request({
    url: `${BASE_API}userEnterprise/distributor/frozen`,
    data
  })
}

/**
 * 启用经销商
 * @yapi http://yapi.cusc.com:3000/project/28/interface/api/8304
 */
export const unfreezeUserEnterpriseDistributor = data => {
  return request({
    url: `${BASE_API}userEnterprise/distributor/unfreeze`,
    data
  })
}

/**
 * 账户管理分页查询
 * @yapi http://yapi.cusc.com:3000/project/28/interface/api/8364
 */
export const queryUserEnterpriseAccount = data => {
  return request({
    url: `${BASE_API}userEnterprise/account/pageList`,
    data
  })
}

/**
 * 根据组织查询角色列表
 * @yapi http://yapi.cusc.com:3000/project/28/interface/api/8372
 */
export const queryRoListByOrganId = (data) => {
  return request({
    url: `${BASE_API}userEnterprise/role/getRoListByOrganId?organId=${data.organId}`,
    method: 'GET',
    data
  })
}

/**
 * 新增账户
 * @yapi http://yapi.cusc.com:3000/project/28/interface/api/8360
 */
export const addUserEnterpriseAccount = data => {
  return request({
    url: `${BASE_API}userEnterprise/account/add`,
    data
  })
}

/**
 * 更新账户
 * @yapi http://yapi.cusc.com:3000/project/28/interface/api/8368
 */
export const updateUserEnterpriseAccount = data => {
  return request({
    url: `${BASE_API}userEnterprise/account/update`,
    data
  })
}

/**
 * 禁用账户
 * @yapi http://yapi.cusc.com:3000/project/28/interface/api/8296
 */
export const frozenUserEnterpriseAccount = data => {
  return request({
    url: `${BASE_API}userEnterprise/account/frozen`,
    data
  })
}

/**
 * 启用账户
 * @yapi http://yapi.cusc.com:3000/project/28/interface/api/8304
 */
export const unfreezeUserEnterpriseAccount = data => {
  return request({
    url: `${BASE_API}userEnterprise/account/unfreeze`,
    data
  })
}

/**
 * 查询是车厂的组织信息
 * @yapi http://yapi.cusc.com:3000/project/28/interface/api/9224
 */
export const queryOrgByList = data => {
  return request({
    url: `${BASE_API}simvehicle/queryOrgByList`,
    method: 'GET',
    data
  })
}

/**
 * 查询车卡绑定分页列表
 * @yapi http://yapi.cusc.com:3000/project/28/interface/api/9248
 */
export const querySimVehicleByPage = data => {
  return request({
    url: `${BASE_API}simvehicle/querySimVehicleByPage`,
    data
  })
}

/**
 * 分页查询导入历史信息
 * @yapi http://yapi.cusc.com:3000/project/28/interface/api/9220
 */
export const queryImportHistory = data => {
  return request({
    url: `${BASE_API}simvehicle/queryImportHistory`,
    data
  })
}

/**
 * 导入车卡关系
 * @yapi http://yapi.cusc.com:3000/project/28/interface/api/9216
 */
export const importSimVehicle = data => {
  return request({
    url: `${BASE_API}simvehicle/import`,
    data
  })
}

/**
 * 查询标签信息列表
 * @yapi http://yapi.cusc.com:3000/project/28/interface/api/9236
 */
export const queryTag = data => {
  return request({
    url: `${BASE_API}simvehicle/queryTags`,
    data
  })
}

/**
 * 车卡关系停用
 */
export const unbindSimVehicle = data => {
  return request({
    url: `${BASE_API}simvehicle/unbind`,
    data
  })
}

/**
 * 车卡关系停用
 */
export const bindSimVehicle = data => {
  return request({
    url: `${BASE_API}simvehicle/bind`,
    data
  })
}

// 文件下载
export const downloadFile = (data) => {
  const params = []
  Object.keys(data).forEach(key => {
    params.push(`${key}=${data[key]}`)
  })
  return request({
    url: `${BASE_API}simvehicle/download/errorfile${params.length > 0 ? `?${params.join('&')}` : ''}`,
    method: 'GET',
    responseType: 'blob'
  })
}

// 下载excel文件
export const downloadExcelFile = data => {
  const params = []
  Object.keys(data).forEach(key => {
    params.push(`${key}=${data[key]}`)
  })
  return request({
    url: `${BASE_API}simvehicle/download/file${params.length > 0 ? `?${params.join('&')}` : ''}`,
    method: 'GET',
    responseType: 'blob'
  })
}

// 车卡关系模板下载
export const carCardExcelTemplate = (data) => {
  return request({
    url: `${BASE_API}simvehicle/download/template?fileType=${data.fileType}`,
    method: 'GET',
    responseType: 'blob'
  })
}

/**
 * 查询车企组织
 * @yapi http://yapi.cusc.com:3000/project/28/interface/api/9916
 */
export const queryOrganList = (data) => {
  return request({
    url: `${BASE_API}organ/pageList`,
    data
  })
}

/**
 * 用户账号列表
 * @yapi http://yapi.cusc.com:3000/project/28/interface/api/9920
 */
export const queryUserAccount = (data) => {
  return request({
    url: `${BASE_API}organ/queryUserAccount`,
    data
  })
}

/**
 * 创建车企组织
 * @yapi http://yapi.cusc.com:3000/project/28/interface/api/9912
 */
export const createOrgan = (data) => {
  return request({
    url: `${BASE_API}organ/create`,
    data
  })
}

/**
 * 更新车企组织
 * @yapi http://yapi.cusc.com:3000/project/28/interface/api/9924
 */
export const updateOrgan = (data) => {
  return request({
    url: `${BASE_API}organ/update`,
    data
  })
}

/**
 * 变更组织管理员
 * @yapi http://yapi.cusc.com:3000/project/28/interface/api/9908
 */
export const changeOrganAdmin = (data) => {
  return request({
    url: `${BASE_API}organ/changeAdmin`,
    data
  })
}

/**
 * 查询协议
 * @yapi http://yapi.cusc.com:3000/project/28/interface/api/10172
 */
export const queryPotocolManage = (data) => {
  return request({
    url: `${BASE_API}protocolManage/query`,
    data
  })
}

/**
 * 新增协议
 * @yapi http://yapi.cusc.com:3000/project/28/interface/api/10164
 */
export const createPotocolManage = (data) => {
  return request({
    url: `${BASE_API}protocolManage/create`,
    data
  })
}

/**
 * 修改协议
 * @yapi http://yapi.cusc.com:3000/project/28/interface/api/10168
 */
export const updatePotocolManage = (data) => {
  return request({
    url: `${BASE_API}protocolManage/update`,
    data
  })
}

/**
 * 协议管理组织列表
 */
export const queryProtocalOrgByList = (data) => {
  return request({
    url: `${BASE_API}protocolManage/queryOrgByList`,
    data,
    method: 'GET'
  })
}

/**
 * 查询文件模板
 * @yapi http://yapi.cusc.com:3000/project/28/interface/api/10208
 */
export const queryFileMould = (data) => {
  return request({
    url: `${BASE_API}protocolManage/queryFileMould`,
    data
  })
}

/**
 * 车辆信息查询
 * @yapi http://yapi.cusc.com:3000/project/28/interface/api/16612
 */
export const queryCarInfo = data => {
  return request({
    url: `${BASE_API}car/info/queryCarInfo`,
    data
  })
}

/**
 * 导入车辆信息
 * @yapi http://yapi.cusc.com:3000/project/28/interface/api/16608
 */
export const importCarInfo = data => {
  return request({
    url: `${BASE_API}car/info/import`,
    data
  })
}

/**
 * 下载车辆信息模板
 */
export const downloadCarInfoTemplate = data => {
  const params = []
  Object.keys(data).forEach(key => {
    params.push(`${key}=${data[key]}`)
  })
  return request({
    url: `${BASE_API}car/info/download/template${params.length > 0 ? `?${params.join('&')}` : ''}`,
    method: 'GET',
    responseType: 'blob'
  })
}

/**
 * 查询登录用户当前组织及其子组织
 * @yapi http://10.166.2.23:3000/project/28/interface/api/16688
 */
export const queryCurrentSubOrgList = data => {
  return request({
    url: `${BASE_API}organ/queryCurrentSubOrgList`,
    method: 'GET'
  })
}
