import http from '@/utils/request'

// 获取销售人员列表
export function getSalesUserList (params) {
  // eslint-disable-next-line prefer-const
  let { pageNum = 1, pageSize = 10, status = ['inactive', 'active'], nickName, name, card_id, phone, real_name, sales_user_types
  } = params
  status = status
    .map((val) => {
      return `status=${val}`
    })
    .join('&')

  if (params.saleType) {
    status += `&saleType=2`
  }

  if (params.parent_sales_user_id) {
    status += `&parent_sales_user_id=${params.parent_sales_user_id}`
  }

  if (nickName) {
    status += `&nickName=${nickName}`
  }
  if (phone) {
    status += `&phone=${phone}`
  }
  if (real_name) {
    status += `&real_name=${real_name}`
  }
  if (card_id) {
    status += `&card_id=${card_id}`
  }

  if (name) {
    status += `&name=${name}`
  } if (sales_user_types) {
    status += `&sales_user_types=${sales_user_types}`
  }

  return http.get(
    `/salesUser?pageNum=${pageNum}&pageSize=${pageSize}&${status}`
  )
}

// 新增销售人员
export function addSalesUser (params) {
  return http.post('/salesUser', params)
}
// 批量导入销售人员
export function addSalesUserBatch (params) {
  return http.post('/salesUser/importBatch', params)
}

// 激活禁用销售人员
export function activeSalesUser (params) {
  return http.post(`/salesUser/${params.id}`, params)
}

// 删除销售人员
export function delSalesUser (id) {
  return http.delete(`/salesUser/${id}`)
}

// 获取兑换卡列表
export function getExchangeCardList (params) {
  // eslint-disable-next-line prefer-const
  let { pageNum = 1, pageSize = 10, sales_user_id, status = ['inactive', 'active'], remark
  } = params
  status = status
    .map((val) => {
      return `status=${val}`
    })
    .join('&')
  return http.get(
    `/exchangeCard?pageNum=${pageNum}&pageSize=${pageSize}&${status}&sales_user_id=${sales_user_id}&remark=${remark}`
  )
}

// 新增兑换卡
export function addExchangeCard (params) {
  return http.post('/exchangeCard/create', params)
}

// 编辑兑换卡
export function editExchangeCard (params) {
  return http.post(`/exchangeCard/${params.id}`, params)
}

// 删除兑换卡
export function delExchangeCard (id) {
  return http.delete(`/exchangeCard/${id}`)
}

// 更新兑换卡过期时间
export function updateExpireTime (params) {
  return http.post(`/exchangeCard/${params.id}/updateExpireTime`, params)
}

// 批量更新兑换卡过期时间
export function batchUpdateExpireTime (params) {
  return http.post(`/exchangeCard/batchUpdateExpireTime`, params)
}

// 获取二级销售人员列表
export function getSecondSaleList (params) {
  const { pageNum, pageSize, phone } = params
  return http.get(
    `/secondSaleUser?pageNum=${pageNum}&pageSize=${pageSize}&phone=${phone}&status=active&status=inactive`,
    params
  )
}
// 创建二级销售人员
export function addSecondSaleList (params) {
  return http.post(`/secondSaleUser`, params)
}
// 编辑二级销售人员
export function editSecondSaleList (params) {
  return http.post(`/secondSaleUser/update`, params)
}
// 批量导入二级销售人员
export function addSecondSalesUserBatch (id, file) {
  return http.post(`/secondSaleUser/importBatch/?parentSaleUserId=${id}`, file)
}
// 删除二级销售人员
export function deleteSecondSaleList (id) {
  return http.delete(`/secondSaleUser/${id}`)
}
// 激活/禁用二级销售人员
export function updateSecondSaleList (params) {
  return http.post(`/secondSaleUser/active/${params.id}`, params)
}

// 创建销售人员分类
export function addSalesUserType (params) {
  return http.post(`/salesUserType`, { ...params, status: 1 })
}
// 编辑销售人员分类
export function deleteSalesUserType (params) {
  return http.post(`/salesUserType/delete`, params)
}
// 删除销售人员分类
export function getSalesUserTypeList (params) {
  return http.post(`/salesUserType/page`, params)
}
// 修改销售人员分类状态
export function updateSalesUserType (params) {
  return http.post(`/salesUserType/update`, params)
}
