ProfileMenu.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352
  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">
  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. },
  100. data() {
  101. return {
  102. hasPassword: false,
  103. showPasswordModal: false,
  104. oldPassword: '',
  105. newPassword: '',
  106. confirmPassword: '',
  107. showToFamily: 1,
  108. isVendor: false
  109. }
  110. },
  111. onShow() {
  112. if (!uni.getStorageSync('token')) return
  113. this.hasPassword = !!uni.getStorageSync('passwordSet')
  114. this.loadShowToFamily()
  115. this.checkVendorStatus()
  116. },
  117. methods: {
  118. async loadShowToFamily() {
  119. try {
  120. const uid = this.$store.state.userId || uni.getStorageSync('userId')
  121. const res = await getVisibleFamilyMembers()
  122. const members = res.data || []
  123. const self = members.find(m => m.id == uid)
  124. if (self) {
  125. this.showToFamily = self.showToFamily !== 0 ? 1 : 0
  126. }
  127. } catch (e) {}
  128. },
  129. goToOnboarding() {
  130. uni.navigateTo({ url: '/pages/profile/onboarding' })
  131. },
  132. goToFamilyMembers() {
  133. uni.navigateTo({ url: '/pages/profile/family-members' })
  134. },
  135. goToAppointments() {
  136. uni.navigateTo({ url: '/pages/parent/appointments' })
  137. },
  138. goToDailyTasks() {
  139. uni.navigateTo({ url: '/pages/tasks/daily-tasks' })
  140. },
  141. async onShowToFamilyChange(e) {
  142. const val = e.detail.value ? 1 : 0
  143. const uid = this.$store.state.userId || uni.getStorageSync('userId')
  144. try {
  145. await updateMemberVisibility(uid, 'parent', val)
  146. this.showToFamily = val
  147. uni.showToast({ title: val ? '已对家庭成员可见' : '已对家庭成员隐藏', icon: 'none' })
  148. } catch (e) {
  149. uni.showToast({ title: '操作失败', icon: 'none' })
  150. }
  151. },
  152. goToMembership() {
  153. uni.navigateTo({ url: '/pages/membership/index' })
  154. },
  155. goToVendorCenter() {
  156. uni.navigateTo({ url: '/pages/vendor/center' })
  157. },
  158. goToOrders() {
  159. uni.navigateTo({ url: '/pages/shop/order-list/order-list' })
  160. },
  161. goToConsigneeList() {
  162. uni.navigateTo({ url: '/pages/shop/consignee-list/consignee-list' })
  163. },
  164. goToAfterSales() {
  165. uni.navigateTo({ url: '/pages/shop/after-sales/after-sales' })
  166. },
  167. showInviteActionSheet() {
  168. const familyId = uni.getStorageSync('familyId')
  169. const userInfo = uni.getStorageSync('userInfo')
  170. if (!familyId) {
  171. uni.showToast({ title: '您暂未加入家庭', icon: 'none' })
  172. return
  173. }
  174. const items = ['👨‍👩‍👧‍👦 邀请家人', '👨‍🏫 邀请成长规划师']
  175. const types = ['family', 'guide']
  176. uni.showActionSheet({
  177. itemList: items,
  178. success: (res) => {
  179. this.inviteGenerate(types[res.tapIndex], familyId, userInfo)
  180. }
  181. })
  182. },
  183. inviteGenerate(type, familyId, userInfo) {
  184. const inviteTypes = {
  185. family: {
  186. title: (userInfo && userInfo.nickname ? userInfo.nickname : '家人') + ' 邀请你加入家庭',
  187. path: '/pages/login/login?invite_type=family'
  188. },
  189. guide: {
  190. title: (userInfo && userInfo.nickname ? userInfo.nickname : '家长') + ' 邀请你成为家庭成长规划师',
  191. path: '/pages/login/login?invite_type=guide'
  192. }
  193. }
  194. const config = inviteTypes[type] || inviteTypes.family
  195. this.$emit('invite-generate', {
  196. title: config.title,
  197. path: config.path + '&invite_code=',
  198. imageUrl: '/static/invite-card.png'
  199. })
  200. uni.showToast({ title: '点击右上角转发给TA', icon: 'none' })
  201. },
  202. async savePassword() {
  203. if (this.newPassword.length !== 6) {
  204. uni.showToast({ title: '请输入6位密码', icon: 'none' })
  205. return
  206. }
  207. if (this.newPassword !== this.confirmPassword) {
  208. uni.showToast({ title: '两次密码不一致', icon: 'none' })
  209. return
  210. }
  211. if (this.hasPassword && this.oldPassword.length !== 6) {
  212. uni.showToast({ title: '请输入旧密码', icon: 'none' })
  213. return
  214. }
  215. try {
  216. if (this.hasPassword) {
  217. const verifyRes = await verifyPassword(this.oldPassword)
  218. if (verifyRes.code !== 200) {
  219. uni.showToast({ title: '旧密码错误', icon: 'none' })
  220. return
  221. }
  222. }
  223. await setPassword(this.newPassword)
  224. uni.setStorageSync('passwordSet', true)
  225. this.hasPassword = true
  226. uni.showToast({ title: '密码设置成功', icon: 'success' })
  227. this.showPasswordModal = false
  228. this.oldPassword = ''
  229. this.newPassword = ''
  230. this.confirmPassword = ''
  231. } catch (e) {
  232. console.error('设置密码失败', e)
  233. }
  234. },
  235. logout() {
  236. uni.showModal({
  237. title: '确认退出',
  238. content: '确定要退出登录吗?',
  239. success: (res) => {
  240. if (res.confirm) {
  241. this.$store.commit('logout')
  242. uni.reLaunch({ url: '/pages/index/index' })
  243. }
  244. }
  245. })
  246. },
  247. async checkVendorStatus() {
  248. try {
  249. const res = await vendorStatus()
  250. this.isVendor = res.data && res.data.vendorStatus === 'approved'
  251. } catch (e) {
  252. this.isVendor = false
  253. }
  254. }
  255. }
  256. }
  257. </script>
  258. <style scoped>
  259. .menu-list {
  260. margin: 30rpx;
  261. }
  262. .menu-group {
  263. background: #fff;
  264. border-radius: 20rpx;
  265. margin-bottom: 20rpx;
  266. overflow: hidden;
  267. }
  268. .menu-group-title {
  269. padding: 20rpx 30rpx 10rpx;
  270. font-size: 22rpx;
  271. color: #999;
  272. text-align: center;
  273. }
  274. .menu-item {
  275. display: flex;
  276. align-items: center;
  277. justify-content: space-between;
  278. padding: 28rpx 30rpx;
  279. border-bottom: 1rpx solid #f5f5f5;
  280. font-size: 28rpx;
  281. color: #333;
  282. }
  283. .menu-item:last-child {
  284. border-bottom: none;
  285. }
  286. .arrow {
  287. color: #ccc;
  288. font-size: 28rpx;
  289. }
  290. .menu-item-switch {
  291. justify-content: space-between;
  292. }
  293. .menu-item-switch text {
  294. flex: 1;
  295. }
  296. .modal-mask {
  297. position: fixed;
  298. top: 0;
  299. left: 0;
  300. right: 0;
  301. bottom: 0;
  302. background: rgba(0,0,0,0.5);
  303. display: flex;
  304. align-items: center;
  305. justify-content: center;
  306. z-index: 999;
  307. }
  308. .modal {
  309. background: #fff;
  310. border-radius: 20rpx;
  311. padding: 40rpx;
  312. width: 80%;
  313. }
  314. .modal-title {
  315. font-size: 32rpx;
  316. font-weight: bold;
  317. text-align: center;
  318. margin-bottom: 30rpx;
  319. }
  320. .form-item {
  321. margin-bottom: 20rpx;
  322. }
  323. .form-item input {
  324. border: 1rpx solid #ddd;
  325. border-radius: 12rpx;
  326. padding: 20rpx;
  327. font-size: 28rpx;
  328. }
  329. .modal-btns {
  330. display: flex;
  331. gap: 20rpx;
  332. margin-top: 30rpx;
  333. }
  334. .modal-btns button {
  335. flex: 1;
  336. font-size: 28rpx;
  337. padding: 20rpx;
  338. border-radius: 12rpx;
  339. }
  340. .modal-btns .btn-primary {
  341. background: #667eea;
  342. color: #fff;
  343. }
  344. </style>