import React, { useState, useEffect, useCallback } from 'react' import { View, Text, Image } from '@tarojs/components' import Taro from '@tarojs/taro' import { getMyClerk } from '@/api/shop/shopStoreUser' import { listShopDealerApply } from '@/api/shop/shopDealerApply' import { pageShopOrder } from '@/api/shop/shopOrder' definePageConfig({ navigationBarTitleText: '门店中心', }) // 功能卡片定义(未来新增功能只需在这里加一项) const FEATURE_CARDS = [ { key: 'orders', icon: '📦', title: '订单管理', desc: '查看和处理门店订单', url: '/pages/store/orders/index', color: '#15803d', bgColor: '#dcfce7', // 显示待处理订单数量角标 showBadge: true, }, { key: 'vip-review', icon: '👑', title: 'VIP会员审核', desc: '审核客户VIP会员申请', url: '/pages/user/vip-review/index', color: '#7c3aed', bgColor: '#ede9fe', showBadge: true, }, ] // 订阅消息模板 ID const SUBSCRIBE_TMPL_IDS = [ 'sh1K9iK7vZjebUNFu6OsMsnsJxm4whThWGrhN7I4zVg', // 交易提醒:订单号、商品名称、联系人、联系电话、送货地址 ] export default function StoreCenterPage() { const [storeInfo, setStoreInfo] = useState(null) const [pendingVipCount, setPendingVipCount] = useState(0) const [pendingOrderCount, setPendingOrderCount] = useState(0) const [loading, setLoading] = useState(true) useEffect(() => { // 验证店员身份 getMyClerk() .then(data => { if (!data) { Taro.showToast({ title: '仅门店店员可访问', icon: 'none' }) setTimeout(() => Taro.navigateBack(), 1500) return } setStoreInfo(data) // 加载待审核数量 loadBadgeCounts() }) .catch(() => { Taro.showToast({ title: '仅门店店员可访问', icon: 'none' }) setTimeout(() => Taro.navigateBack(), 1500) }) .finally(() => setLoading(false)) }, []) /** 加载各类待处理角标数量 */ const loadBadgeCounts = async () => { try { // VIP 待审核 const vipData = await listShopDealerApply({ applyStatus: 10 }) setPendingVipCount((vipData || []).length) } catch { /* ignore */ } try { // 待处理订单:未付款/待发货/待收货 const orderData = await pageShopOrder({ statusFilter: 1, page: 1, limit: 1 }) setPendingOrderCount(orderData?.total || 0) } catch { /* ignore */ } } /** 获取卡片角标数字 */ const getBadgeCount = (key: string) => { if (key === 'orders') return pendingOrderCount if (key === 'vip-review') return pendingVipCount return 0 } /** 请求订阅消息授权 */ const handleSubscribe = useCallback(() => { if (SUBSCRIBE_TMPL_IDS.length === 0) { Taro.showToast({ title: '暂无可订阅的消息模板', icon: 'none' }) return } Taro.requestSubscribeMessage({ tmplIds: SUBSCRIBE_TMPL_IDS, success: (res) => { // res[templateId] === 'accept' 表示用户同意订阅 const accepted = SUBSCRIBE_TMPL_IDS.filter(id => res[id] === 'accept') if (accepted.length > 0) { Taro.showToast({ title: '订阅成功', icon: 'success' }) } }, fail: (err) => { console.error('订阅失败:', err) }, }) }, []) if (loading) { return ( 加载中... ) } if (!storeInfo) return null return ( {/* 顶部信息区:店员头像 + 门店名称 */} {/* 店员头像 */} {storeInfo.avatar ? ( ) : ( 👤 )} {/* 门店信息 */} {storeInfo.storeName || '门店中心'} {storeInfo.name} {storeInfo.phone ? `· ${storeInfo.phone}` : ''} {/* 功能卡片区 */} {FEATURE_CARDS.map(card => ( Taro.navigateTo({ url: card.url })} > {/* 图标 */} {card.icon} {/* 文字 */} {card.title} {card.desc} {/* 待处理角标 */} {card.showBadge && getBadgeCount(card.key) > 0 && ( {getBadgeCount(card.key) > 99 ? '99+' : getBadgeCount(card.key)} )} {/* 箭头 */} ))} {/* 底部提示 */} {/* 订阅消息提醒 */} 🔔 接收新订单提醒 开启后新订单将通过微信服务通知提醒您 去开启 未来更多功能将持续上线 ) }