ProfileMenu.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445
  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="goToMessageHistory">
  8. <text>📨 消息历史</text>
  9. <text class="arrow">›</text>
  10. </view>
  11. <view class="menu-item" v-if="role === 'parent'" @click="goToFamilyMembers">
  12. <text>👨‍👩‍👧‍👦 家庭成员</text>
  13. <text class="arrow">›</text>
  14. </view>
  15. <view class="menu-item" v-if="role === 'parent'" @click="goToAppointments">
  16. <text>📅 测评预约</text>
  17. <text class="arrow">›</text>
  18. </view>
  19. <view class="menu-item" @click="goToDailyTasks">
  20. <text>📋 每日任务</text>
  21. <text class="arrow">›</text>
  22. </view>
  23. <view class="menu-item" v-if="role === 'parent'" @click="goToOnboarding">
  24. <text>🎯 新手任务</text>
  25. <text class="arrow">›</text>
  26. </view>
  27. <view class="menu-item" @click="goToReportManagement">
  28. <text>📋 报告管理</text>
  29. <text class="arrow">›</text>
  30. </view>
  31. <view class="menu-item" v-if="role === 'parent'" @click="goToServiceRoleApply">
  32. <text>📋 服务角色申请</text>
  33. <text class="arrow">›</text>
  34. </view>
  35. </view>
  36. <!-- ===== 服务 ===== -->
  37. <view class="menu-group" v-if="showServices">
  38. <view class="menu-group-title">── 服务 ──</view>
  39. <view class="menu-item" @click="goToShop">
  40. <text>🛍️ 商城</text>
  41. <text class="arrow">›</text>
  42. </view>
  43. <view class="menu-item" @click="goToCart">
  44. <text>🛒 购物车</text>
  45. <text class="arrow">›</text>
  46. </view>
  47. <view class="menu-item" @click="goToMembership">
  48. <text>👑 会员中心</text>
  49. <text class="arrow">›</text>
  50. </view>
  51. <view class="menu-item" v-if="isVendor" @click="goToVendorCenter">
  52. <text>🏪 服务商中心</text>
  53. <text class="arrow">›</text>
  54. </view>
  55. <view class="menu-item" @click="goToOrders">
  56. <text>🛒 订单管理</text>
  57. <text class="arrow">›</text>
  58. </view>
  59. <view class="menu-item" @click="goToConsigneeList">
  60. <text>📍 收货人管理</text>
  61. <text class="arrow">›</text>
  62. </view>
  63. <view class="menu-item" @click="goToAfterSales">
  64. <text>🔄 售后记录</text>
  65. <text class="arrow">›</text>
  66. </view>
  67. </view>
  68. <!-- ===== 设置 ===== -->
  69. <view class="menu-group">
  70. <view class="menu-group-title">── 设置 ──</view>
  71. <view class="menu-item" v-if="role === 'parent'" @click="showPasswordModal = true">
  72. <text>🔐 {{ hasPassword ? '重置密码' : '设置密码' }}</text>
  73. <text class="arrow">›</text>
  74. </view>
  75. <view class="menu-item menu-item-switch" v-if="role === 'parent'">
  76. <text>👁 对家庭成员可见</text>
  77. <switch :checked="showToFamily === 1" @change="onShowToFamilyChange" color="#5B9BD5" />
  78. </view>
  79. <view class="menu-item" @click="goToShare">
  80. <text>📤 分享推广码</text>
  81. <text class="arrow">›</text>
  82. </view>
  83. <view class="menu-item" @click="showInviteActionSheet">
  84. <text>📨 邀请加入</text>
  85. <text class="arrow">›</text>
  86. </view>
  87. <view class="menu-item" @click="logout">
  88. <text>🚪 退出登录</text>
  89. <text class="arrow">›</text>
  90. </view>
  91. </view>
  92. </view>
  93. <!-- 设置/重置密码弹窗 -->
  94. <view class="modal-mask" v-if="showPasswordModal" @click="showPasswordModal = false">
  95. <view class="modal" @click.stop>
  96. <view class="modal-title">{{ hasPassword ? '重置密码' : '设置密码' }}</view>
  97. <view class="form-item" v-if="hasPassword">
  98. <input v-model="oldPassword" type="number" password placeholder="输入旧密码" maxlength="6" />
  99. </view>
  100. <view class="form-item">
  101. <input v-model="newPassword" type="number" password placeholder="输入新密码" maxlength="6" />
  102. </view>
  103. <view class="form-item">
  104. <input v-model="confirmPassword" type="number" password placeholder="确认新密码" maxlength="6" />
  105. </view>
  106. <view class="modal-btns">
  107. <button @click="showPasswordModal = false">取消</button>
  108. <button class="btn-primary" @click="savePassword">确定</button>
  109. </view>
  110. </view>
  111. </view>
  112. </view>
  113. </template>
  114. <script>
  115. import { setPassword, verifyPassword, updateMemberVisibility, getFamilyMemberList, vendorStatus, ensureFamily, getReferralCode, extractReferralCode } from '@/utils/api.js'
  116. export default {
  117. name: 'ProfileMenu',
  118. props: {
  119. role: {
  120. type: String,
  121. default: 'parent'
  122. },
  123. showServices: {
  124. type: Boolean,
  125. default: true
  126. }
  127. },
  128. data() {
  129. return {
  130. hasPassword: false,
  131. showPasswordModal: false,
  132. oldPassword: '',
  133. newPassword: '',
  134. confirmPassword: '',
  135. showToFamily: 1,
  136. isVendor: false,
  137. referralCode: '',
  138. referralCodeLoaded: false
  139. }
  140. },
  141. onShow() {
  142. if (!uni.getStorageSync('token')) return
  143. this.hasPassword = !!uni.getStorageSync('passwordSet')
  144. this.loadShowToFamily()
  145. this.checkVendorStatus()
  146. this.loadReferralCode()
  147. },
  148. methods: {
  149. /** 获取自己的邀请码用于分享 */
  150. async loadReferralCode() {
  151. if (this.referralCodeLoaded || !uni.getStorageSync('token')) return
  152. try {
  153. var res = await getReferralCode()
  154. this.referralCode = extractReferralCode(res)
  155. } catch (e) {}
  156. this.referralCodeLoaded = true
  157. },
  158. async loadShowToFamily() {
  159. try {
  160. const uid = this.$store.state.userId || uni.getStorageSync('userId')
  161. const res = await getFamilyMemberList({ visibleOnly: true })
  162. const members = res.data || []
  163. const self = members.find(m => m.id == uid)
  164. if (self) {
  165. this.showToFamily = self.showToFamily !== 0 ? 1 : 0
  166. }
  167. } catch (e) {}
  168. },
  169. goToOnboarding() {
  170. uni.navigateTo({ url: '/pages/profile-extra/onboarding' })
  171. },
  172. goToReportManagement() {
  173. uni.navigateTo({ url: '/pages/profile/report-management' })
  174. },
  175. goToServiceRoleApply() {
  176. uni.navigateTo({ url: '/pages/profile/service-role-apply' })
  177. },
  178. goToFamilyMembers() {
  179. uni.navigateTo({ url: '/pages/profile-extra/family-members' })
  180. },
  181. goToAppointments() {
  182. uni.navigateTo({ url: '/pages/parent/appointments' })
  183. },
  184. goToDailyTasks() {
  185. uni.navigateTo({ url: '/pages/tasks/daily-tasks' })
  186. },
  187. goToMessageHistory() {
  188. uni.navigateTo({ url: '/pages/profile/message-history' })
  189. },
  190. async onShowToFamilyChange(e) {
  191. const val = e.detail.value ? 1 : 0
  192. const uid = this.$store.state.userId || uni.getStorageSync('userId')
  193. try {
  194. await updateMemberVisibility(uid, 'parent', val)
  195. this.showToFamily = val
  196. uni.showToast({ title: val ? '已对家庭成员可见' : '已对家庭成员隐藏', icon: 'none' })
  197. } catch (e) {
  198. uni.showToast({ title: '操作失败', icon: 'none' })
  199. }
  200. },
  201. goToShop() {
  202. uni.navigateTo({ url: '/pages/shop/index/index' })
  203. },
  204. goToCart() {
  205. uni.navigateTo({ url: '/pages/shop/cart/cart' })
  206. },
  207. goToMembership() {
  208. uni.navigateTo({ url: '/pages/membership/index' })
  209. },
  210. goToVendorCenter() {
  211. uni.navigateTo({ url: '/pages/vendor/center' })
  212. },
  213. goToOrders() {
  214. uni.navigateTo({ url: '/pages/shop/order-list/order-list' })
  215. },
  216. goToConsigneeList() {
  217. uni.navigateTo({ url: '/pages/shop/consignee-list/consignee-list' })
  218. },
  219. goToAfterSales() {
  220. uni.navigateTo({ url: '/pages/shop/after-sales/after-sales' })
  221. },
  222. goToShare() {
  223. uni.navigateTo({ url: '/pages/profile/share' })
  224. },
  225. showInviteActionSheet() {
  226. var self = this
  227. var ui = uni.getStorageSync('userInfo') || {}
  228. if (!ui.familyId) {
  229. ensureFamily().then(function(result) {
  230. if (result && result.created) {
  231. self.showInviteActionSheet()
  232. }
  233. })
  234. return
  235. }
  236. const userInfo = ui
  237. const items = ['👨‍👩‍👧‍👦 邀请家人', '👨‍🏫 邀请成长规划师']
  238. const types = ['family', 'guide']
  239. uni.showActionSheet({
  240. itemList: items,
  241. success: (res) => {
  242. self.inviteGenerate(types[res.tapIndex], userInfo)
  243. }
  244. })
  245. },
  246. inviteGenerate(type, userInfo) {
  247. const inviteTypes = {
  248. family: {
  249. title: (userInfo && userInfo.nickname ? userInfo.nickname : '家人') + ' 邀请你加入家庭',
  250. path: '/pages/login/login?invite_type=family'
  251. },
  252. guide: {
  253. title: (userInfo && userInfo.nickname ? userInfo.nickname : '家长') + ' 邀请你成为家庭成长规划师',
  254. path: '/pages/login/login?invite_type=guide'
  255. }
  256. }
  257. const config = inviteTypes[type] || inviteTypes.family
  258. var path = config.path
  259. if (this.referralCode) {
  260. path = path + '&refCode=' + this.referralCode
  261. }
  262. this.$emit('invite-generate', {
  263. title: config.title,
  264. path: path,
  265. imageUrl: '/static/invite-card.png'
  266. })
  267. uni.showToast({ title: '点击右上角转发给TA', icon: 'none' })
  268. },
  269. async savePassword() {
  270. if (this.newPassword.length !== 6) {
  271. uni.showToast({ title: '请输入6位密码', icon: 'none' })
  272. return
  273. }
  274. if (this.newPassword !== this.confirmPassword) {
  275. uni.showToast({ title: '两次密码不一致', icon: 'none' })
  276. return
  277. }
  278. if (this.hasPassword && this.oldPassword.length !== 6) {
  279. uni.showToast({ title: '请输入旧密码', icon: 'none' })
  280. return
  281. }
  282. try {
  283. if (this.hasPassword) {
  284. const verifyRes = await verifyPassword(this.oldPassword)
  285. if (verifyRes.code !== 200) {
  286. uni.showToast({ title: '旧密码错误', icon: 'none' })
  287. return
  288. }
  289. }
  290. await setPassword(this.newPassword)
  291. uni.setStorageSync('passwordSet', true)
  292. this.hasPassword = true
  293. uni.showToast({ title: '密码设置成功', icon: 'success' })
  294. this.showPasswordModal = false
  295. this.oldPassword = ''
  296. this.newPassword = ''
  297. this.confirmPassword = ''
  298. } catch (e) {
  299. console.error('设置密码失败', e)
  300. }
  301. },
  302. logout() {
  303. uni.showModal({
  304. title: '确认退出',
  305. content: '确定要退出登录吗?',
  306. success: (res) => {
  307. if (res.confirm) {
  308. this.$store.commit('logout')
  309. uni.reLaunch({ url: '/pages/index-home/index' })
  310. }
  311. }
  312. })
  313. },
  314. async checkVendorStatus() {
  315. try {
  316. const res = await vendorStatus()
  317. this.isVendor = res.data && res.data.vendorStatus === 'approved'
  318. } catch (e) {
  319. this.isVendor = false
  320. }
  321. },
  322. }
  323. }
  324. </script>
  325. <style scoped>
  326. .menu-list {
  327. margin: 30rpx;
  328. }
  329. .menu-group {
  330. background: #fff;
  331. border-radius: 20rpx;
  332. margin-bottom: 20rpx;
  333. overflow: hidden;
  334. }
  335. .menu-group-title {
  336. padding: 20rpx 30rpx 10rpx;
  337. font-size: 22rpx;
  338. color: #999;
  339. text-align: center;
  340. }
  341. .menu-item {
  342. display: flex;
  343. align-items: center;
  344. justify-content: space-between;
  345. padding: 28rpx 30rpx;
  346. border-bottom: 1rpx solid #f5f5f5;
  347. font-size: 28rpx;
  348. color: #333;
  349. }
  350. .menu-item:last-child {
  351. border-bottom: none;
  352. }
  353. .arrow {
  354. color: #ccc;
  355. font-size: 28rpx;
  356. }
  357. .menu-item-switch {
  358. justify-content: space-between;
  359. }
  360. .menu-item-switch text {
  361. flex: 1;
  362. }
  363. .modal-mask {
  364. position: fixed;
  365. top: 0;
  366. left: 0;
  367. right: 0;
  368. bottom: 0;
  369. background: rgba(0,0,0,0.5);
  370. display: flex;
  371. align-items: center;
  372. justify-content: center;
  373. z-index: 999;
  374. }
  375. .modal {
  376. background: #fff;
  377. border-radius: 20rpx;
  378. padding: 40rpx;
  379. width: 80%;
  380. }
  381. .modal-title {
  382. font-size: 32rpx;
  383. font-weight: bold;
  384. text-align: center;
  385. margin-bottom: 30rpx;
  386. }
  387. .form-item {
  388. margin-bottom: 20rpx;
  389. }
  390. .form-item input {
  391. border: 1rpx solid #ddd;
  392. border-radius: 12rpx;
  393. padding: 20rpx;
  394. font-size: 28rpx;
  395. }
  396. .modal-btns {
  397. display: flex;
  398. gap: 20rpx;
  399. margin-top: 30rpx;
  400. }
  401. .modal-btns button {
  402. flex: 1;
  403. font-size: 28rpx;
  404. padding: 20rpx;
  405. border-radius: 12rpx;
  406. }
  407. .modal-btns .btn-primary {
  408. background: #667eea;
  409. color: #fff;
  410. }
  411. .intent-reselect-hint {
  412. margin: 0 30rpx 30rpx;
  413. padding: 24rpx 30rpx;
  414. background: #fff;
  415. border-radius: 20rpx;
  416. display: flex;
  417. align-items: center;
  418. font-size: 26rpx;
  419. }
  420. .intent-reselect-label {
  421. color: #999;
  422. margin-right: 8rpx;
  423. }
  424. .intent-reselect-value {
  425. flex: 1;
  426. color: #F97316;
  427. font-weight: bold;
  428. }
  429. .intent-reselect-link {
  430. color: #5B9BD5;
  431. text-decoration: underline;
  432. }
  433. </style>