index.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505
  1. <template>
  2. <view class="container">
  3. <!-- 导航栏 -->
  4. <view class="nav-bar">
  5. <view class="nav-left" @click="navBack">
  6. <image class="back-icon" src="/static/icons/chevron_right_dark.svg"></image>
  7. </view>
  8. <text class="nav-title">我的钱包</text>
  9. <view class="nav-right"></view>
  10. </view>
  11. <!-- 钱包卡片 -->
  12. <view class="wallet-card">
  13. <!-- 背景装饰圆 -->
  14. <view class="bg-circle big"></view>
  15. <view class="bg-circle small"></view>
  16. <view class="card-content">
  17. <view class="card-top">
  18. <view class="app-info">
  19. <image class="app-logo" src="/static/icons/wallet_white.svg" mode="aspectFit"></image>
  20. <text class="app-name">履约者APP</text>
  21. </view>
  22. <view class="bill-btn" @click="navToBill">
  23. <text>账单</text>
  24. </view>
  25. </view>
  26. <view class="balance-container">
  27. <view class="balance-main">
  28. <text class="balance-label">账户余额 (元)</text>
  29. <text class="balance-num">{{ balance }}</text>
  30. </view>
  31. <view class="balance-pending">
  32. <text class="pending-label">待入账 (元)</text>
  33. <text class="pending-num">{{ pendingBalance }}</text>
  34. </view>
  35. </view>
  36. </view>
  37. </view>
  38. <!-- 最近记录区域 -->
  39. <view class="record-container">
  40. <view class="record-header">
  41. <text class="header-title">最近账户余额变动记录</text>
  42. <view class="header-more" @click="navToBill">
  43. <text>查看全部</text>
  44. <image class="more-icon" src="/static/icons/arrow_right_gray.svg"></image>
  45. </view>
  46. </view>
  47. <!-- Tabs -->
  48. <view class="tabs-row">
  49. <view class="tab-item" :class="{ active: currentTab === 0 }" @click="switchTab(0)">
  50. <text>全部</text>
  51. <view class="tab-line" v-if="currentTab === 0"></view>
  52. </view>
  53. <view class="tab-item" :class="{ active: currentTab === 1 }" @click="switchTab(1)">
  54. <text>收入</text>
  55. <view class="tab-line" v-if="currentTab === 1"></view>
  56. </view>
  57. <view class="tab-item" :class="{ active: currentTab === 2 }" @click="switchTab(2)">
  58. <text>支出</text>
  59. <view class="tab-line" v-if="currentTab === 2"></view>
  60. </view>
  61. </view>
  62. <!-- 列表 -->
  63. <view class="record-list">
  64. <view class="list-item" v-for="(item, index) in displayList" :key="index">
  65. <view class="item-left">
  66. <text class="item-title">{{ item.title }}</text>
  67. <text class="item-desc">{{ item.desc }}</text>
  68. <text class="item-time">{{ item.time }}</text>
  69. </view>
  70. <view class="item-right">
  71. <text class="item-amount" :class="{ income: item.type === 'income', expense: item.type === 'expense' }">
  72. {{ item.type === 'income' ? '+' : '' }}{{ item.amount }}
  73. </text>
  74. <view class="item-tag">
  75. <text>{{ item.tag }}</text>
  76. </view>
  77. </view>
  78. </view>
  79. </view>
  80. </view>
  81. </view>
  82. </template>
  83. <script>
  84. import { getBalanceOnApp, pageBalanceOnApp } from '@/api/fulfiller/log';
  85. import fulfillerEnum from '@/enums/fulfiller.json';
  86. const bizTypeMap = fulfillerEnum.FlfBalanceBizType;
  87. const actionTypeMap = fulfillerEnum.FlfActionType;
  88. export default {
  89. data() {
  90. return {
  91. balance: '0.00',
  92. pendingBalance: '0.00',
  93. currentTab: 0,
  94. list: [],
  95. pageNum: 1,
  96. pageSize: 10,
  97. total: 0,
  98. loading: false
  99. }
  100. },
  101. computed: {
  102. displayList() {
  103. if (this.currentTab === 0) return this.list;
  104. if (this.currentTab === 1) return this.list.filter(item => item.type === 'income');
  105. if (this.currentTab === 2) return this.list.filter(item => item.type === 'expense');
  106. return [];
  107. }
  108. },
  109. onShow() {
  110. this.fetchData();
  111. this.fetchList(true);
  112. },
  113. onReachBottom() {
  114. this.fetchList();
  115. },
  116. methods: {
  117. async fetchData() {
  118. try {
  119. const res = await getBalanceOnApp();
  120. if (res.code === 200 && res.data) {
  121. this.balance = (res.data.balance / 100).toFixed(2);
  122. this.pendingBalance = (res.data.pendingBalance / 100).toFixed(2);
  123. }
  124. } catch (error) {
  125. console.error('获取余额数据失败', error);
  126. }
  127. },
  128. async fetchList(reset = false) {
  129. if (reset) {
  130. this.pageNum = 1;
  131. this.list = [];
  132. this.total = 0;
  133. }
  134. if (this.loading) return;
  135. if (!reset && this.list.length >= this.total && this.total !== 0) return;
  136. this.loading = true;
  137. try {
  138. const res = await pageBalanceOnApp({
  139. pageNum: this.pageNum,
  140. pageSize: this.pageSize
  141. });
  142. if (res.code === 200) {
  143. this.total = res.total || 0;
  144. const rows = res.rows || [];
  145. const mappedRows = rows.map(item => {
  146. // type 枚举:add 增加, reduce 减少
  147. const isAdd = item.type === 'add';
  148. const uiType = isAdd ? 'income' : 'expense';
  149. const title = bizTypeMap[item.bizType] || item.bizType || '其他';
  150. // 金额处理:分转元
  151. let amountStr = (Math.abs(item.amount) / 100).toFixed(2);
  152. if (!isAdd) {
  153. amountStr = '-' + amountStr;
  154. }
  155. return {
  156. ...item,
  157. title: title,
  158. desc: item.reason || '',
  159. time: item.createTime || '',
  160. amount: amountStr,
  161. type: uiType, // 'income' or 'expense' for template class
  162. tag: title
  163. };
  164. });
  165. this.list = this.list.concat(mappedRows);
  166. this.pageNum++;
  167. }
  168. } catch (error) {
  169. console.error('获取列表数据失败', error);
  170. } finally {
  171. this.loading = false;
  172. }
  173. },
  174. navBack() {
  175. uni.navigateBack();
  176. },
  177. navToBill() {
  178. uni.navigateTo({
  179. url: '/pages/mine/wallet/bill'
  180. });
  181. },
  182. switchTab(index) {
  183. this.currentTab = index;
  184. }
  185. }
  186. }
  187. </script>
  188. <style>
  189. /* 基础容器 */
  190. .container {
  191. background-color: #F8F9FA;
  192. min-height: 100vh;
  193. display: flex;
  194. flex-direction: column;
  195. }
  196. /* 导航栏 */
  197. .nav-bar {
  198. background-color: #fff;
  199. padding-top: var(--status-bar-height);
  200. padding-left: 30rpx;
  201. padding-right: 30rpx;
  202. height: 88rpx;
  203. box-sizing: content-box;
  204. display: flex;
  205. justify-content: space-between;
  206. align-items: center;
  207. position: sticky;
  208. top: 0;
  209. z-index: 100;
  210. }
  211. .nav-left {
  212. height: 100%;
  213. display: flex;
  214. align-items: center;
  215. width: 60rpx; /* 增大点击区域 */
  216. }
  217. /* 复用通用图标并旋转 */
  218. .back-icon {
  219. width: 40rpx;
  220. height: 40rpx;
  221. transform: rotate(180deg);
  222. }
  223. /* 导航标题 */
  224. .nav-title {
  225. font-size: 28rpx;
  226. font-weight: bold;
  227. color: #333;
  228. }
  229. .nav-right {
  230. width: 60rpx;
  231. }
  232. /* 钱包卡片 */
  233. .wallet-card {
  234. margin: 20rpx 30rpx 0;
  235. /* 增加高度以优化内部间距 (原220rpx -> 300rpx) */
  236. height: 300rpx;
  237. background: linear-gradient(135deg, #FF6B00 0%, #FF8F00 100%);
  238. border-radius: 20rpx;
  239. position: relative;
  240. overflow: hidden;
  241. color: #fff;
  242. box-shadow: 0 4rpx 16rpx rgba(255, 107, 0, 0.15);
  243. }
  244. .bg-circle {
  245. position: absolute;
  246. border-radius: 50%;
  247. background: rgba(255,255,255,0.08);
  248. }
  249. .bg-circle.big {
  250. width: 400rpx;
  251. height: 400rpx;
  252. right: -100rpx;
  253. bottom: -150rpx;
  254. }
  255. .bg-circle.small {
  256. width: 200rpx;
  257. height: 200rpx;
  258. right: 80rpx;
  259. bottom: 40rpx;
  260. }
  261. .card-content {
  262. position: relative;
  263. z-index: 1;
  264. padding: 30rpx; /* 增加内边距 */
  265. height: 100%;
  266. box-sizing: border-box;
  267. display: flex;
  268. flex-direction: column;
  269. /* justify-content: space-between; */
  270. }
  271. .card-top {
  272. display: flex;
  273. justify-content: space-between;
  274. align-items: center;
  275. }
  276. .app-info {
  277. display: flex;
  278. align-items: center;
  279. }
  280. .app-logo {
  281. width: 28rpx; /* 图标调小 */
  282. height: 28rpx;
  283. background-color: transparent; /* SVG不需要背景色 */
  284. margin-right: 10rpx;
  285. border-radius: 0;
  286. }
  287. .app-name {
  288. font-size: 26rpx; /* 调小:13pt */
  289. font-weight: 500;
  290. }
  291. .bill-btn {
  292. font-size: 26rpx; /* 13pt */
  293. opacity: 0.9;
  294. }
  295. .bill-btn text {
  296. font-size: 26rpx; /* 调小:13pt */
  297. opacity: 0.95;
  298. }
  299. .balance-container {
  300. margin-top: auto; /* Push to bottom */
  301. display: flex;
  302. justify-content: space-between;
  303. align-items: flex-end;
  304. padding-bottom: 10rpx; /* Align with bottom padding visual */
  305. }
  306. .balance-main {
  307. display: flex;
  308. flex-direction: column;
  309. }
  310. .balance-label {
  311. font-size: 24rpx; /* 12pt */
  312. opacity: 0.9;
  313. margin-bottom: 4rpx;
  314. }
  315. .balance-num {
  316. font-size: 48rpx; /* 调整适中,不至于太小也不太大 */
  317. font-weight: bold;
  318. line-height: 1.1;
  319. }
  320. .balance-pending {
  321. display: flex;
  322. flex-direction: column;
  323. align-items: flex-end;
  324. margin-bottom: 10rpx;
  325. }
  326. .pending-label {
  327. font-size: 24rpx; /* 12pt */
  328. opacity: 0.9;
  329. margin-bottom: 4rpx;
  330. }
  331. .pending-num {
  332. font-size: 28rpx; /* 14pt */
  333. font-weight: bold;
  334. }
  335. /* 记录区域 */
  336. .record-container {
  337. flex: 1;
  338. background-color: #fff;
  339. margin: 24rpx 24rpx 0; /* 调整边距 */
  340. border-radius: 20rpx 20rpx 0 0;
  341. padding: 30rpx 24rpx;
  342. }
  343. .record-header {
  344. display: flex;
  345. justify-content: space-between;
  346. align-items: center;
  347. margin-bottom: 24rpx;
  348. }
  349. .header-title {
  350. font-size: 28rpx; /* 14pt */
  351. font-weight: bold;
  352. color: #333;
  353. }
  354. .header-more {
  355. display: flex;
  356. align-items: center;
  357. font-size: 24rpx; /* 12pt */
  358. color: #999;
  359. }
  360. .more-icon {
  361. width: 24rpx;
  362. height: 24rpx;
  363. margin-left: 6rpx;
  364. /* Ensure icon color is visible - svgs are usually static. display:block just in case */
  365. display: block;
  366. }
  367. /* Tabs */
  368. .tabs-row {
  369. display: flex;
  370. border-bottom: 1rpx solid #f5f5f5;
  371. margin-bottom: 10rpx;
  372. }
  373. .tab-item {
  374. margin-right: 40rpx;
  375. padding-bottom: 12rpx;
  376. font-size: 28rpx; /* 14pt */
  377. color: #666;
  378. position: relative;
  379. display: flex;
  380. flex-direction: column;
  381. align-items: center;
  382. }
  383. .tab-item.active {
  384. font-weight: bold;
  385. color: #333;
  386. }
  387. .tab-line {
  388. width: 28rpx;
  389. height: 4rpx;
  390. background-color: #FF6B00;
  391. border-radius: 4rpx;
  392. position: absolute;
  393. bottom: 0;
  394. }
  395. /* 列表 */
  396. .list-item {
  397. display: flex;
  398. justify-content: space-between;
  399. padding: 24rpx 0;
  400. border-bottom: 1rpx solid #f9f9f9;
  401. }
  402. .item-left {
  403. display: flex;
  404. flex-direction: column;
  405. }
  406. .item-title {
  407. font-size: 28rpx; /* 14pt (Green Box) */
  408. color: #333;
  409. margin-bottom: 8rpx;
  410. font-weight: 500;
  411. }
  412. .item-desc {
  413. font-size: 26rpx; /* 13pt (Red Box) */
  414. color: #999;
  415. margin-bottom: 6rpx;
  416. }
  417. .item-time {
  418. font-size: 24rpx; /* 12pt */
  419. color: #ccc;
  420. }
  421. .item-right {
  422. display: flex;
  423. flex-direction: column;
  424. /* align-items: flex-end; 保持右对齐 */
  425. text-align: right;
  426. }
  427. .item-amount {
  428. font-size: 28rpx; /* 14pt */
  429. font-weight: bold;
  430. margin-bottom: 8rpx;
  431. }
  432. .item-amount.income {
  433. color: #4CAF50;
  434. }
  435. .item-amount.expense {
  436. color: #333;
  437. }
  438. .item-tag {
  439. display: inline-flex;
  440. justify-content: flex-end;
  441. }
  442. .item-tag text {
  443. background-color: #F5F5F5;
  444. padding: 4rpx 12rpx;
  445. border-radius: 6rpx;
  446. font-size: 22rpx; /* 11pt */
  447. color: #999;
  448. }
  449. </style>