| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238 |
- /**
- * 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) })
- }
|