index.vue 13 KB

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