ProfileMenu.vue 13 KB

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