diff --git a/common/api/customer.js b/common/api/customer.js index 9549d25..a7ce95d 100644 --- a/common/api/customer.js +++ b/common/api/customer.js @@ -11,7 +11,6 @@ * @param {string} params.excludeld 排除id * @param {string[]} params.ids id列表 * @param {string} params.intent 意向 - * @param {string} params.createDate 创建日期 (yyyy-MM-dd) * @param {string} params.joinUserld 参与人id * @param {string} params.lastFollowDate 上次跟进日期 (yyyy-MM-dd) * @param {string} params.nextFollowDate 下次跟进日期 (yyyy-MM-dd) @@ -21,85 +20,42 @@ * @param {string[]} params.saleList 销售列表 * @returns {Promise} 返回客户列表 { total: number, rows: array } */ +// 最终推荐版本(添加默认排序参数) export const getCustomerList = (params = {}) => { + console.log('api params:', params); + const queryParams = []; - - // 处理分页参数 - if (params.pageNum !== undefined && params.pageNum !== null) { - queryParams.push(`pageNum=${encodeURIComponent(params.pageNum)}`); - } - - if (params.pageSize !== undefined && params.pageSize !== null) { - queryParams.push(`pageSize=${encodeURIComponent(params.pageSize)}`); - } - - // 处理数组参数 - if (params.statusList && Array.isArray(params.statusList) && params.statusList.length > 0) { - params.statusList.forEach(status => { - queryParams.push(`statusList=${encodeURIComponent(status)}`); - }); - } - - if (params.ids && Array.isArray(params.ids) && params.ids.length > 0) { - params.ids.forEach(id => { - queryParams.push(`ids=${encodeURIComponent(id)}`); - }); - } - - if (params.createDateRange && Array.isArray(params.createDateRange) && params.createDateRange.length > 0) { - params.createDateRange.forEach(date => { - queryParams.push(`createDateRange=${encodeURIComponent(date)}`); - }); - } - - if (params.saleList && Array.isArray(params.saleList) && params.saleList.length > 0) { - params.saleList.forEach(sale => { - queryParams.push(`saleList=${encodeURIComponent(sale)}`); - }); - } - - // 处理字符串参数 - if (params.excludeld) { - queryParams.push(`excludeld=${encodeURIComponent(params.excludeld)}`); - } - - if (params.intent) { - queryParams.push(`intent=${encodeURIComponent(params.intent)}`); - } - - if (params.createDate) { - queryParams.push(`createDate=${encodeURIComponent(params.createDate)}`); - } - - if (params.joinUserld) { - queryParams.push(`joinUserld=${encodeURIComponent(params.joinUserld)}`); - } - - if (params.lastFollowDate) { - queryParams.push(`lastFollowDate=${encodeURIComponent(params.lastFollowDate)}`); - } - - if (params.nextFollowDate) { - queryParams.push(`nextFollowDate=${encodeURIComponent(params.nextFollowDate)}`); - } - - if (params.nextFollowDateStart) { - queryParams.push(`nextFollowDateStart=${encodeURIComponent(params.nextFollowDateStart)}`); - } - - if (params.nextFollowDateEnd) { - queryParams.push(`nextFollowDateEnd=${encodeURIComponent(params.nextFollowDateEnd)}`); - } - - const queryString = queryParams.length > 0 ? `?${queryParams.join('&')}` : ''; - - return uni.$uv.http.get(`bst/customer/list${queryString}`, { - custom: { - auth: true // 启用 token 认证 + + // 添加默认排序参数 + 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 diff --git a/components/CustomerManagement.vue b/components/CustomerManagement.vue index cdd1150..8f6fe3a 100644 --- a/components/CustomerManagement.vue +++ b/components/CustomerManagement.vue @@ -3,6 +3,7 @@ 客户管理 + 筛选 @@ -105,7 +106,7 @@ - 客户归属: + 跟进人: {{ customer.followName || '--' }} @@ -161,11 +162,13 @@ import FabPlus from '@/components/FabPlus.vue'; import CustomerSummaryBrief from '@/components/customer/CustomerSummaryBrief.vue'; import { usePagination } from '@/composables/usePagination'; import { getCustomerList, deleteCustomer } from '@/common/api/customer'; +import{useUserStore} from "@/store/user"; import { getStatusListByFilter } from '@/utils/customerMappings'; // 筛选状态 +const filterSelf =ref(false); const showFilter = ref(false); const filterStatus = ref(''); @@ -226,6 +229,10 @@ const formatDateTime = (dateTime) => { const buildQueryParams = () => { const params = {}; + params.joinUserId = filterSelf.value? useUserStore().getUserInfo.user.userId : null + console.log(filterSelf.value? useUserStore().getUserInfo.user.userId : null) + + // 只有有效的筛选状态才添加statusList参数 if (filterStatus.value) { const statusList = getStatusListByFilter(filterStatus.value); @@ -364,6 +371,7 @@ watch(filterStatus, () => { reset(); // 清除所有查询参数,只保留基础分页参数 queryParams.value = { + joinUserId: filterSelf.value? useUserStore().getUserInfo.user.userId : null, pageNum: 1, pageSize: 10 }; @@ -376,6 +384,13 @@ watch(filterStatus, () => { } }); +watch(filterSelf, () => { + console.log('筛选是否自己变化:', filterSelf.value); + const params = buildQueryParams(); + console.log(':当前参数', params); + updateParams(params); +}) + // 监听客户列表刷新事件 const handleCustomerListRefresh = () => { console.log('收到客户列表刷新事件'); diff --git a/utils/request/index.js b/utils/request/index.js index a397cd6..1a9501b 100644 --- a/utils/request/index.js +++ b/utils/request/index.js @@ -11,7 +11,7 @@ export const Request = () => { uni.$uv.http.setConfig((config) => { /* config 为默认全局配置*/ config.baseURL = 'http://192.168.1.5:4001'; /* 根域名 */ - config.baseURL = 'https://pm.ccttiot.com/prod-api'; /* 根域名 */ + // config.baseURL = 'https://pm.ccttiot.com/prod-api'; /* 根域名 */ return config })