ProfileMenu.vue 12 KB

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