| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363 |
- <template>
- <view>
- <view class="menu-list">
- <!-- ===== 个人 ===== -->
- <view class="menu-group">
- <view class="menu-group-title">── 个人 ──</view>
- <view class="menu-item" @click="goToDailyTasks">
- <text>📋 每日任务</text>
- <text class="arrow">›</text>
- </view>
- <view class="menu-item" v-if="role === 'parent'" @click="goToOnboarding">
- <text>🎯 新手任务</text>
- <text class="arrow">›</text>
- </view>
- </view>
- <!-- ===== 财富 ===== -->
- <view class="menu-group">
- <view class="menu-group-title">── 财富 ──</view>
- <view class="menu-item" @click="goToPromotion">
- <text>📢 推广中心</text>
- <text class="arrow">›</text>
- </view>
- <view class="menu-item" @click="goToPointsLogs">
- <text>📊 积分记录</text>
- <text class="arrow">›</text>
- </view>
- <view class="menu-item" @click="goToCoupons">
- <text>🎫 我的优惠券</text>
- <text class="arrow">›</text>
- </view>
- </view>
- <!-- ===== 服务 ===== -->
- <view class="menu-group">
- <view class="menu-group-title">── 服务 ──</view>
- <view class="menu-item" @click="goToMembership">
- <text>👑 会员中心</text>
- <text class="arrow">›</text>
- </view>
- <view class="menu-item" v-if="isVendor" @click="goToVendorCenter">
- <text>🏪 服务商中心</text>
- <text class="arrow">›</text>
- </view>
- <view class="menu-item" @click="goToOrders">
- <text>🛒 订单管理</text>
- <text class="arrow">›</text>
- </view>
- <view class="menu-item" @click="goToConsigneeList">
- <text>📍 收货人管理</text>
- <text class="arrow">›</text>
- </view>
- <view class="menu-item" @click="goToAfterSales">
- <text>🔄 售后记录</text>
- <text class="arrow">›</text>
- </view>
- </view>
- <!-- ===== 设置 ===== -->
- <view class="menu-group">
- <view class="menu-group-title">── 设置 ──</view>
- <view class="menu-item" v-if="role === 'parent'" @click="showPasswordModal = true">
- <text>🔐 {{ hasPassword ? '重置密码' : '设置密码' }}</text>
- <text class="arrow">›</text>
- </view>
- <view class="menu-item menu-item-switch" v-if="role === 'parent'">
- <text>👁 对家庭成员可见</text>
- <switch :checked="showToFamily === 1" @change="onShowToFamilyChange" color="#5B9BD5" />
- </view>
- <view class="menu-item" @click="showInviteActionSheet">
- <text>📨 邀请加入</text>
- <text class="arrow">›</text>
- </view>
- <view class="menu-item" @click="logout">
- <text>🚪 退出登录</text>
- <text class="arrow">›</text>
- </view>
- </view>
- </view>
- <!-- 设置/重置密码弹窗 -->
- <view class="modal-mask" v-if="showPasswordModal" @click="showPasswordModal = false">
- <view class="modal" @click.stop>
- <view class="modal-title">{{ hasPassword ? '重置密码' : '设置密码' }}</view>
- <view class="form-item" v-if="hasPassword">
- <input v-model="oldPassword" type="number" password placeholder="输入旧密码" maxlength="6" />
- </view>
- <view class="form-item">
- <input v-model="newPassword" type="number" password placeholder="输入新密码" maxlength="6" />
- </view>
- <view class="form-item">
- <input v-model="confirmPassword" type="number" password placeholder="确认新密码" maxlength="6" />
- </view>
- <view class="modal-btns">
- <button @click="showPasswordModal = false">取消</button>
- <button class="btn-primary" @click="savePassword">确定</button>
- </view>
- </view>
- </view>
- </view>
- </template>
- <script>
- import { setPassword, verifyPassword, updateMemberVisibility, getVisibleFamilyMembers, vendorStatus } from '../../../utils/api.js'
- export default {
- name: 'ProfileMenu',
- props: {
- role: {
- type: String,
- default: 'parent'
- }
- },
- data() {
- return {
- hasPassword: false,
- showPasswordModal: false,
- oldPassword: '',
- newPassword: '',
- confirmPassword: '',
- showToFamily: 1,
- isVendor: false
- }
- },
- onShow() {
- if (!uni.getStorageSync('token')) return
- this.hasPassword = !!uni.getStorageSync('passwordSet')
- this.loadShowToFamily()
- this.checkVendorStatus()
- },
- methods: {
- async loadShowToFamily() {
- try {
- const uid = this.$store.state.userId || uni.getStorageSync('userId')
- const res = await getVisibleFamilyMembers()
- const members = res.data || []
- const self = members.find(m => m.id == uid)
- if (self) {
- this.showToFamily = self.showToFamily !== 0 ? 1 : 0
- }
- } catch (e) {}
- },
- goToOnboarding() {
- uni.navigateTo({ url: '/pages/profile/onboarding' })
- },
- goToDailyTasks() {
- uni.navigateTo({ url: '/pages/tasks/daily-tasks' })
- },
- goToPointsLogs() {
- uni.navigateTo({ url: '/pages/points/points' })
- },
- async onShowToFamilyChange(e) {
- const val = e.detail.value ? 1 : 0
- const uid = this.$store.state.userId || uni.getStorageSync('userId')
- try {
- await updateMemberVisibility(uid, 'parent', val)
- this.showToFamily = val
- uni.showToast({ title: val ? '已对家庭成员可见' : '已对家庭成员隐藏', icon: 'none' })
- } catch (e) {
- uni.showToast({ title: '操作失败', icon: 'none' })
- }
- },
- goToMembership() {
- uni.navigateTo({ url: '/pages/membership/index' })
- },
- goToVendorCenter() {
- uni.navigateTo({ url: '/pages/vendor/center' })
- },
- goToOrders() {
- uni.navigateTo({ url: '/pages/shop/order-list/order-list' })
- },
- goToConsigneeList() {
- uni.navigateTo({ url: '/pages/shop/consignee-list/consignee-list' })
- },
- goToAfterSales() {
- uni.navigateTo({ url: '/pages/shop/after-sales/after-sales' })
- },
- goToPromotion() {
- uni.navigateTo({ url: '/pages/promotion/index' })
- },
- goToCoupons() {
- uni.navigateTo({ url: '/pages/profile/coupons' })
- },
- showInviteActionSheet() {
- const familyId = uni.getStorageSync('familyId')
- const userInfo = uni.getStorageSync('userInfo')
- if (!familyId) {
- uni.showToast({ title: '您暂未加入家庭', icon: 'none' })
- return
- }
- const items = ['👨👩👧👦 邀请家人', '👨🏫 邀请成长规划师']
- const types = ['family', 'guide']
- uni.showActionSheet({
- itemList: items,
- success: (res) => {
- this.inviteGenerate(types[res.tapIndex], familyId, userInfo)
- }
- })
- },
- inviteGenerate(type, familyId, userInfo) {
- const inviteTypes = {
- family: {
- title: (userInfo && userInfo.nickname ? userInfo.nickname : '家人') + ' 邀请你加入家庭',
- path: '/pages/login/login?invite_type=family'
- },
- guide: {
- title: (userInfo && userInfo.nickname ? userInfo.nickname : '家长') + ' 邀请你成为家庭成长规划师',
- path: '/pages/login/login?invite_type=guide'
- }
- }
- const config = inviteTypes[type] || inviteTypes.family
- this.$emit('invite-generate', {
- title: config.title,
- path: config.path + '&invite_code=',
- imageUrl: '/static/invite-card.png'
- })
- uni.showToast({ title: '点击右上角转发给TA', icon: 'none' })
- },
- async savePassword() {
- if (this.newPassword.length !== 6) {
- uni.showToast({ title: '请输入6位密码', icon: 'none' })
- return
- }
- if (this.newPassword !== this.confirmPassword) {
- uni.showToast({ title: '两次密码不一致', icon: 'none' })
- return
- }
- if (this.hasPassword && this.oldPassword.length !== 6) {
- uni.showToast({ title: '请输入旧密码', icon: 'none' })
- return
- }
- try {
- if (this.hasPassword) {
- const verifyRes = await verifyPassword(this.oldPassword)
- if (verifyRes.code !== 200) {
- uni.showToast({ title: '旧密码错误', icon: 'none' })
- return
- }
- }
- await setPassword(this.newPassword)
- uni.setStorageSync('passwordSet', true)
- this.hasPassword = true
- uni.showToast({ title: '密码设置成功', icon: 'success' })
- this.showPasswordModal = false
- this.oldPassword = ''
- this.newPassword = ''
- this.confirmPassword = ''
- } catch (e) {
- console.error('设置密码失败', e)
- }
- },
- logout() {
- uni.showModal({
- title: '确认退出',
- content: '确定要退出登录吗?',
- success: (res) => {
- if (res.confirm) {
- this.$store.commit('logout')
- uni.reLaunch({ url: '/pages/index/index' })
- }
- }
- })
- },
- async checkVendorStatus() {
- try {
- const res = await vendorStatus()
- this.isVendor = res.data && res.data.vendorStatus === 'approved'
- } catch (e) {
- this.isVendor = false
- }
- }
- }
- }
- </script>
- <style scoped>
- .menu-list {
- margin: 30rpx;
- }
- .menu-group {
- background: #fff;
- border-radius: 20rpx;
- margin-bottom: 20rpx;
- overflow: hidden;
- }
- .menu-group-title {
- padding: 20rpx 30rpx 10rpx;
- font-size: 22rpx;
- color: #999;
- text-align: center;
- }
- .menu-item {
- display: flex;
- align-items: center;
- justify-content: space-between;
- padding: 28rpx 30rpx;
- border-bottom: 1rpx solid #f5f5f5;
- font-size: 28rpx;
- color: #333;
- }
- .menu-item:last-child {
- border-bottom: none;
- }
- .arrow {
- color: #ccc;
- font-size: 28rpx;
- }
- .menu-item-switch {
- justify-content: space-between;
- }
- .menu-item-switch text {
- flex: 1;
- }
- .modal-mask {
- position: fixed;
- top: 0;
- left: 0;
- right: 0;
- bottom: 0;
- background: rgba(0,0,0,0.5);
- display: flex;
- align-items: center;
- justify-content: center;
- z-index: 999;
- }
- .modal {
- background: #fff;
- border-radius: 20rpx;
- padding: 40rpx;
- width: 80%;
- }
- .modal-title {
- font-size: 32rpx;
- font-weight: bold;
- text-align: center;
- margin-bottom: 30rpx;
- }
- .form-item {
- margin-bottom: 20rpx;
- }
- .form-item input {
- border: 1rpx solid #ddd;
- border-radius: 12rpx;
- padding: 20rpx;
- font-size: 28rpx;
- }
- .modal-btns {
- display: flex;
- gap: 20rpx;
- margin-top: 30rpx;
- }
- .modal-btns button {
- flex: 1;
- font-size: 28rpx;
- padding: 20rpx;
- border-radius: 12rpx;
- }
- .modal-btns .btn-primary {
- background: #667eea;
- color: #fff;
- }
- </style>
|