records.vue 8.5 KB

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