ProfileMenu.vue 10 KB

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