index.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602
  1. <template>
  2. <Theme>
  3. <view class="wrap">
  4. <view class="cont">
  5. <Navbar bgColor="transparent" fixed height="0px" leftShow />
  6. <view class="cont_bg">
  7. <view class="bg_top">
  8. <view class="top_left">
  9. <image
  10. :src="userInfo.userimg"
  11. mode="widthFix"
  12. class="userInfo_avatar"
  13. >
  14. </image>
  15. <view class="userInfo_" v-if="token">
  16. <view class="user_name"> {{ userInfo.username }}</view>
  17. <view class="user_id">
  18. <trans _t="ID" />: {{ userInfo.newid }}
  19. </view>
  20. </view>
  21. <view class="login_btn" v-else @click="toLogin">
  22. <trans _t="点击登录" />
  23. </view>
  24. </view>
  25. <view class="bg_right" @click="onEdit" v-if="token">
  26. <image src="../../static/user/edit.png" class="img"></image>
  27. </view>
  28. </view>
  29. <view class="bg_logo">买家中心</view>
  30. </view>
  31. <!-- 订单状态 -->
  32. <view class="order_status" v-if="token">
  33. <view class="order_title">
  34. <trans _t="我的订单" />
  35. <view class="more_btn" @click="toOrderList">
  36. <trans _t="查看全部" />
  37. <i class="icon-font icon-arrow-right"></i>
  38. </view>
  39. </view>
  40. <view class="order_items">
  41. <view
  42. class="order_item"
  43. v-for="(item, index) in orderStatusList"
  44. :key="index"
  45. @click="toOrderList(item.status)"
  46. >
  47. <view class="order_icon">
  48. <image :src="item.icon" class="icon" />
  49. <view class="badge" v-if="item.count > 0">{{
  50. item.count
  51. }}</view>
  52. </view>
  53. <text class="order_text">{{ t(item.text) }}</text>
  54. </view>
  55. </view>
  56. </view>
  57. <!-- 功能菜单 -->
  58. <view class="menu_section">
  59. <view class="menu_title">
  60. <trans _t="我的服务" />
  61. </view>
  62. <view class="menu_list">
  63. <view
  64. class="menu_item"
  65. v-for="(item, index) in menuList"
  66. :key="index"
  67. @click="handleMenuClick(item)"
  68. >
  69. <view class="menu_icon">
  70. <image :src="item.icon" class="icon" />
  71. <view class="badge" v-if="item.badge">{{ item.badge }}</view>
  72. </view>
  73. <text class="menu_text">{{ t(item.text) }}</text>
  74. <i class="icon-font icon-arrow-right menu_arrow"></i>
  75. </view>
  76. </view>
  77. </view>
  78. <!-- 其他功能 -->
  79. <view class="other_section">
  80. <view class="menu_title">
  81. <trans _t="其他功能" />
  82. </view>
  83. <view class="menu_list">
  84. <view
  85. class="menu_item"
  86. v-for="(item, index) in otherMenuList"
  87. :key="index"
  88. @click="handleMenuClick(item)"
  89. >
  90. <view class="menu_icon">
  91. <image :src="item.icon" class="icon" />
  92. </view>
  93. <text class="menu_text">{{ t(item.text) }}</text>
  94. <i class="icon-font icon-arrow-right menu_arrow"></i>
  95. </view>
  96. </view>
  97. </view>
  98. </view>
  99. <view class="footer" v-if="token">
  100. <view class="switch_user_type" @click="switchUserType">
  101. <trans _t="切换到卖家模式" />
  102. </view>
  103. <view class="exit_btn" @click="exit">
  104. <trans _t="退出登录" />
  105. </view>
  106. <view class="version">v {{ manifest.versionName }}</view>
  107. </view>
  108. </view>
  109. <Tabbar page="profile" />
  110. </Theme>
  111. </template>
  112. <script setup>
  113. import Tabbar from "@/components/tabbar";
  114. import Navbar from "@/components/navbar";
  115. import { computed, watch, ref, reactive, onMounted, nextTick } from "vue";
  116. import { storeToRefs } from "pinia";
  117. import {
  118. useUserStore,
  119. useTabbarStore,
  120. useShopStore,
  121. useSystemStore,
  122. useMessageStore,
  123. } from "@/store";
  124. import { t } from "@/locale";
  125. import { onShow, onLoad } from "@dcloudio/uni-app";
  126. import manifest from "@/manifest.json";
  127. import { Modal, Toast } from "@/utils";
  128. const useUser = useUserStore();
  129. const useTabbar = useTabbarStore();
  130. const useSystem = useSystemStore();
  131. const useShop = useShopStore();
  132. const useMessage = useMessageStore();
  133. const { globalMap } = storeToRefs(useMessage);
  134. const unreadCount = ref(0);
  135. watch(
  136. () => globalMap.value.serviceChannel,
  137. (newVal, oldVal) => {
  138. if (newVal) {
  139. unreadCount.value = newVal.unreadCount;
  140. }
  141. },
  142. {
  143. deep: true,
  144. immediate: true,
  145. }
  146. );
  147. const userInfo = computed(() => useUser.getuserInfo);
  148. const token = computed(() => useUser.getToken);
  149. // 订单状态列表
  150. const orderStatusList = ref([
  151. {
  152. icon: "/static/user/payment.png",
  153. text: "待支付",
  154. status: "waitPay",
  155. count: 0,
  156. },
  157. {
  158. icon: "/static/user/shipping.png",
  159. text: "待发货",
  160. status: "waitShipping",
  161. count: 0,
  162. },
  163. {
  164. icon: "/static/user/receive.png",
  165. text: "待收货",
  166. status: "waitReceive",
  167. count: 0,
  168. },
  169. {
  170. icon: "/static/user/comment.png",
  171. text: "待评价",
  172. status: "waitComment",
  173. count: 0,
  174. },
  175. {
  176. icon: "/static/user/refund.png",
  177. text: "退款/售后",
  178. status: "refund",
  179. count: 0,
  180. },
  181. ]);
  182. // 功能菜单列表
  183. const menuList = ref([
  184. {
  185. icon: "/static/user/wallet.png",
  186. text: "我的钱包",
  187. url: "/pagesBuyer/profile/wallet",
  188. },
  189. {
  190. icon: "/static/user/coupon.png",
  191. text: "优惠券",
  192. url: "/pagesBuyer/profile/coupon",
  193. badge: "3",
  194. },
  195. {
  196. icon: "/static/user/favorite.png",
  197. text: "我的收藏",
  198. url: "/pagesBuyer/profile/favorite",
  199. },
  200. {
  201. icon: "/static/user/footprint.png",
  202. text: "浏览历史",
  203. url: "/pagesBuyer/profile/footprint",
  204. },
  205. {
  206. icon: "/static/user/address.png",
  207. text: "收货地址",
  208. url: "/pagesBuyer/profile/address",
  209. },
  210. {
  211. icon: "/static/user/invite.png",
  212. text: "邀请好友",
  213. url: "/pagesBuyer/profile/invite",
  214. },
  215. ]);
  216. // 其他功能菜单
  217. const otherMenuList = ref([
  218. {
  219. icon: "/static/user/setting.png",
  220. text: "设置",
  221. url: "/pagesBuyer/profile/setting",
  222. },
  223. {
  224. icon: "/static/user/help.png",
  225. text: "帮助中心",
  226. url: "/pagesBuyer/profile/help",
  227. },
  228. {
  229. icon: "/static/user/feedback.png",
  230. text: "意见反馈",
  231. url: "/pagesBuyer/profile/feedback",
  232. },
  233. {
  234. icon: "/static/user/about.png",
  235. text: "关于我们",
  236. url: "/pagesBuyer/profile/about",
  237. },
  238. ]);
  239. // 退出登录
  240. const exit = () => {
  241. Modal({ content: t("确定要退出登录吗") }).then(async () => {
  242. useUser.loginOut();
  243. });
  244. };
  245. // 去登录
  246. const toLogin = () => {
  247. uni.navigateTo({
  248. url: "/pages/login/login",
  249. });
  250. };
  251. // 编辑用户信息
  252. const onEdit = () => {
  253. uni.navigateTo({ url: "/pagesBuyer/profile/edit" });
  254. };
  255. // 查看订单列表
  256. const toOrderList = (status) => {
  257. uni.navigateTo({
  258. url: `/pagesBuyer/profile/orders?status=${status || ""}`,
  259. });
  260. };
  261. // 处理菜单点击
  262. const handleMenuClick = (item) => {
  263. if (!item.url) {
  264. Toast(t("功能开发中"));
  265. return;
  266. }
  267. if (item.url === "service") {
  268. useSystem.service();
  269. return;
  270. }
  271. uni.navigateTo({ url: item.url });
  272. };
  273. // 获取订单数量
  274. const getOrderCount = async () => {
  275. if (!token.value) return;
  276. try {
  277. // 这里应该调用实际的API获取订单数量
  278. // const res = await USER_ORDER_COUNT();
  279. // orderStatusList.value[0].count = res.data.waitPay || 0;
  280. // orderStatusList.value[1].count = res.data.waitShipping || 0;
  281. // orderStatusList.value[2].count = res.data.waitReceive || 0;
  282. // orderStatusList.value[3].count = res.data.waitComment || 0;
  283. // orderStatusList.value[4].count = res.data.refund || 0;
  284. } catch (error) {
  285. Toast(error.msg);
  286. }
  287. };
  288. // 切换用户类型
  289. const switchUserType = () => {
  290. Modal({
  291. content: t("确定要切换到卖家模式吗?切换后底部导航将显示卖家功能"),
  292. }).then(() => {
  293. // 设置为卖家类型
  294. useUser.setUserType(1);
  295. // 跳转到卖家首页
  296. uni.reLaunch({
  297. url: "/pages/index/index",
  298. });
  299. });
  300. };
  301. onMounted(() => {
  302. getOrderCount();
  303. });
  304. onLoad(() => {
  305. // useUser.getUserInfo();
  306. });
  307. onShow(() => {
  308. if (token.value) {
  309. useUser.getUserInfo({}, { isLoading: true });
  310. getOrderCount();
  311. }
  312. });
  313. uni.hideTabBar();
  314. </script>
  315. <style lang="less" scoped>
  316. @import url("@/style.less");
  317. .wrap {
  318. background: var(--bg);
  319. min-height: 100vh;
  320. padding-bottom: calc(90rpx + constant(safe-area-inset-bottom));
  321. padding-bottom: calc(90rpx + env(safe-area-inset-bottom));
  322. .flex();
  323. flex-direction: column;
  324. justify-content: space-between;
  325. .cont {
  326. padding-bottom: 24rpx;
  327. flex-grow: 1;
  328. &_bg {
  329. background: var(--black);
  330. border-radius: 0 0 20rpx 20rpx;
  331. position: relative;
  332. .bg_top {
  333. .flex_position(space-between);
  334. padding: 40rpx 40rpx 140rpx;
  335. position: relative;
  336. z-index: 1;
  337. .top_left {
  338. .flex();
  339. .userInfo_avatar {
  340. width: 120rpx;
  341. height: 120rpx;
  342. border-radius: 50%;
  343. }
  344. .login_btn {
  345. .flex_center();
  346. background-color: var(--primary);
  347. border: 2px solid var(--bg-primary);
  348. border-radius: 30rpx;
  349. color: var(--light);
  350. padding: 8rpx 30rpx;
  351. .size(28rpx);
  352. font-weight: 700;
  353. margin-left: 24rpx;
  354. }
  355. .userInfo_ {
  356. .hor();
  357. flex-direction: column;
  358. margin-left: 24rpx;
  359. color: var(--light);
  360. .user_name {
  361. .size();
  362. font-weight: 700;
  363. line-height: 44rpx;
  364. }
  365. .user_id {
  366. .size(24rpx);
  367. line-height: 40rpx;
  368. }
  369. }
  370. }
  371. .bg_right {
  372. .img {
  373. width: 40rpx;
  374. height: 40rpx;
  375. }
  376. }
  377. }
  378. .bg_logo {
  379. position: absolute;
  380. .size(128rpx);
  381. color: var(--inputBg);
  382. opacity: 0.06;
  383. top: 0;
  384. left: 50%;
  385. font-weight: bold;
  386. transform: translateX(-50%);
  387. line-height: 128rpx;
  388. text-transform: uppercase;
  389. font-family: "HarmonyOS_Sans";
  390. white-space: nowrap;
  391. }
  392. }
  393. .order_status {
  394. margin: -70rpx 24rpx 32rpx;
  395. position: relative;
  396. z-index: 2;
  397. background: var(--light);
  398. border-radius: 20rpx;
  399. padding: 32rpx 24rpx;
  400. .order_title {
  401. display: flex;
  402. justify-content: space-between;
  403. align-items: center;
  404. font-size: 32rpx;
  405. font-weight: bold;
  406. color: var(--black);
  407. margin-bottom: 24rpx;
  408. .more_btn {
  409. display: flex;
  410. align-items: center;
  411. font-size: 24rpx;
  412. color: var(--text-01);
  413. .icon-arrow-right {
  414. margin-left: 8rpx;
  415. font-size: 20rpx;
  416. }
  417. }
  418. }
  419. .order_items {
  420. display: flex;
  421. justify-content: space-around;
  422. .order_item {
  423. display: flex;
  424. flex-direction: column;
  425. align-items: center;
  426. .order_icon {
  427. position: relative;
  428. margin-bottom: 12rpx;
  429. .icon {
  430. width: 48rpx;
  431. height: 48rpx;
  432. }
  433. .badge {
  434. position: absolute;
  435. top: -8rpx;
  436. right: -8rpx;
  437. background: var(--danger);
  438. color: var(--light);
  439. font-size: 20rpx;
  440. padding: 4rpx 8rpx;
  441. border-radius: 20rpx;
  442. min-width: 32rpx;
  443. text-align: center;
  444. line-height: 1;
  445. }
  446. }
  447. .order_text {
  448. font-size: 24rpx;
  449. color: var(--text);
  450. }
  451. }
  452. }
  453. }
  454. .menu_section,
  455. .other_section {
  456. margin: 0 24rpx 32rpx;
  457. .menu_title {
  458. font-size: 32rpx;
  459. font-weight: bold;
  460. color: var(--black);
  461. margin-bottom: 24rpx;
  462. }
  463. .menu_list {
  464. background: var(--light);
  465. border-radius: 20rpx;
  466. overflow: hidden;
  467. .menu_item {
  468. display: flex;
  469. align-items: center;
  470. padding: 32rpx 24rpx;
  471. border-bottom: 1rpx solid var(--border-color);
  472. &:last-child {
  473. border-bottom: none;
  474. }
  475. .menu_icon {
  476. position: relative;
  477. margin-right: 24rpx;
  478. .icon {
  479. width: 40rpx;
  480. height: 40rpx;
  481. }
  482. .badge {
  483. position: absolute;
  484. top: -8rpx;
  485. right: -8rpx;
  486. background: var(--danger);
  487. color: var(--light);
  488. font-size: 20rpx;
  489. padding: 4rpx 8rpx;
  490. border-radius: 20rpx;
  491. min-width: 32rpx;
  492. text-align: center;
  493. line-height: 1;
  494. }
  495. }
  496. .menu_text {
  497. flex: 1;
  498. font-size: 28rpx;
  499. color: var(--black);
  500. }
  501. .menu_arrow {
  502. font-size: 24rpx;
  503. color: var(--text-01);
  504. }
  505. }
  506. }
  507. }
  508. }
  509. .footer {
  510. padding: 0 24rpx;
  511. .switch_user_type {
  512. background-color: var(--primary);
  513. color: var(--light);
  514. .size(28rpx);
  515. height: 84rpx;
  516. padding: 16rpx 30rpx;
  517. .flex_center();
  518. border-radius: 16rpx;
  519. margin-bottom: 16rpx;
  520. }
  521. .exit_btn {
  522. background-color: var(--black);
  523. color: var(--light);
  524. .size(28rpx);
  525. height: 84rpx;
  526. padding: 16rpx 30rpx;
  527. .flex_center();
  528. border-radius: 16rpx;
  529. margin-bottom: 24rpx;
  530. }
  531. .version {
  532. text-align: center;
  533. color: var(--black);
  534. .size(24rpx);
  535. padding: 24rpx 0;
  536. }
  537. }
  538. }
  539. </style>