index.vue 13 KB

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