OfficeSystem/api/customer.js
2025-11-12 15:34:06 +08:00

341 lines
9.8 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.

/**
* 客户相关 API
*/
/**
* 获取客户列表
* @param {Object} params 请求参数(可选)
* @param {number} params.pageNum 页码从1开始
* @param {number} params.pageSize 每页数量
* @param {string[]} params.statusList 客户状态列表:["1"] 潜在, ["2"] 意向, ["3"] 成交, ["4"] 失效
* @param {string} params.excludeld 排除id
* @param {string[]} params.ids id列表
* @param {string} params.intent 意向
* @param {string} params.joinUserld 参与人id
* @param {string} params.lastFollowDate 上次跟进日期 (yyyy-MM-dd)
* @param {string} params.nextFollowDate 下次跟进日期 (yyyy-MM-dd)
* @param {string} params.nextFollowDateStart 下次跟进日期开始 (yyyy-MM-dd)
* @param {string} params.nextFollowDateEnd 下次跟进日期结束 (yyyy-MM-dd)
* @param {string[]} params.createDateRange 创建日期范围 (yyyy-MM-dd)
* @param {string[]} params.saleList 销售列表
* @returns {Promise} 返回客户列表 { total: number, rows: array }
*/
// 最终推荐版本(添加默认排序参数)
export const getCustomerList = (params = {}) => {
console.log('api params:', params);
const queryParams = [];
// 添加默认排序参数
const defaultParams = {
orderByColumn: 'nextFollowTime',
isAsc: 'ascending'
};
// 合并参数:默认参数 + 用户传入参数(用户参数优先)
const finalParams = { ...defaultParams, ...params };
Object.entries(finalParams).forEach(([key, value]) => {
if (value == null) return; // 过滤 null 和 undefined
if (Array.isArray(value)) {
value.forEach(item => {
if (item != null) {
queryParams.push(`${encodeURIComponent(key)}=${encodeURIComponent(item.toString())}`);
}
});
} else {
queryParams.push(`${encodeURIComponent(key)}=${encodeURIComponent(value.toString())}`);
}
});
const queryString = queryParams.join('&');
const url = `bst/customer/list${queryString ? `?${queryString}` : ''}`;
console.log('最终请求URL:', url);
return uni.$uv.http.get(url, { custom: { auth: true } });
};
/**
* 获取客户详情
* @param {string} id 客户ID
* @returns {Promise} 返回客户详情
*/
export const getCustomerDetail = (id) => {
return uni.$uv.http.get(`bst/customer/${id}`, {
custom: {
auth: true // 启用 token 认证
}
});
};
/**
* 获取客户跟进动态列表
* @param {string} customerId 客户ID
* @returns {Promise} 返回跟进动态列表 { total: number, rows: array }
*/
export const getCustomerFollowupList = (customerId) => {
return uni.$uv.http.get(`bst/customerFollow/list`, {
params: {
customerId: customerId
},
custom: {
auth: true
}
});
};
/**
* 获取跟进详情
* @param {string} followId 跟进ID
* @returns {Promise} 返回跟进详情
*/
export const getFollowupDetail = (followId) => {
return uni.$uv.http.get(`bst/customerFollow/${followId}`, {
custom: {
auth: true
}
});
};
/**
* 创建跟进记录
* @param {Object} data 跟进记录数据
* @param {string} data.customerId 客户ID
* @param {string} data.type 跟进方式
* @param {string} data.content 跟进内容
* @param {string} data.picture 图片URL多个用逗号分隔
* @param {string} data.attaches 附件URL多个用逗号分隔
* @param {string} data.followTime 跟进时间 (yyyy-MM-dd HH:mm:ss)
* @param {string} data.nextFollowTime 下次跟进时间 (yyyy-MM-dd HH:mm:ss)
* @param {string} data.customerStatus 客户状态
* @param {string} data.customerIntentLevel 客户意向强度
* @returns {Promise} 返回创建结果
*/
export const createFollowup = (data) => {
return uni.$uv.http.post(`bst/customerFollow`, data, {
custom: {
auth: true
}
});
};
/**
* 更新跟进记录
* @param {Object} data 跟进记录数据(必须包含 followId
* @param {string} data.followId 跟进ID
* @param {string} data.customerId 客户ID
* @param {string} data.type 跟进方式
* @param {string} data.content 跟进内容
* @param {string} data.picture 图片URL多个用逗号分隔
* @param {string} data.attaches 附件URL多个用逗号分隔
* @param {string} data.followTime 跟进时间 (yyyy-MM-dd HH:mm:ss)
* @param {string} data.nextFollowTime 下次跟进时间 (yyyy-MM-dd HH:mm:ss)
* @param {string} data.customerStatus 客户状态
* @param {string} data.customerIntentLevel 客户意向强度
* @returns {Promise} 返回更新结果
*/
export const updateFollowup = (data) => {
return uni.$uv.http.put(`bst/customerFollow`, data, {
custom: {
auth: true
}
});
};
/**
* 删除跟进记录
* @param {string|string[]} followIds 跟进ID或ID数组多个ID用逗号分隔或传入数组
* @returns {Promise} 返回删除结果
*/
export const deleteFollowup = (followIds) => {
// 如果传入的是数组,转换为逗号分隔的字符串
const idsParam = Array.isArray(followIds) ? followIds.join(',') : followIds;
return uni.$uv.http.delete(`bst/customerFollow/${idsParam}`, {}, {
custom: {
auth: true
}
});
};
/**
* 获取客户项目列表
* @param {string} customerId 客户ID
* @returns {Promise} 返回项目列表
*/
export const getCustomerProjects = (customerId) => {
return uni.$uv.http.get(`bst/project/list`, {
params: {
customerId: customerId,
pageNum: 1,
pageSize: 30
},
custom: {
auth: true
}
});
};
/**
* 创建客户
* @param {Object} data 客户数据
* @param {string} data.type 类型(固定为2)
* @param {string} data.name 客户名
* @param {string} data.mobile 手机号
* @param {string} data.wechat 微信号
* @param {string} data.source 来源
* @param {string} data.intents 意向的设备,逗号分离
* @param {string} data.status 状态(1潜在2意向3成交4失效)
* @param {string} data.intentLevel 意向强度
* @param {string} data.customerStatus 客户状态
* @param {string} data.customerIntentLevel 客户意向强度
* @param {string} data.nextFollowTime 下次跟进时间
* @param {string} data.followId 跟进人id
* @param {string} data.remark 备注
* @param {string} data.concern 顾虑点
* @param {string} data.pain 痛点
* @param {string} data.attention 关注点
* @param {string} data.demand 需求点
* @returns {Promise} 返回创建结果
*/
export const createCustomer = (data) => {
return uni.$uv.http.post(`bst/customer`, data, {
custom: {
auth: true
}
});
};
/**
* 更新客户
* @param {Object} data 客户数据必须包含id
* @param {string} data.id 客户ID
* @param {string} data.type 类型
* @param {string} data.name 客户名
* @param {string} data.mobile 手机号
* @param {string} data.wechat 微信号
* @param {string} data.source 来源
* @param {string} data.intents 意向的设备,逗号分离
* @param {string} data.status 状态(1潜在2意向3成交4失效)
* @param {string} data.intentLevel 意向强度
* @param {string} data.customerStatus 客户状态
* @param {string} data.customerIntentLevel 客户意向强度
* @param {string} data.nextFollowTime 下次跟进时间
* @param {string} data.followId 跟进人id
* @param {string} data.remark 备注
* @param {string} data.concern 顾虑点
* @param {string} data.pain 痛点
* @param {string} data.attention 关注点
* @param {string} data.demand 需求点
* @returns {Promise} 返回更新结果
*/
export const updateCustomer = (data) => {
return uni.$uv.http.put(`bst/customer`, data, {
custom: {
auth: true
}
});
};
/**
* 获取客户意向字典数据
* @returns {Promise} 返回字典数据数组,包含 dictLabel 和 dictValue
*/
export const getCustomerIntentDict = () => {
return uni.$uv.http.get(`system/dict/data/type/customer_intent`, {
custom: {
auth: true
}
});
};
/**
* 获取客户意向强度字典数据
* @returns {Promise} 返回字典数据数组,包含 dictLabel 和 dictValue
*/
export const getCustomerIntentLevelDict = () => {
return uni.$uv.http.get(`system/dict/data/type/customer_intent_level`, {
custom: {
auth: true
}
});
};
/**
* 获取客户来源字典数据
* @returns {Promise} 返回字典数据数组,包含 dictLabel 和 dictValue
*/
export const getCustomerSourceDict = () => {
return uni.$uv.http.get(`system/dict/data/type/customer_source`, {
custom: {
auth: true
}
});
};
/**
* 获取客户类型字典数据
* @returns {Promise} 返回字典数据数组,包含 dictLabel 和 dictValue
*/
export const getCustomerTypeDict = () => {
return uni.$uv.http.get(`system/dict/data/type/customer_type`, {
custom: {
auth: true
}
});
};
/**
* 获取客户状态字典数据
* @returns {Promise} 返回字典数据数组,包含 dictLabel 和 dictValue
*/
export const getCustomerStatusDict = () => {
return uni.$uv.http.get(`system/dict/data/type/customer_status`, {
custom: {
auth: true
}
});
};
/**
* 获取客户跟进方式字典数据
* @returns {Promise} 返回字典数据数组,包含 dictLabel 和 dictValue
*/
export const getCustomerFollowTypeDict = () => {
return uni.$uv.http.get(`system/dict/data/type/customer_follow_type`, {
custom: {
auth: true
}
});
};
/**
* 获取微信列表
* @returns {Promise} 返回微信列表 { total: number, rows: array }
*/
export const getWechatList = () => {
return uni.$uv.http.get(`bst/wechat/list`, {
custom: {
auth: true
}
});
};
/**
* 删除客户
* @param {string|string[]} ids 客户ID或ID数组多个ID用逗号分隔或传入数组
* @returns {Promise} 返回删除结果
*/
export const deleteCustomer = (ids) => {
// 如果传入的是数组,转换为逗号分隔的字符串
const idsParam = Array.isArray(ids) ? ids.join(',') : ids;
return uni.$uv.http.delete(`bst/customer/${idsParam}`,{}, {
custom: {
auth: true // 启用 token 认证
}
});
};