ProfileMenu.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363
  1. <template>
  2. <view>
  3. <view class="menu-list">
  4. <!-- ===== 个人 ===== -->
  5. <view class="menu-group">
  6. <view class="menu-group-title">── 个人 ──</view>
  7. <view class="menu-item" @click="goToDailyTasks">
  8. <text>📋 每日任务</text>
  9. <text class="arrow">›</text>
  10. </view>
  11. <view class="menu-item" v-if="role === 'parent'" @click="goToOnboarding">
  12. <text>🎯 新手任务</text>
  13. <text class="arrow">›</text>
  14. </view>
  15. </view>
  16. <!-- ===== 财富 ===== -->
  17. <view class="menu-group">
  18. <view class="menu-group-title">── 财富 ──</view>
  19. <view class="menu-item" @click="goToPromotion">
  20. <text>📢 推广中心</text>
  21. <text class="arrow">›</text>
  22. </view>
  23. <view class="menu-item" @click="goToPointsLogs">
  24. <text>📊 积分记录</text>
  25. <text class="arrow">›</text>
  26. </view>
  27. <view class="menu-item" @click="goToCoupons">
  28. <text>🎫 我的优惠券</text>
  29. <text class="arrow">›</text>
  30. </view>
  31. </view>
  32. <!-- ===== 服务 ===== -->
  33. <view class="menu-group">
  34. <view class="menu-group-title">── 服务 ──</view>
  35. <view class="menu-item" @click="goToMembership">
  36. <text>👑 会员中心</text>
  37. <text class="arrow">›</text>
  38. </view>
  39. <view class="menu-item" v-if="isVendor" @click="goToVendorCenter">
  40. <text>🏪 服务商中心</text>
  41. <text class="arrow">›</text>
  42. </view>
  43. <view class="menu-item" @click="goToOrders">
  44. <text>🛒 订单管理</text>
  45. <text class="arrow">›</text>
  46. </view>
  47. <view class="menu-item" @click="goToConsigneeList">
  48. <text>📍 收货人管理</text>
  49. <text class="arrow">›</text>
  50. </view>
  51. <view class="menu-item" @click="goToAfterSales">
  52. <text>🔄 售后记录</text>
  53. <text class="arrow">›</text>
  54. </view>
  55. </view>
  56. <!-- ===== 设置 ===== -->
  57. <view class="menu-group">
  58. <view class="menu-group-title">── 设置 ──</view>
  59. <view class="menu-item" v-if="role === 'parent'" @click="showPasswordModal = true">
  60. <text>🔐 {{ hasPassword ? '重置密码' : '设置密码' }}</text>
  61. <text class="arrow">›</text>
  62. </view>
  63. <view class="menu-item menu-item-switch" v-if="role === 'parent'">
  64. <text>👁 对家庭成员可见</text>
  65. <switch :checked="showToFamily === 1" @change="onShowToFamilyChange" color="#5B9BD5" />
  66. </view>
  67. <view class="menu-item" @click="showInviteActionSheet">
  68. <text>📨 邀请加入</text>
  69. <text class="arrow">›</text>
  70. </view>
  71. <view class="menu-item" @click="logout">
  72. <text>🚪 退出登录</text>
  73. <text class="arrow">›</text>
  74. </view>
  75. </view>
  76. </view>
  77. <!-- 设置/重置密码弹窗 -->
  78. <view class="modal-mask" v-if="showPasswordModal" @click="showPasswordModal = false">
  79. <view class="modal" @click.stop>
  80. <view class="modal-title">{{ hasPassword ? '重置密码' : '设置密码' }}</view>
  81. <view class="form-item" v-if="hasPassword">
  82. <input v-model="oldPassword" type="number" password placeholder="输入旧密码" maxlength="6" />
  83. </view>
  84. <view class="form-item">
  85. <input v-model="newPassword" type="number" password placeholder="输入新密码" maxlength="6" />
  86. </view>
  87. <view class="form-item">
  88. <input v-model="confirmPassword" type="number" password placeholder="确认新密码" maxlength="6" />
  89. </view>
  90. <view class="modal-btns">
  91. <button @click="showPasswordModal = false">取消</button>
  92. <button class="btn-primary" @click="savePassword">确定</button>
  93. </view>
  94. </view>
  95. </view>
  96. </view>
  97. </template>
  98. <script>
  99. import { setPassword, verifyPassword, updateMemberVisibility, getVisibleFamilyMembers, vendorStatus } from '../../../utils/api.js'
  100. export default {
  101. name: 'ProfileMenu',
  102. props: {
  103. role: {
  104. type: String,
  105. default: 'parent'
  106. }
  107. },
  108. data() {
  109. return {
  110. hasPassword: false,
  111. showPasswordModal: false,
  112. oldPassword: '',
  113. newPassword: '',
  114. confirmPassword: '',
  115. showToFamily: 1,
  116. isVendor: false
  117. }
  118. },
  119. onShow() {
  120. if (!uni.getStorageSync('token')) return
  121. this.hasPassword = !!uni.getStorageSync('passwordSet')
  122. this.loadShowToFamily()
  123. this.checkVendorStatus()
  124. },
  125. methods: {
  126. async loadShowToFamily() {
  127. try {
  128. const uid = this.$store.state.userId || uni.getStorageSync('userId')
  129. const res = await getVisibleFamilyMembers()
  130. const members = res.data || []
  131. const self = members.find(m => m.id == uid)
  132. if (self) {
  133. this.showToFamily = self.showToFamily !== 0 ? 1 : 0
  134. }
  135. } catch (e) {}
  136. },
  137. goToOnboarding() {
  138. uni.navigateTo({ url: '/pages/profile/onboarding' })
  139. },
  140. goToDailyTasks() {
  141. uni.navigateTo({ url: '/pages/tasks/daily-tasks' })
  142. },
  143. goToPointsLogs() {
  144. uni.navigateTo({ url: '/pages/points/points' })
  145. },
  146. async onShowToFamilyChange(e) {
  147. const val = e.detail.value ? 1 : 0
  148. const uid = this.$store.state.userId || uni.getStorageSync('userId')
  149. try {
  150. await updateMemberVisibility(uid, 'parent', val)
  151. this.showToFamily = val
  152. uni.showToast({ title: val ? '已对家庭成员可见' : '已对家庭成员隐藏', icon: 'none' })
  153. } catch (e) {
  154. uni.showToast({ title: '操作失败', icon: 'none' })
  155. }
  156. },
  157. goToMembership() {
  158. uni.navigateTo({ url: '/pages/membership/index' })
  159. },
  160. goToVendorCenter() {
  161. uni.navigateTo({ url: '/pages/vendor/center' })
  162. },
  163. goToOrders() {
  164. uni.navigateTo({ url: '/pages/shop/order-list/order-list' })
  165. },
  166. goToConsigneeList() {
  167. uni.navigateTo({ url: '/pages/shop/consignee-list/consignee-list' })
  168. },
  169. goToAfterSales() {
  170. uni.navigateTo({ url: '/pages/shop/after-sales/after-sales' })
  171. },
  172. goToPromotion() {
  173. uni.navigateTo({ url: '/pages/promotion/index' })
  174. },
  175. goToCoupons() {
  176. uni.navigateTo({ url: '/pages/profile/coupons' })
  177. },
  178. showInviteActionSheet() {
  179. const familyId = uni.getStorageSync('familyId')
  180. const userInfo = uni.getStorageSync('userInfo')
  181. if (!familyId) {
  182. uni.showToast({ title: '您暂未加入家庭', icon: 'none' })
  183. return
  184. }
  185. const items = ['👨‍👩‍👧‍👦 邀请家人', '👨‍🏫 邀请成长规划师']
  186. const types = ['family', 'guide']
  187. uni.showActionSheet({
  188. itemList: items,
  189. success: (res) => {
  190. this.inviteGenerate(types[res.tapIndex], familyId, userInfo)
  191. }
  192. })
  193. },
  194. inviteGenerate(type, familyId, userInfo) {
  195. const inviteTypes = {
  196. family: {
  197. title: (userInfo && userInfo.nickname ? userInfo.nickname : '家人') + ' 邀请你加入家庭',
  198. path: '/pages/login/login?invite_type=family'
  199. },
  200. guide: {
  201. title: (userInfo && userInfo.nickname ? userInfo.nickname : '家长') + ' 邀请你成为家庭成长规划师',
  202. path: '/pages/login/login?invite_type=guide'
  203. }
  204. }
  205. const config = inviteTypes[type] || inviteTypes.family
  206. this.$emit('invite-generate', {
  207. title: config.title,
  208. path: config.path + '&invite_code=',
  209. imageUrl: '/static/invite-card.png'
  210. })
  211. uni.showToast({ title: '点击右上角转发给TA', icon: 'none' })
  212. },
  213. async savePassword() {
  214. if (this.newPassword.length !== 6) {
  215. uni.showToast({ title: '请输入6位密码', icon: 'none' })
  216. return
  217. }
  218. if (this.newPassword !== this.confirmPassword) {
  219. uni.showToast({ title: '两次密码不一致', icon: 'none' })
  220. return
  221. }
  222. if (this.hasPassword && this.oldPassword.length !== 6) {
  223. uni.showToast({ title: '请输入旧密码', icon: 'none' })
  224. return
  225. }
  226. try {
  227. if (this.hasPassword) {
  228. const verifyRes = await verifyPassword(this.oldPassword)
  229. if (verifyRes.code !== 200) {
  230. uni.showToast({ title: '旧密码错误', icon: 'none' })
  231. return
  232. }
  233. }
  234. await setPassword(this.newPassword)
  235. uni.setStorageSync('passwordSet', true)
  236. this.hasPassword = true
  237. uni.showToast({ title: '密码设置成功', icon: 'success' })
  238. this.showPasswordModal = false
  239. this.oldPassword = ''
  240. this.newPassword = ''
  241. this.confirmPassword = ''
  242. } catch (e) {
  243. console.error('设置密码失败', e)
  244. }
  245. },
  246. logout() {
  247. uni.showModal({
  248. title: '确认退出',
  249. content: '确定要退出登录吗?',
  250. success: (res) => {
  251. if (res.confirm) {
  252. this.$store.commit('logout')
  253. uni.reLaunch({ url: '/pages/index/index' })
  254. }
  255. }
  256. })
  257. },
  258. async checkVendorStatus() {
  259. try {
  260. const res = await vendorStatus()
  261. this.isVendor = res.data && res.data.vendorStatus === 'approved'
  262. } catch (e) {
  263. this.isVendor = false
  264. }
  265. }
  266. }
  267. }
  268. </script>
  269. <style scoped>
  270. .menu-list {
  271. margin: 30rpx;
  272. }
  273. .menu-group {
  274. background: #fff;
  275. border-radius: 20rpx;
  276. margin-bottom: 20rpx;
  277. overflow: hidden;
  278. }
  279. .menu-group-title {
  280. padding: 20rpx 30rpx 10rpx;
  281. font-size: 22rpx;
  282. color: #999;
  283. text-align: center;
  284. }
  285. .menu-item {
  286. display: flex;
  287. align-items: center;
  288. justify-content: space-between;
  289. padding: 28rpx 30rpx;
  290. border-bottom: 1rpx solid #f5f5f5;
  291. font-size: 28rpx;
  292. color: #333;
  293. }
  294. .menu-item:last-child {
  295. border-bottom: none;
  296. }
  297. .arrow {
  298. color: #ccc;
  299. font-size: 28rpx;
  300. }
  301. .menu-item-switch {
  302. justify-content: space-between;
  303. }
  304. .menu-item-switch text {
  305. flex: 1;
  306. }
  307. .modal-mask {
  308. position: fixed;
  309. top: 0;
  310. left: 0;
  311. right: 0;
  312. bottom: 0;
  313. background: rgba(0,0,0,0.5);
  314. display: flex;
  315. align-items: center;
  316. justify-content: center;
  317. z-index: 999;
  318. }
  319. .modal {
  320. background: #fff;
  321. border-radius: 20rpx;
  322. padding: 40rpx;
  323. width: 80%;
  324. }
  325. .modal-title {
  326. font-size: 32rpx;
  327. font-weight: bold;
  328. text-align: center;
  329. margin-bottom: 30rpx;
  330. }
  331. .form-item {
  332. margin-bottom: 20rpx;
  333. }
  334. .form-item input {
  335. border: 1rpx solid #ddd;
  336. border-radius: 12rpx;
  337. padding: 20rpx;
  338. font-size: 28rpx;
  339. }
  340. .modal-btns {
  341. display: flex;
  342. gap: 20rpx;
  343. margin-top: 30rpx;
  344. }
  345. .modal-btns button {
  346. flex: 1;
  347. font-size: 28rpx;
  348. padding: 20rpx;
  349. border-radius: 12rpx;
  350. }
  351. .modal-btns .btn-primary {
  352. background: #667eea;
  353. color: #fff;
  354. }
  355. </style>