import React, { useState, useEffect } from 'react' import { View, Text, Input } from '@tarojs/components' import Taro from '@tarojs/taro' import { useUser } from '@/hooks/useUser' import { addShopDealerApply, listShopDealerApply } from '@/api/shop/shopDealerApply' import type { ShopDealerApply } from '@/api/shop/shopDealerApply/model' definePageConfig({ navigationBarTitleText: '升级VIP会员', }) const VipUpgradePage: React.FC = () => { const { user, isLoggedIn } = useUser() const [realName, setRealName] = useState('') const [address, setAddress] = useState('') const [loading, setLoading] = useState(false) const [existingApply, setExistingApply] = useState(null) useEffect(() => { if (!isLoggedIn) { Taro.navigateTo({ url: '/passport/login' }) return } if (user) { // 门店名称和地址统一从 shop-dealer-apply 表读取 listShopDealerApply({ userId: (user as any)?.userId || (user as any)?.id }) .then(data => { if (!data || data.length === 0) return // 取最新一条申请记录(按 applyId 倒序) const latest = [...data].sort((a, b) => (b.applyId || 0) - (a.applyId || 0))[0] if (latest) { setExistingApply(latest) setRealName(latest.realName || '') setAddress(latest.address || '') } }) .catch(() => {}) } }, [user, isLoggedIn]) const handleSave = async () => { if (!realName.trim()) { Taro.showToast({ title: '请输入门店名称', icon: 'none' }) return } if (!address.trim()) { Taro.showToast({ title: '请输入门店地址', icon: 'none' }) return } setLoading(true) try { await addShopDealerApply({ userId: (user as any)?.userId || (user as any)?.id, realName: realName.trim(), address: address.trim(), applyType: 10, // 需后台审核 applyStatus: 10, // 待审核 } as ShopDealerApply) Taro.showToast({ title: '提交成功,等待审核', icon: 'none' }) setTimeout(() => { Taro.navigateBack() }, 1500) } catch (error) { console.error('提交失败:', error) Taro.showToast({ title: '提交失败,请重试', icon: 'none' }) } finally { setLoading(false) } } // 待审核(10) 和 已通过(20) 时只读展示;已驳回(30) 允许编辑后重新提交 const isReadonly = existingApply?.applyStatus === 10 || existingApply?.applyStatus === 20 if (!isLoggedIn) return null return ( {/* 顶部渐变背景 */} 👑 升级VIP会员 {existingApply?.applyStatus === 20 ? '恭喜您已是VIP会员' : '填写门店信息,申请VIP会员资格'} {/* 状态提示 */} {existingApply && ( {existingApply.applyStatus === 10 ? '⏳' : '✅'} {existingApply.applyStatus === 10 ? '审核中' : '审核通过'} {existingApply.applyStatus === 10 ? '您的VIP申请正在审核中,请耐心等待。审核结果将通过消息通知您。' : '恭喜!您的VIP会员申请已审核通过,现在可以享受全部VIP专属权益。'} )} {/* 说明卡片 */} {!existingApply && ( 💡 温馨提示 请填写您的门店信息,提交后管理员将进行审核。审核通过后即可享受VIP会员专属权益,包括更高佣金、专属折扣等特权。 )} {/* 表单 */} {/* 门店名称 */} 门店名称 * setRealName(e.detail.value)} maxlength={50} disabled={isReadonly} /> {/* 门店地址 */} 门店地址 * setAddress(e.detail.value)} maxlength={100} disabled={isReadonly} /> {/* VIP权益预览 */} VIP会员专属权益 {[ { icon: '💎', title: '更高佣金', desc: '享受高额团队佣金' }, { icon: '🎁', title: '专属折扣', desc: '购物享VIP专属价' }, { icon: '⚡', title: '优先发货', desc: '订单优先处理配送' }, { icon: '🎧', title: '专属客服', desc: '一对一VIP服务' }, ].map(item => ( {item.icon} {item.title} {item.desc} ))} {/* 提交按钮 */} {!existingApply && ( {loading ? '提交中...' : '提交申请'} 提交后管理员将在1-3个工作日内审核 )} ) } export default VipUpgradePage