/** * CRM 管理端接口(复用 /web/crm/*,需 admin JWT) */ import { request, parseResponseJson } from '@/utils/request' function unwrap(res) { const body = parseResponseJson(res) if (!body || typeof body !== 'object') { throw new Error('接口响应异常') } if (body.code != null && body.code !== 200) { throw new Error(body.message || '请求失败') } return body.data != null ? body.data : body } async function post(url, data = {}) { const res = await request({ url, method: 'POST', data }) return unwrap(res) } async function get(url, params = {}) { const res = await request({ url, method: 'GET', data: params, params }) return unwrap(res) } function pageBody(query = {}) { const { pageNum, page, pageSize, ...rest } = query return { page: pageNum ?? page ?? 1, pageSize: pageSize ?? 20, ...rest } } function normalizeList(data) { if (Array.isArray(data)) { return { rows: data, total: data.length } } const d = data || {} return { rows: d.list || d.rows || [], total: d.total ?? (d.list || d.rows || []).length } } // ── 线索 ── export async function listClue(query = {}) { const { pageNum, pageSize, ...rest } = query return normalizeList(await post('/web/crm/clue/list', pageBody({ pageNum, pageSize, ...rest }))) } export async function listMyClue(query = {}) { const { pageNum, pageSize, ...rest } = query return normalizeList(await post('/web/crm/clue/mine', pageBody({ pageNum, pageSize, ...rest }))) } export async function getClue(id) { return post('/web/crm/clue/detail', { id: String(id) }) } export function addClue(data) { return post('/web/crm/clue/add', data) } export function updateClue(data) { return post('/web/crm/clue/update', data) } export function convertClue(data) { return post('/web/crm/clue/convert', { id: String(data.clueId ?? data.id), customerName: data.customerName, customerType: data.customerType, contactName: data.contactName, contactMobile: data.contactMobile, remark: data.remark }) } export function markClueInvalid(data) { return post('/web/crm/clue/invalid', { id: data.id != null ? String(data.id) : undefined, remark: data.remark }) } export async function listClueFollow(clueId, pageNum = 1, pageSize = 20) { return normalizeList( await post('/web/crm/clue/follow/list', { clueId: String(clueId), page: pageNum, pageSize }) ) } export function addClueFollow(data) { return post('/web/crm/clue/follow/add', { ...data, clueId: String(data.clueId) }) } // ── 商机 ── export async function listOpportunity(query = {}) { const { pageNum, pageSize, ...rest } = query return normalizeList( await post('/web/crm/opportunity/list', pageBody({ pageNum, pageSize, ...rest })) ) } export async function getOpportunity(id) { return post('/web/crm/opportunity/detail', { id: String(id) }) } export async function listOpportunityFollow(opportunityId, pageNum = 1, pageSize = 20) { return normalizeList( await post('/web/crm/opportunity/follow/list', { opportunityId: String(opportunityId), page: pageNum, pageSize }) ) } export function addOpportunityFollow(data) { return post('/web/crm/opportunity/follow/add', { ...data, opportunityId: String(data.opportunityId) }) } // ── 客户 ── export async function listCustomer(query = {}) { const { pageNum, pageSize, ...rest } = query return normalizeList( await post('/web/crm/customer/list', pageBody({ pageNum, pageSize, ...rest })) ) } export async function listMyCustomer(query = {}) { const { pageNum, pageSize, ...rest } = query return normalizeList( await post('/web/crm/customer/mine', pageBody({ pageNum, pageSize, ...rest })) ) } export async function getCustomer(id) { return post('/web/crm/customer/detail', { id: String(id) }) } export async function listCustomerFollow(customerId, pageNum = 1, pageSize = 20) { return normalizeList( await post('/web/crm/customer/follow/byCustomer', { customerId: String(customerId), page: pageNum, pageSize }) ) } export function addCustomerFollow(data) { return post('/web/crm/customer/follow/add', { ...data, customerId: String(data.customerId) }) } // ── 公海 ── export async function listPoolCustomer(query = {}) { const { pageNum, pageSize, ...rest } = query return normalizeList( await post('/web/crm/customer/pool/list', pageBody({ pageNum, pageSize, ...rest })) ) } export function claimCustomer(ids) { const idList = Array.isArray(ids) ? ids.map(String) : [String(ids)] return post('/web/crm/customer/claim', { ids: idList }) } // ── 报价 ── export async function listQuote(query = {}) { const { pageNum, pageSize, ...rest } = query return normalizeList(await post('/web/crm/quote/list', pageBody({ pageNum, pageSize, ...rest }))) } export async function getQuote(id) { return post('/web/crm/quote/detail', { id: String(id) }) } // ── 合同(GET) ── export async function listContract(query = {}) { const params = { pageNum: query.pageNum ?? 1, pageSize: query.pageSize ?? 20 } ;['keyword', 'contractNo', 'contractName', 'customerName', 'status', 'approvalStatus'].forEach( (k) => { if (query[k] != null && query[k] !== '') params[k] = query[k] } ) return normalizeList(await get('/web/crm/contract/list', params)) } export async function getContract(id) { return get(`/web/crm/contract/${String(id)}`) } // ── 产品分类 ── /** 产品分类树(不分页,嵌套 children) */ export async function listProductCategoryTree(query = {}) { const body = {} if (query.categoryName) body.categoryName = String(query.categoryName).trim() if (query.status != null && query.status !== '') body.status = String(query.status) const data = await post('/web/crm/product-categories/tree', body) return Array.isArray(data) ? data : [] } export function addProductCategory(data) { return post('/web/crm/product-categories/add', data) } export function updateProductCategory(data) { return post('/web/crm/product-categories/update', data) } export function deleteProductCategory(id) { return post('/web/crm/product-categories/delete', { id: String(id) }) }