ProfileMenu.vue 10 KB

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