From 3a6d9d1b6b44f0c0d3c252b60ff45121cac82998 Mon Sep 17 00:00:00 2001 From: WindowBird <13870814+windows-bird@user.noreply.gitee.com> Date: Fri, 7 Nov 2025 15:25:23 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=AE=A2=E6=88=B7=E8=A1=A5?= =?UTF-8?q?=E5=85=85=E5=B7=A5=E4=BD=9C=E5=BE=AE=E4=BF=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- common/api/customer.js | 12 ++++++++++ pages/customer/add/index.vue | 45 ++++++++++++++++++++++++++---------- 2 files changed, 45 insertions(+), 12 deletions(-) diff --git a/common/api/customer.js b/common/api/customer.js index 779af75..fae4097 100644 --- a/common/api/customer.js +++ b/common/api/customer.js @@ -224,3 +224,15 @@ export const getCustomerStatusDict = () => { }); }; +/** + * 获取微信列表 + * @returns {Promise} 返回微信列表 { total: number, rows: array } + */ +export const getWechatList = () => { + return uni.$uv.http.get(`bst/wechat/list`, { + custom: { + auth: true + } + }); +}; + diff --git a/pages/customer/add/index.vue b/pages/customer/add/index.vue index 5d01af0..a0fa8a6 100644 --- a/pages/customer/add/index.vue +++ b/pages/customer/add/index.vue @@ -372,7 +372,8 @@ import { getCustomerIntentLevelDict, getCustomerSourceDict, getCustomerTypeDict, - getCustomerStatusDict + getCustomerStatusDict, + getWechatList } from '@/common/api'; import { useUserStore } from '@/store/user'; @@ -500,6 +501,30 @@ const loadDictData = async () => { } }; +// 加载微信列表数据 +const loadWechatList = async () => { + try { + const res = await getWechatList(); + const rows = res?.rows || []; + + // 处理微信列表数据,使用 id 作为值(传递给后端的 workWechatId) + workWechatOptions.value = rows.map(item => ({ + label: item.nickName ? `${item.nickName} (${item.wechatId})` : item.wechatId, + value: String(item.id), // 使用数据库主键 id,转换为字符串 + id: item.id, + wechatId: item.wechatId // 保留 wechatId 用于显示 + })); + + console.log('微信列表加载成功:', workWechatOptions.value); + } catch (err) { + console.error('加载微信列表失败:', err); + uni.showToast({ + title: '加载微信列表失败', + icon: 'none' + }); + } +}; + // 加载地区树数据 const loadRegionTree = async () => { try { @@ -569,13 +594,8 @@ const handlePickValueDefault = () => { } }; -// 工作微信选项(示例数据,实际应从API获取,包含ID和名称) -const workWechatOptions = [ - { label: '工作微信1', value: '工作微信1', id: '1' }, - { label: '工作微信2', value: '工作微信2', id: '2' }, - { label: '工作微信3', value: '工作微信3', id: '3' }, - { label: '工作微信4', value: '工作微信4', id: '4' } -]; +// 工作微信选项(从API获取) +const workWechatOptions = ref([]); // 获取客户类型文本 const getCustomerTypeText = (value) => { @@ -797,10 +817,10 @@ const selectWorkWechat = (value) => { // 确认工作微信 const confirmWorkWechat = () => { - const selectedWechat = workWechatOptions.find(w => w.value === tempWorkWechat.value); + const selectedWechat = workWechatOptions.value.find(w => w.value === tempWorkWechat.value); if (selectedWechat) { - formData.value.workWechat = selectedWechat.value; - formData.value.workWechatId = selectedWechat.id; + formData.value.workWechat = selectedWechat.label; // 显示名称 + formData.value.workWechatId = selectedWechat.value; // 使用 id 作为值(传递给后端的 workWechatId) } showWorkWechatPicker.value = false; }; @@ -853,10 +873,11 @@ const handleCancel = () => { uni.navigateBack(); }; -// 组件挂载时加载地区树数据和字典数据 +// 组件挂载时加载地区树数据、字典数据和微信列表 onMounted(() => { loadRegionTree(); loadDictData(); + loadWechatList(); }); // 保存