// pwuniapp/common/support.js // 统一客服入口:平台沟通仅通过官方客服微信/热线,不在买卖双方之间直接建立联系。 import { getPlatformConfigs } from '@/common/api.js'; let cachedContact = null; let cachedAt = 0; export async function getSupportContact() { if (cachedContact && Date.now() - cachedAt < 5 * 60 * 1000) { return cachedContact; } let hotline = ''; let wechat = ''; try { const configs = await getPlatformConfigs(); const cs = (configs && configs.customer_service) || {}; hotline = String(cs.hotline || '').trim(); wechat = String(cs.wechat || '').trim(); } catch (_) { // 配置拉取失败时使用空值,避免展示写死的客服账号 } cachedContact = { hotline, wechat }; cachedAt = Date.now(); return cachedContact; } export async function openSupportSheet() { const contact = await getSupportContact(); const actions = []; if (contact.wechat) actions.push({ key: 'wechat', label: `复制客服微信(${contact.wechat})` }); if (contact.hotline) actions.push({ key: 'hotline', label: `拨打客服热线(${contact.hotline})` }); if (actions.length === 0) { uni.showToast({ title: '客服信息暂未配置,请稍后再试', icon: 'none' }); return; } uni.showActionSheet({ itemList: actions.map((a) => a.label), success: (res) => { const picked = actions[res.tapIndex]; if (!picked) return; if (picked.key === 'wechat') { uni.setClipboardData({ data: contact.wechat, success: () => { uni.showToast({ title: '客服微信已复制,请前往微信添加', icon: 'none', duration: 2200 }); } }); } else if (picked.key === 'hotline') { uni.makePhoneCall({ phoneNumber: contact.hotline.replace(/[^0-9+]/g, ''), fail: () => { uni.showToast({ title: `客服热线:${contact.hotline}`, icon: 'none' }); } }); } } }); }