ProfileMenu.vue 13 KB

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