user.vue 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487
  1. <template>
  2. <view class="container">
  3. <!-- 顶部用户信息卡片(优化版) -->
  4. <view class="user-card">
  5. <image class="avatar" :src="userInfo.avatarUrl || '@/static/login/logo.png'" mode="aspectFill"></image>
  6. <view class="user-info">
  7. <view class="info-top">
  8. <view class="username">{{userInfo.name}}</view>
  9. <view class="phone">{{filterPhone(userInfo.phone)}}</view>
  10. </view>
  11. <!-- 配送时间 - 优化样式 -->
  12. <view class="delivery-time">
  13. <view class="time-item">
  14. <text class="time-text">配送时间 {{userInfo.deliveryStart}}~{{userInfo.deliveryEnd}}</text>
  15. </view>
  16. </view>
  17. </view>
  18. </view>
  19. <!-- 钱包余额卡片 -->
  20. <view class="wallet-card">
  21. <view class="wallet-header">
  22. <text class="title">我的钱包</text>
  23. <text class="subtitle">实时更新</text>
  24. </view>
  25. <view class="balance-container">
  26. <view class="balance-item">
  27. <text class="label">可用余额</text>
  28. <text class="value">¥{{formatMoney(walletBalance)}}</text>
  29. </view>
  30. <view class="balance-item">
  31. <text class="label">待提现</text>
  32. <text class="value">¥{{formatMoney(toBeWithdrawn)}}</text>
  33. </view>
  34. </view>
  35. </view>
  36. <!-- 快捷功能区 -->
  37. <view class="quick-actions">
  38. <view class="action-item" @click="navTo('income')">
  39. <image class="icon" src="@/static/icons/withdraw.png" mode="aspectFit"></image>
  40. <text class="text">收益明细</text>
  41. </view>
  42. <view class="action-item" @click="navTo('withdraw')">
  43. <image class="icon" src="@/static/icons/withdraw.png" mode="aspectFit"></image>
  44. <text class="text">提现</text>
  45. </view>
  46. <view class="action-item" @click="navTo('profile')">
  47. <image class="icon" src="@/static/icons/profile.png" mode="aspectFit"></image>
  48. <text class="text">资料填写</text>
  49. </view>
  50. </view>
  51. <!-- 交易记录列表 -->
  52. <view class="transaction-section">
  53. <view class="section-header">
  54. <text class="title">交易记录</text>
  55. <text class="more" @click="viewAllTransactions">查看全部</text>
  56. </view>
  57. <view class="transaction-list">
  58. <view class="transaction-item" v-for="item in transactions" :key="item.id" @click="viewDetail(item)">
  59. <view class="left">
  60. <view class="type">{{getTypeText(item.transactionType)}}</view>
  61. <view class="time">{{item.createTime}}</view>
  62. </view>
  63. <view class="right" :class="{'income': item.amount > 0, 'expense': item.amount < 0}">
  64. {{item.amount > 0 ? '+' : ''}}{{formatMoney(item.amount)}}
  65. </view>
  66. </view>
  67. <view class="load-more" @click="loadMore" v-if="hasMore">
  68. <text>{{loading ? '加载中...' : '加载更多'}}</text>
  69. <image v-if="!loading" class="arrow" src="" mode="aspectFit"></image>
  70. </view>
  71. </view>
  72. </view>
  73. <!-- 底部操作栏 -->
  74. <view class="bottom-bar">
  75. <button class="logout-btn" @click="onLogout">退出登录</button>
  76. </view>
  77. </view>
  78. </template>
  79. <script>
  80. import {
  81. mapState,
  82. mapMutations
  83. } from 'vuex';
  84. export default {
  85. computed: {
  86. ...mapState(['token', 'userInfo'])
  87. },
  88. data() {
  89. return {
  90. walletBalance: 0,
  91. toBeWithdrawn: 0,
  92. transactions: [],
  93. page: 1,
  94. pageSize: 10,
  95. total: 0,
  96. loading: false,
  97. hasMore: true
  98. };
  99. },
  100. onLoad() {
  101. this.initData();
  102. },
  103. onShow() {
  104. this.refreshData();
  105. },
  106. methods: {
  107. ...mapMutations(['logout']),
  108. initData() {
  109. this.userInfo = uni.getStorageSync("usemall_userInfo") || {};
  110. this.loadMore();
  111. },
  112. refreshData() {
  113. this.page = 1;
  114. this.hasMore = true;
  115. this.getWalletInfo();
  116. this.getTransactions(true);
  117. },
  118. filterPhone(val) {
  119. return val ? val.toString().slice(0, 3) + '****' + val.toString().slice(-4) : '';
  120. },
  121. formatMoney(amount) {
  122. const num = Number(amount || 0);
  123. return num.toFixed(2);
  124. },
  125. navTo(url) {
  126. const pages = {
  127. income: '../income/income',
  128. withdraw: '../wallet/withdraw',
  129. transaction: '../wallet/transaction-list',
  130. profile: '../profile/edit' // 新增
  131. };
  132. uni.navigateTo({
  133. url: pages[url] || url
  134. });
  135. },
  136. viewAllTransactions() {
  137. this.navTo('transaction');
  138. },
  139. onLogout() {
  140. uni.showModal({
  141. title: '提示',
  142. content: '确定要退出登录吗?',
  143. success: (res) => {
  144. if (res.confirm) {
  145. this.logout();
  146. uni.reLaunch({
  147. url: '/pages/login/login'
  148. });
  149. }
  150. }
  151. });
  152. },
  153. getWalletInfo() {
  154. this.request("get", "rider/wallet/info", this.token).then(res => {
  155. if (res.code === 200) {
  156. this.walletBalance = res.data.walletBalance || 0;
  157. this.toBeWithdrawn = res.data.toBeWithdrawn || 0;
  158. }
  159. });
  160. },
  161. getTransactions(refresh = false) {
  162. if (this.loading) return;
  163. this.loading = true;
  164. if (refresh) {
  165. this.page = 1;
  166. }
  167. this.request("get", "rider/wallet/transactions", this.token, {
  168. page: this.page,
  169. size: this.pageSize
  170. }).then(res => {
  171. if (res.code === 200) {
  172. const newData = res.rows || [];
  173. this.transactions = refresh ? newData : [...this.transactions, ...newData];
  174. this.total = res.total || 0;
  175. this.hasMore = this.transactions.length < this.total;
  176. }
  177. }).finally(() => {
  178. this.loading = false;
  179. });
  180. },
  181. loadMore() {
  182. if (this.hasMore && !this.loading) {
  183. this.page++;
  184. this.getTransactions();
  185. }
  186. },
  187. viewDetail(item) {
  188. uni.navigateTo({
  189. url: `/pages/wallet/detail?id=${item.id}`
  190. });
  191. },
  192. getTypeText(type) {
  193. const types = {
  194. 1: '收入',
  195. 2: '支出',
  196. 3: '提现',
  197. 4: '退款'
  198. };
  199. return types[type] || '交易';
  200. }
  201. }
  202. };
  203. </script>
  204. <style lang="scss" scoped>
  205. .container {
  206. padding: 20rpx;
  207. background-color: #f7f7f7;
  208. min-height: 85vh;
  209. padding-bottom: 120rpx;
  210. }
  211. /* 用户信息卡片 - 优化版 */
  212. .user-card {
  213. display: flex;
  214. align-items: center;
  215. padding: 30rpx;
  216. background: linear-gradient(135deg, #437CE8, #437CE8);
  217. border-radius: 16rpx;
  218. margin-bottom: 20rpx;
  219. color: #fff;
  220. box-shadow: 0 4rpx 12rpx rgba(74, 144, 226, 0.3);
  221. .avatar {
  222. width: 120rpx;
  223. height: 120rpx;
  224. border-radius: 50%;
  225. border: 4rpx solid rgba(255, 255, 255, 0.3);
  226. flex-shrink: 0;
  227. }
  228. .user-info {
  229. margin-left: 24rpx;
  230. flex: 1;
  231. display: flex;
  232. flex-direction: column;
  233. .info-top {
  234. margin-bottom: 15rpx;
  235. .username {
  236. font-size: 36rpx;
  237. font-weight: bold;
  238. margin-bottom: 8rpx;
  239. line-height: 1.2;
  240. }
  241. .phone {
  242. font-size: 26rpx;
  243. opacity: 0.9;
  244. }
  245. }
  246. /* 配送时间 - 优化样式 */
  247. .delivery-time {
  248. background: rgba(255, 255, 255, 0.15);
  249. border-radius: 8rpx;
  250. padding: 12rpx 15rpx;
  251. backdrop-filter: blur(5px);
  252. .time-item {
  253. display: flex;
  254. align-items: center;
  255. .time-icon {
  256. width: 28rpx;
  257. height: 28rpx;
  258. margin-right: 10rpx;
  259. filter: brightness(0) invert(1);
  260. }
  261. .time-text {
  262. font-size: 26rpx;
  263. opacity: 0.95;
  264. }
  265. }
  266. }
  267. }
  268. }
  269. /* 钱包卡片 */
  270. .wallet-card {
  271. background-color: #fff;
  272. border-radius: 16rpx;
  273. padding: 30rpx;
  274. margin-bottom: 20rpx;
  275. box-shadow: 0 4rpx 12rpx rgba(0, 0, 0, 0.05);
  276. .wallet-header {
  277. display: flex;
  278. justify-content: space-between;
  279. align-items: center;
  280. margin-bottom: 30rpx;
  281. .title {
  282. font-size: 32rpx;
  283. font-weight: bold;
  284. color: #333;
  285. }
  286. .subtitle {
  287. font-size: 24rpx;
  288. color: #999;
  289. }
  290. }
  291. .balance-container {
  292. display: flex;
  293. justify-content: space-around;
  294. text-align: center;
  295. .balance-item {
  296. .label {
  297. display: block;
  298. font-size: 26rpx;
  299. color: #666;
  300. margin-bottom: 10rpx;
  301. }
  302. .value {
  303. font-size: 36rpx;
  304. font-weight: bold;
  305. color: #ff6b35;
  306. }
  307. }
  308. }
  309. }
  310. /* 快捷功能区 */
  311. .quick-actions {
  312. display: flex;
  313. justify-content: space-around;
  314. background-color: #fff;
  315. border-radius: 16rpx;
  316. padding: 30rpx 0;
  317. margin-bottom: 20rpx;
  318. box-shadow: 0 4rpx 12rpx rgba(0, 0, 0, 0.05);
  319. .action-item {
  320. display: flex;
  321. flex-direction: column;
  322. align-items: center;
  323. .icon {
  324. width: 60rpx;
  325. height: 60rpx;
  326. margin-bottom: 15rpx;
  327. }
  328. .text {
  329. font-size: 28rpx;
  330. color: #333;
  331. }
  332. }
  333. }
  334. /* 交易记录区域 */
  335. .transaction-section {
  336. background-color: #fff;
  337. border-radius: 16rpx;
  338. padding: 20rpx 0;
  339. box-shadow: 0 4rpx 12rpx rgba(0, 0, 0, 0.05);
  340. .section-header {
  341. display: flex;
  342. justify-content: space-between;
  343. align-items: center;
  344. padding: 0 30rpx 20rpx;
  345. border-bottom: 1rpx solid #f0f0f0;
  346. .title {
  347. font-size: 32rpx;
  348. font-weight: bold;
  349. color: #333;
  350. }
  351. .more {
  352. font-size: 26rpx;
  353. color: #437CE8;
  354. }
  355. }
  356. .transaction-list {
  357. .transaction-item {
  358. display: flex;
  359. justify-content: space-between;
  360. align-items: center;
  361. padding: 25rpx 30rpx;
  362. border-bottom: 1rpx solid #f0f0f0;
  363. &:last-child {
  364. border-bottom: none;
  365. }
  366. .left {
  367. .type {
  368. font-size: 30rpx;
  369. color: #333;
  370. margin-bottom: 8rpx;
  371. }
  372. .time {
  373. font-size: 24rpx;
  374. color: #999;
  375. }
  376. }
  377. .right {
  378. font-size: 32rpx;
  379. font-weight: bold;
  380. &.income {
  381. color: #4caf50;
  382. }
  383. &.expense {
  384. color: #f44336;
  385. }
  386. }
  387. }
  388. .load-more {
  389. display: flex;
  390. justify-content: center;
  391. align-items: center;
  392. padding: 25rpx 0;
  393. color: #437CE8;
  394. font-size: 28rpx;
  395. .arrow {
  396. width: 24rpx;
  397. height: 24rpx;
  398. margin-left: 10rpx;
  399. }
  400. }
  401. }
  402. }
  403. /* 底部操作栏 */
  404. .bottom-bar {
  405. position: fixed;
  406. bottom: 0;
  407. left: 0;
  408. right: 0;
  409. padding: 20rpx;
  410. background-color: #fff;
  411. box-shadow: 0 -2rpx 10rpx rgba(0, 0, 0, 0.05);
  412. .logout-btn {
  413. background-color: #f8f8f8;
  414. color: #f44336;
  415. border: none;
  416. height: 80rpx;
  417. line-height: 80rpx;
  418. border-radius: 40rpx;
  419. font-size: 30rpx;
  420. &::after {
  421. border: none;
  422. }
  423. }
  424. }
  425. </style>