Files
smartDriveEEFront/src/api/customer.js
2026-05-02 19:03:59 +08:00

222 lines
5.5 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
})
}
function isLikelyBackendOrProxyAsset(absoluteUrl) {
try {
const p = new URL(absoluteUrl).pathname || ''
return p.startsWith('/api/') || p.includes('/customerManagement')
} catch (e) {
return false
}
}
/**
* 按列表/详情中保存的地址拉取图片:相对路径或指向本系统接口的完整 URL 走 axios含 Token、业务头经 dev 代理);
* 其余完整 URL如公网图床、MinIO 外链)返回 { useDirect: true, url },由前端用 img 直链展示。
*/
export function loadCustomerPhotoForDisplay(storedUrl) {
if (storedUrl == null || String(storedUrl).trim() === '') {
return Promise.reject(new Error('EMPTY_URL'))
}
const raw = String(storedUrl).trim()
const isAbs = /^https?:\/\//i.test(raw)
if (isAbs && !isLikelyBackendOrProxyAsset(raw)) {
return Promise.resolve({ useDirect: true, url: raw })
}
let path = raw
if (isAbs) {
try {
const u = new URL(raw)
path = u.pathname + (u.search || '')
} catch (e) {
return Promise.reject(e)
}
}
if (!path.startsWith('/')) {
path = `/${path}`
}
if (path.startsWith('/api/')) {
path = path.slice(4)
}
return request({
url: path,
method: 'get',
responseType: 'blob',
timeout: 120000
}).then(blob => ({ useDirect: false, blob }))
}
/** 客户照片上传至 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'
})
}
// 沟通记录相关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'
})
}