records.vue 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380
  1. <template>
  2. <view class="page">
  3. <u-navbar title="账户明细" :autoBack="true" :placeholder="true"></u-navbar>
  4. <!-- Tabs -->
  5. <view class="tabs">
  6. <view
  7. class="tab"
  8. v-for="(tab, idx) in tabs"
  9. :key="idx"
  10. :class="{ active: currentTab === idx }"
  11. @click="switchTab(idx)"
  12. >
  13. <text class="tab-text">{{ tab }}</text>
  14. <image v-if="currentTab === idx" class="tab-indicator" :src="tabIndicator" mode="aspectFit"></image>
  15. </view>
  16. </view>
  17. <!-- 内容卡片:月份 + 列表 -->
  18. <view class="content-card">
  19. <view class="filter-bar">
  20. <picker mode="date" :value="monthValue" fields="month" @change="onMonthChange">
  21. <view class="month">
  22. <text>{{ monthLabel }}</text>
  23. <u-icon name="arrow-down" color="#666" size="12"></u-icon>
  24. </view>
  25. </picker>
  26. <view class="summary">
  27. <template v-if="currentTab === 0">
  28. <text>充值¥{{ formatMoney(summary.recharge) }}</text>
  29. <text class="sep">|</text>
  30. <text>支出¥{{ formatMoney(summary.spend) }}</text>
  31. </template>
  32. <template v-else-if="currentTab === 1">
  33. <text>支出¥{{ formatMoney(summary.spend) }}</text>
  34. </template>
  35. <template v-else>
  36. <text>实付¥{{ formatMoney(summary.paid) }}</text>
  37. <text class="sep">|</text>
  38. <text>赠送¥{{ formatMoney(summary.gift) }}</text>
  39. </template>
  40. </view>
  41. </view>
  42. <view class="list-wrap">
  43. <ListScrollView
  44. ref="listScroll"
  45. :api="api"
  46. :init="initParams"
  47. :pageSize="10"
  48. @afterFetch="afterFetch"
  49. >
  50. <template v-slot:list="{ data }">
  51. <view class="list">
  52. <view class="item" v-for="item in data" :key="item.id" @click="goDetail(item)">
  53. <image class="left-icon" :src="getTypeIcon(item.type)" mode="aspectFit"></image>
  54. <view class="info">
  55. <view class="row1">
  56. <text class="name">{{ item.title }}</text>
  57. <text class="amount" :class="{ plus: item.amount > 0 }">
  58. {{ item.amount > 0 ? '+' : '' }}{{ formatMoney(item.amount) }}
  59. </text>
  60. </view>
  61. <view class="row2">
  62. <text class="store">{{ item.storeName }}</text>
  63. <text class="time">{{ formatListTime(item.time) }}</text>
  64. </view>
  65. </view>
  66. </view>
  67. </view>
  68. </template>
  69. </ListScrollView>
  70. </view>
  71. </view>
  72. </view>
  73. </template>
  74. <script>
  75. import { getMerchantId } from '@/api/memberPrepaid.js'
  76. import ListScrollView from '@/components/list-scroll-view/index.vue'
  77. const TAB_TYPES = ['ALL', 'CONSUME', 'RECHARGE']
  78. const BASE = '/memberPrepaidMerchant'
  79. export default {
  80. components: {
  81. ListScrollView
  82. },
  83. data() {
  84. const now = new Date();
  85. const y = now.getFullYear();
  86. const m = now.getMonth() + 1;
  87. return {
  88. tabs: ['全部', '支出', '充值'],
  89. currentTab: 0,
  90. year: y,
  91. month: m,
  92. tabIndicator: '/static/topUp/tabs.png',
  93. iconRecharge: '/static/topUp/recharge.png',
  94. iconSpend: '/static/topUp/expenditure.png',
  95. iconGive: '/static/topUp/give.png',
  96. summary: {
  97. recharge: 0,
  98. spend: 0,
  99. paid: 0,
  100. gift: 0
  101. },
  102. api: {
  103. url: `${BASE}/account/ledger/page`,
  104. method: 'GET'
  105. }
  106. };
  107. },
  108. computed: {
  109. monthLabel() {
  110. return `${this.year}年${this.month}月`;
  111. },
  112. monthValue() {
  113. return `${this.year}-${String(this.month).padStart(2, '0')}`;
  114. },
  115. initParams() {
  116. return {
  117. merchantId: getMerchantId(),
  118. month: this.monthValue,
  119. transactionType: TAB_TYPES[this.currentTab]
  120. };
  121. }
  122. },
  123. methods: {
  124. formatMoney(val) {
  125. const n = Number(val) || 0;
  126. return n.toFixed(2);
  127. },
  128. formatListTime(time) {
  129. const m = String(time).match(/(\d{4})-(\d{1,2})-(\d{1,2})\s+(\d{2}:\d{2}:\d{2})/);
  130. if (!m) return time;
  131. return `${Number(m[2])}月${Number(m[3])}日 ${m[4]}`;
  132. },
  133. getTypeIcon(type) {
  134. if (type === 'spend') return this.iconSpend;
  135. if (type === 'gift') return this.iconGive;
  136. return this.iconRecharge;
  137. },
  138. mapItem(item) {
  139. const txType = String(item.transactionType || '').toUpperCase();
  140. const isRecharge = txType === 'RECHARGE';
  141. const isGift = txType === 'GIFT' || txType === 'GIVE';
  142. const userName = item.userName || '用户';
  143. const changeAmount = Number(item.changeAmount);
  144. let type = 'spend';
  145. let titlePrefix = '支出';
  146. if (isGift) {
  147. type = 'gift';
  148. titlePrefix = '赠送';
  149. } else if (isRecharge) {
  150. type = 'recharge';
  151. titlePrefix = '充值';
  152. }
  153. return {
  154. id: item.ledgerId,
  155. type,
  156. title: `${titlePrefix}-${userName}`,
  157. storeName: item.storeName || '',
  158. amount: Number.isNaN(changeAmount)
  159. ? isRecharge || isGift
  160. ? Number(item.payAmount || 0) + Number(item.giftAmount || 0)
  161. : -Math.abs(Number(item.payAmount || 0))
  162. : changeAmount,
  163. time: item.transactionTime || ''
  164. };
  165. },
  166. afterFetch(result) {
  167. const summary = result.summary || {};
  168. this.summary = {
  169. recharge: Number(summary.rechargeAmount) || 0,
  170. spend: Number(summary.consumeAmount) || 0,
  171. paid: Number(summary.payAmount) || 0,
  172. gift: Number(summary.giftAmount) || 0
  173. };
  174. const records = Array.isArray(result.records)
  175. ? result.records
  176. : (result.page && Array.isArray(result.page.records) ? result.page.records : []);
  177. records.forEach((item) => {
  178. Object.assign(item, this.mapItem(item));
  179. });
  180. },
  181. reload() {
  182. this.$nextTick(() => {
  183. if (this.$refs.listScroll) {
  184. this.$refs.listScroll.reloadList(this.initParams);
  185. }
  186. });
  187. },
  188. switchTab(idx) {
  189. if (this.currentTab === idx) return;
  190. this.currentTab = idx;
  191. this.reload();
  192. },
  193. onMonthChange(e) {
  194. const val = e.detail.value || '';
  195. const parts = val.split('-');
  196. if (parts.length >= 2) {
  197. this.year = Number(parts[0]);
  198. this.month = Number(parts[1]);
  199. this.reload();
  200. }
  201. },
  202. goDetail(item) {
  203. const type = item.type === 'spend' ? 'spend' : 'recharge';
  204. uni.navigateTo({
  205. url: `/pages/topUp/recordDetail?id=${item.id}&type=${type}`
  206. });
  207. }
  208. }
  209. };
  210. </script>
  211. <style scoped lang="scss">
  212. .page {
  213. height: 100vh;
  214. background: #f5f6f8;
  215. display: flex;
  216. flex-direction: column;
  217. box-sizing: border-box;
  218. }
  219. .tabs {
  220. display: flex;
  221. background: #fff;
  222. padding-bottom: 4rpx;
  223. flex-shrink: 0;
  224. .tab {
  225. flex: 1;
  226. display: flex;
  227. align-items: center;
  228. justify-content: center;
  229. height: 88rpx;
  230. position: relative;
  231. .tab-text {
  232. font-size: 30rpx;
  233. color: #999;
  234. line-height: 1.2;
  235. }
  236. .tab-indicator {
  237. position: absolute;
  238. left: 50%;
  239. bottom: 10rpx;
  240. transform: translateX(-50%);
  241. width: 48rpx;
  242. height: 12rpx;
  243. }
  244. &.active {
  245. .tab-text {
  246. color: #2f7bff;
  247. font-weight: 600;
  248. }
  249. }
  250. }
  251. }
  252. .content-card {
  253. flex: 1;
  254. display: flex;
  255. flex-direction: column;
  256. margin: 24rpx;
  257. margin-bottom: calc(24rpx + env(safe-area-inset-bottom));
  258. background: #fff;
  259. border-radius: 20rpx;
  260. overflow: hidden;
  261. min-height: 0;
  262. }
  263. .filter-bar {
  264. display: flex;
  265. align-items: center;
  266. justify-content: space-between;
  267. padding: 28rpx 28rpx 12rpx;
  268. flex-shrink: 0;
  269. .month {
  270. display: flex;
  271. align-items: center;
  272. gap: 8rpx;
  273. font-size: 28rpx;
  274. color: #333;
  275. font-weight: 500;
  276. }
  277. .summary {
  278. display: flex;
  279. align-items: center;
  280. font-size: 24rpx;
  281. color: #999;
  282. .sep {
  283. margin: 0 10rpx;
  284. color: #ccc;
  285. }
  286. }
  287. }
  288. .list-wrap {
  289. flex: 1;
  290. min-height: 0;
  291. }
  292. .list {
  293. padding: 0 28rpx 24rpx;
  294. }
  295. .item {
  296. display: flex;
  297. align-items: center;
  298. padding: 28rpx 0;
  299. .left-icon {
  300. width: 72rpx;
  301. height: 72rpx;
  302. margin-right: 20rpx;
  303. flex-shrink: 0;
  304. border-radius: 50%;
  305. }
  306. .info {
  307. flex: 1;
  308. min-width: 0;
  309. }
  310. .row1,
  311. .row2 {
  312. display: flex;
  313. justify-content: space-between;
  314. align-items: center;
  315. }
  316. .row1 {
  317. margin-bottom: 10rpx;
  318. .name {
  319. font-size: 28rpx;
  320. color: #333;
  321. font-weight: 500;
  322. overflow: hidden;
  323. text-overflow: ellipsis;
  324. white-space: nowrap;
  325. max-width: 360rpx;
  326. }
  327. .amount {
  328. font-size: 30rpx;
  329. font-weight: 600;
  330. color: #2f7bff;
  331. flex-shrink: 0;
  332. &.plus {
  333. color: #2f7bff;
  334. }
  335. }
  336. }
  337. .row2 {
  338. .store,
  339. .time {
  340. font-size: 22rpx;
  341. color: #999;
  342. }
  343. .store {
  344. overflow: hidden;
  345. text-overflow: ellipsis;
  346. white-space: nowrap;
  347. max-width: 360rpx;
  348. }
  349. }
  350. }
  351. </style>