Files
smartDriveEEFront/src/api/customer.js
zhonghua.li 69f6cf78ac 高德商户
2026-05-03 10:26:52 +08:00

223 lines
5.7 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import request from '@/utils/request'
import store from '@/store'
import { getLoginAccount } from '@/utils/auth'
import { getBusinessHeaders } from '@/utils/business-headers'
function resolveCurrentLoginAccount() {
const fromStore = (store.getters.account || '').trim()
if (fromStore) return fromStore
const fromStorage = getLoginAccount()
if (fromStorage) return fromStorage
const fromHeader = (getBusinessHeaders()['X-Account-Name'] || '').trim()
return fromHeader || ''
}
// 分页查询客户列表
export function getCustomerList(params) {
return request({
url: '/customerManagement/list',
method: 'get',
params: {
current: params.current || 1,
size: params.size || 10,
customerName: params.customerName,
contact: params.contact,
salesName: params.salesName,
dealershipId: params.dealershipId,
projectId: params.projectId,
createTimeStart: params.createTimeStart,
createTimeEnd: params.createTimeEnd,
infoCard: params.infoCard
}
})
}
// 根据联系方式查询客户信息
export function getCustomerByContact(contact) {
return request({
url: '/customerManagement/getByContact',
method: 'get',
params: { contact }
})
}
// 根据ID查询客户
export function getCustomerById(id) {
return request({
url: `/customerManagement/get/${id}`,
method: 'get'
})
}
// 删除客户
export function deleteCustomer(id) {
return request({
url: `/customerManagement/delete/${id}`,
method: 'delete'
})
}
// 批量删除客户
export function batchDeleteCustomer(ids) {
return request({
url: '/customerManagement/batchDelete',
method: 'delete',
data: ids
})
}
// 添加新的客户信息(自动附带当前登录人姓名、账号,供后端 salesName / salesPhone
export function addCustomer(data) {
const body = data && typeof data === 'object' ? { ...data } : {}
const salesName = (store.getters.name || '').trim()
const salesPhone = resolveCurrentLoginAccount()
if (salesName) body.salesName = salesName
if (salesPhone) body.salesPhone = salesPhone
return request({
url: '/customerManagement/add',
method: 'post',
data: body
})
}
// 更新客户信息
export function updateCustomer(data) {
return request({
url: '/customerManagement/update',
method: 'put',
data
})
}
/**
* 预览客户照片(后端从 MinIO 拉流)。
* 方式一:传 url与 uploadPhoto 返回的 MinIO 访问 URL 一致)。
* 方式二:传 id + photoTypefront | side | life由后端读库再拉 MinIO。
* @param {{ url?: string, id?: string|number, photoType?: 'front'|'side'|'life' }}=} params
*/
export function previewCustomerPhoto(params) {
const p = params && typeof params === 'object' ? params : {}
const query = {}
if (p.url != null && String(p.url).trim() !== '') {
query.url = String(p.url).trim()
}
if (p.id != null && String(p.id).trim() !== '') {
query.id = String(p.id).trim()
}
if (p.photoType != null && String(p.photoType).trim() !== '') {
query.photoType = String(p.photoType).trim()
}
return request({
url: '/customerManagement/previewPhoto',
method: 'get',
params: query,
responseType: 'blob',
timeout: 120000
})
}
/** 客户照片上传至 MinIOid 可选,有则作为 query 传入;成功时响应 data 中含 url */
export function uploadCustomerPhoto(customerId, file) {
const formData = new FormData()
formData.append('file', file)
const config = {
url: '/customerManagement/uploadPhoto',
method: 'post',
data: formData,
timeout: 120000
}
if (customerId != null && String(customerId).trim() !== '') {
config.params = { id: String(customerId).trim() }
}
return request(config)
}
// 获取客户统计信息
export function getCustomerStatistics() {
return request({
url: '/customerManagement/statistics',
method: 'get'
})
}
// 导出客流
export function exportCustomerFlow(params) {
return request({
url: '/customerManagement/export',
method: 'get',
params,
responseType: 'blob'
})
}
/**
* 高德周边商家检索(地理编码 + place/around
* @param {{ CITY: string, ADDRESS: string, RADIUS: number, MAX_PAGE: number, maxRecordsOfpage: number }} params
*/
export function searchNearbyMerchants(params) {
return request({
url: '/customerManagement/searchNearbyMerchants',
method: 'get',
params: {
CITY: params.CITY,
ADDRESS: params.ADDRESS,
RADIUS: params.RADIUS,
MAX_PAGE: params.MAX_PAGE,
maxRecordsOfpage: params.maxRecordsOfpage
},
timeout: 120000,
skipResponseNormalize: true
})
}
// 沟通记录相关API
// 分页查询沟通记录
export function getCommunicationRecordPage(params) {
return request({
url: '/communication-record/page',
method: 'get',
params: {
current: params.current || 1,
size: params.size || 10,
customerName: params.customerName,
customerPhone: params.customerPhone,
communicationType: params.communicationType,
ownerName: params.ownerName
}
})
}
// 添加沟通记录
export function addCommunicationRecord(data) {
return request({
url: '/communication-record/add',
method: 'post',
data
})
}
// 更新沟通记录
export function updateCommunicationRecord(data) {
return request({
url: '/communication-record/update',
method: 'put',
data
})
}
// 删除沟通记录
export function deleteCommunicationRecord(id) {
return request({
url: `/communication-record/delete/${id}`,
method: 'delete'
})
}
// 根据ID查询沟通记录详情
export function getCommunicationRecordById(id) {
return request({
url: `/communication-record/get/${id}`,
method: 'get'
})
}