index.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464
  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="content-area">
  13. <!-- 筛选行: Tabs + 日期选择器 -->
  14. <view class="filter-area">
  15. <!-- Tabs -->
  16. <view class="tabs-row">
  17. <view class="tab-item" :class="{ active: currentTab === 0 }" @click="switchTab(0)">
  18. <text>全部</text>
  19. <view class="tab-line" v-if="currentTab === 0"></view>
  20. </view>
  21. <view class="tab-item" :class="{ active: currentTab === 1 }" @click="switchTab(1)">
  22. <text>收入</text>
  23. <view class="tab-line" v-if="currentTab === 1"></view>
  24. </view>
  25. <view class="tab-item" :class="{ active: currentTab === 2 }" @click="switchTab(2)">
  26. <text>支出</text>
  27. <view class="tab-line" v-if="currentTab === 2"></view>
  28. </view>
  29. </view>
  30. <!-- 日期选择器 -->
  31. <view class="date-picker-wrap">
  32. <picker mode="date" fields="month" :value="currentDate" @change="onDateChange">
  33. <view class="date-picker">
  34. <text class="date-text">{{ year }}年{{ `${month}`.padStart(2, '0') }}月</text>
  35. <text class="arrow-down">﹀</text>
  36. </view>
  37. </picker>
  38. </view>
  39. </view>
  40. <!-- 账单列表 -->
  41. <scroll-view scroll-y class="bill-list">
  42. <view v-for="(group, gIndex) in displayGroups" :key="gIndex" class="month-group">
  43. <!-- 月份头 -->
  44. <view class="group-header">
  45. <text class="month-title">{{ group.month }}</text>
  46. <text class="month-summary">收入 ¥{{ group.income }} 支出 ¥{{ group.expense }}</text>
  47. </view>
  48. <!-- 列表项 -->
  49. <view class="list-item" v-for="(item, index) in group.items" :key="index">
  50. <!-- 图标 -->
  51. <view class="item-icon-box" :class="item.type">
  52. <text class="item-icon-symbol">{{ item.type === 'income' ? '+' : '-' }}</text>
  53. </view>
  54. <!-- 中间内容 -->
  55. <view class="item-center">
  56. <text class="item-title">{{ item.title }}</text>
  57. <text class="item-desc">{{ item.time }} {{ item.desc }}</text>
  58. </view>
  59. <!-- 右侧数据 -->
  60. <view class="item-right">
  61. <text class="item-amount" :class="{ income: item.type === 'income', expense: item.type === 'expense' }">
  62. {{ item.type === 'income' ? '+' : '' }}{{ item.amount }}
  63. </text>
  64. <view class="item-tag">
  65. <text>{{ item.tag }}</text>
  66. </view>
  67. </view>
  68. </view>
  69. </view>
  70. <view class="list-padding-bottom"></view>
  71. </scroll-view>
  72. </view>
  73. </view>
  74. </template>
  75. <script>
  76. import { listBalanceOnApp } from '@/api/fulfiller/log';
  77. import fulfillerEnum from '@/enums/fulfiller.json';
  78. const bizTypeMap = fulfillerEnum.FlfBalanceBizType;
  79. export default {
  80. data() {
  81. const d = new Date();
  82. return {
  83. currentTab: 0,
  84. year: d.getFullYear(),
  85. month: d.getMonth() + 1,
  86. groups: []
  87. }
  88. },
  89. computed: {
  90. currentDate() {
  91. return `${this.year}-${String(this.month).padStart(2, '0')}`;
  92. },
  93. displayGroups() {
  94. if (this.currentTab === 0) return this.groups;
  95. return this.groups.map(group => {
  96. const filteredItems = group.items.filter(item => {
  97. const type = this.currentTab === 1 ? 'income' : 'expense';
  98. return item.type === type;
  99. });
  100. return {
  101. ...group,
  102. items: filteredItems
  103. };
  104. }).filter(group => group.items.length > 0);
  105. }
  106. },
  107. onShow() {
  108. this.fetchData();
  109. },
  110. methods: {
  111. async fetchData() {
  112. try {
  113. const res = await listBalanceOnApp({
  114. year: this.year,
  115. month: this.month
  116. });
  117. if (res.code === 200) {
  118. const list = res.data || [];
  119. let incomeTotal = 0;
  120. let expenseTotal = 0;
  121. const items = list.map(item => {
  122. const isAdd = item.type === 'add';
  123. const uiType = isAdd ? 'income' : 'expense';
  124. const title = bizTypeMap[item.bizType] || item.bizType || '其他';
  125. let amountVal = Math.abs(item.amount) / 100;
  126. if (isAdd) {
  127. incomeTotal += amountVal;
  128. } else {
  129. expenseTotal += amountVal;
  130. }
  131. let amountStr = amountVal.toFixed(2);
  132. if (!isAdd) amountStr = '-' + amountStr;
  133. // 取时间 HH:mm
  134. let timeStr = item.createTime || '';
  135. if (timeStr.length >= 16) {
  136. timeStr = timeStr.substring(5, 16);
  137. }
  138. return {
  139. ...item,
  140. title: title,
  141. desc: item.reason || '',
  142. time: timeStr,
  143. amount: amountStr,
  144. type: uiType,
  145. tag: title
  146. };
  147. });
  148. this.groups = [
  149. {
  150. month: `${this.month}月 ${this.year}`,
  151. income: incomeTotal.toFixed(2),
  152. expense: expenseTotal.toFixed(2),
  153. items: items
  154. }
  155. ];
  156. }
  157. } catch (error) {
  158. console.error('获取账单记录失败', error);
  159. uni.showToast({ title: error.message || error.msg || '请求失败', icon: 'none' });
  160. }
  161. },
  162. onDateChange(e) {
  163. const val = e.detail.value; // "YYYY-MM"
  164. const [y, m] = val.split('-');
  165. this.year = parseInt(y, 10);
  166. this.month = parseInt(m, 10);
  167. this.fetchData();
  168. },
  169. navBack() {
  170. uni.navigateBack();
  171. },
  172. switchTab(index) {
  173. this.currentTab = index;
  174. }
  175. }
  176. }
  177. </script>
  178. <style>
  179. /* 基础容器 */
  180. .container {
  181. background-color: #F5F7FA;
  182. min-height: 100vh;
  183. display: flex;
  184. flex-direction: column;
  185. }
  186. /* 导航栏 */
  187. .nav-bar {
  188. background-color: #fff;
  189. padding-top: var(--status-bar-height);
  190. padding-left: 30rpx;
  191. padding-right: 30rpx;
  192. height: 88rpx;
  193. box-sizing: content-box;
  194. display: flex;
  195. justify-content: space-between;
  196. align-items: center;
  197. position: sticky;
  198. top: 0;
  199. z-index: 100;
  200. }
  201. .nav-left {
  202. height: 100%;
  203. display: flex;
  204. align-items: center;
  205. width: 60rpx;
  206. }
  207. .back-icon {
  208. width: 40rpx;
  209. height: 40rpx;
  210. transform: rotate(180deg);
  211. }
  212. .nav-title {
  213. font-size: 28rpx; /* 14pt (Strictly enforced) */
  214. font-weight: bold;
  215. color: #333;
  216. }
  217. .nav-right {
  218. width: 60rpx;
  219. }
  220. /* 内容区域 */
  221. .content-area {
  222. flex: 1;
  223. display: flex;
  224. flex-direction: column;
  225. }
  226. /* 筛选区域 */
  227. .filter-area {
  228. background-color: #fff;
  229. display: flex;
  230. justify-content: space-between;
  231. align-items: center;
  232. padding: 0 30rpx;
  233. margin-bottom: 20rpx;
  234. }
  235. /* Tabs */
  236. .tabs-row {
  237. display: flex;
  238. padding-top: 20rpx;
  239. padding-bottom: 2rpx;
  240. gap: 40rpx;
  241. }
  242. .tab-item {
  243. padding-bottom: 16rpx;
  244. font-size: 28rpx;
  245. color: #666;
  246. position: relative;
  247. display: flex;
  248. flex-direction: column;
  249. align-items: center;
  250. min-width: 100rpx;
  251. }
  252. .tab-item.active {
  253. font-weight: bold;
  254. color: #FF6B00; /* Orange text for active */
  255. }
  256. .tab-line {
  257. width: 40rpx; /* Little wider line */
  258. height: 4rpx;
  259. background-color: #FF6B00;
  260. border-radius: 4rpx;
  261. position: absolute;
  262. bottom: 0;
  263. }
  264. /* 日期选择器 */
  265. .date-picker-wrap {
  266. display: flex;
  267. align-items: center;
  268. }
  269. .date-picker {
  270. background-color: #F5F7FA;
  271. padding: 8rpx 20rpx;
  272. border-radius: 30rpx;
  273. display: flex;
  274. align-items: center;
  275. }
  276. .date-text {
  277. font-size: 26rpx;
  278. color: #333;
  279. margin-right: 8rpx;
  280. }
  281. .arrow-down {
  282. font-size: 24rpx;
  283. color: #999;
  284. }
  285. /* 列表容器 */
  286. .bill-list {
  287. flex: 1;
  288. padding: 0 20rpx;
  289. box-sizing: border-box;
  290. }
  291. /* 月份卡片 */
  292. .month-group {
  293. background-color: #fff;
  294. border-radius: 16rpx;
  295. padding: 0 20rpx;
  296. margin-bottom: 20rpx;
  297. box-shadow: 0 2rpx 6rpx rgba(0,0,0,0.02);
  298. }
  299. .group-header {
  300. display: flex;
  301. justify-content: space-between;
  302. align-items: center;
  303. padding: 24rpx 10rpx;
  304. /* No border bottom for header in card view usually, or light one */
  305. border-bottom: 1rpx solid #f9f9f9;
  306. }
  307. .month-title {
  308. font-size: 30rpx;
  309. font-weight: bold;
  310. color: #333;
  311. }
  312. .month-summary {
  313. font-size: 24rpx;
  314. color: #999;
  315. }
  316. /* 列表项 */
  317. .list-item {
  318. display: flex;
  319. align-items: center;
  320. padding: 30rpx 10rpx;
  321. border-bottom: 1rpx solid #f9f9f9;
  322. }
  323. .list-item:last-child {
  324. border-bottom: none;
  325. }
  326. /* 左侧图标 */
  327. .item-icon-box {
  328. width: 80rpx;
  329. height: 80rpx;
  330. border-radius: 50%;
  331. display: flex;
  332. justify-content: center;
  333. align-items: center;
  334. margin-right: 20rpx;
  335. flex-shrink: 0;
  336. }
  337. .item-icon-box.income {
  338. background-color: #EEF9F2; /* Light Green */
  339. }
  340. .item-icon-box.expense {
  341. background-color: #FFF0F0; /* Light Red */
  342. }
  343. .item-icon-symbol {
  344. font-size: 40rpx;
  345. font-weight: 300;
  346. line-height: 1;
  347. margin-top: -4rpx; /* Visual center adjustment */
  348. }
  349. .item-icon-box.income .item-icon-symbol {
  350. color: #4CAF50;
  351. }
  352. .item-icon-box.expense .item-icon-symbol {
  353. color: #FF4D4F;
  354. }
  355. /* 中间内容 */
  356. .item-center {
  357. flex: 1;
  358. display: flex;
  359. flex-direction: column;
  360. justify-content: space-around;
  361. height: 80rpx;
  362. }
  363. .item-title {
  364. font-size: 28rpx;
  365. font-weight: 500;
  366. color: #333;
  367. }
  368. .item-desc {
  369. font-size: 22rpx;
  370. color: #999;
  371. margin-top: 8rpx;
  372. }
  373. /* 右侧数据 */
  374. .item-right {
  375. display: flex;
  376. flex-direction: column;
  377. align-items: flex-end;
  378. justify-content: space-around;
  379. height: 80rpx;
  380. margin-left: 10rpx;
  381. }
  382. .item-amount {
  383. font-size: 30rpx;
  384. font-weight: bold;
  385. }
  386. .item-amount.income {
  387. color: #4CAF50;
  388. }
  389. .item-amount.expense {
  390. color: #333;
  391. }
  392. .item-tag {
  393. display: inline-flex;
  394. justify-content: flex-end;
  395. margin-top: 6rpx;
  396. }
  397. .item-tag text {
  398. background-color: #FFFFFF;
  399. border: 1rpx solid #eee;
  400. padding: 2rpx 8rpx;
  401. border-radius: 6rpx;
  402. font-size: 20rpx;
  403. color: #999;
  404. }
  405. .list-padding-bottom {
  406. height: 40rpx;
  407. }
  408. </style>