import request from '@/utils/request'

// 导出
export function exportLead(query) {
  return request({
    url: '/business/lead/export',
    method: 'get',
    params: query
  })
}

// 查询线索管理列表
export function listLead(query) {
  return request({
    url: '/business/lead/list',
    method: 'get',
    params: query
  })
}

// 查询关联线索
export function getRelatedLead() {
  return request({
    url: '/business/lead/leadlist',
    method: 'get'
  })
}

// 查询关联线索
export function getRelatedLeadByQuery(query) {
  return request({
    url: '/business/lead/leadDataQuery',
    method: 'get',
    params: query
  })
}

export function getRelatedLeadByQueryPage(query) {
  return request({
    url: '/business/lead/leadDataQueryPage',
    method: 'get',
    params: query
  })
}

// 查询关联线索
export function getRelatedLeadByLeadId(query) {
  return request({
    url: '/business/lead/leadData',
    method: 'get',
    params: query
  })
}

// 查询线索管理详细
export function getLead(leadId) {
  return request({
    url: '/business/lead/' + leadId,
    method: 'get'
  })
}

// 新增线索管理
export function addLead(data) {
  return request({
    url: '/business/lead',
    method: 'post',
    data: data
  })
}

// 修改线索管理
export function updateLead(data) {
  return request({
    url: '/business/lead',
    method: 'put',
    data: data
  })
}

// 删除线索管理
export function delLead(leadId) {
  return request({
    url: '/business/lead/' + leadId,
    method: 'delete'
  })
}

// 查询地区
// export function getArea() {
//   return request({
//     url: '/user/area/getAllAreaList',
//     method: 'get'
//   })
// }

// 查询客户关联线索
export function selectLeadListByAccount(query) {
  return request({
    url: '/business/lead/listByAccount',
    method: 'get',
    params: query
  })
}

// 根据 线索id 查询跟进记录
// export function getFollowRecord(leadId) {
//   return request({
//     url: '/business/follow/listByTypeAndBusinessId',
//     method: 'get',
//     params: { followType: '0',  businessId: leadId }
//   })
// }
export function getFollowRecord(query) {
  return request({
    url: '/business/follow/listByTypeAndBusinessId',
    method: 'get',
    params: query
  })
}

// 根据线索id查询履历
export function getHistoryByLeadId(leadId) {
  return request({
    url: `/system/leadHistory/getHistoryByLeadId/${leadId}`,
    method: 'get',
  })
}

// 根据当前用户查询下一级别用户
export function getNextLevelsByCur() {
  return request({
    url: `/system/user/getNextLevelsByCur/`,
    method: 'get'
  })
}

// 分配
export function allot(data) {
  return request({
    url: '/business/lead/allot',
    method: 'put',
    data: data
  })
}

// 回收
export function recycle(data) {
  return request({
    url: '/business/lead/recycle',
    method: 'put',
    data: data
  })
}

/**
 * 转化客户
 * @param data :  {leadId: 1, relativeAccount: 1, remark: '备注'}
 */
export function convertCustomer(data) {
  return request({
    url: '/business/lead/convertCustomer',
    method: 'put',
    data: data
  })
}

// 查询当前用户全部未转化客户的线索
export function listByCurUser(query) {
  return request({
    url: `/business/lead/listByCurUser`,
    method: 'get',
    params: query
  })
}

export function allList(query) {
  return request({
    url: `/business/lead/allList`,
    method: 'get',
    params: query
  })
}


//  查询当前用户能看到的所有线索中的所有代理商列表：用于下拉检索
export function curAgent() {
  return request({
    url: `/business/lead/curAgent`,
    method: 'get'
  })
}

// //  查询当前用户能看到的所有线索中的所有国家列表：用于下拉检索
// export function curCountry() {
//   return request({
//     url: `/business/lead/curCountry`,
//     method: 'get'
//   })
// }

// 转化客户
export function convertCust(data) {
  return request({
    url: '/business/lead/convertCust',
    method: 'put',
    data: data
  })
}


// 查询当前用户可见国家下拉
export function getCountryList() {
  return request({
    url: '/business/lead/countries',
    method: 'get'
  })
}
// 查询当前用户可见区域下拉
export function getAreaList() {
  return request({
    url: '/business/lead/areas',
    method: 'get'
  })
}

// 静默 无效
export function silentInvalid(data) {
  return request({
    url: '/business/lead/silentOrInvalid',
    method: 'put',
    data: data
  })
}
