recordDetail.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418
  1. <template>
  2. <view class="page">
  3. <u-navbar :title="pageTitle" :autoBack="true" :placeholder="true"></u-navbar>
  4. <view v-if="loading" class="loading">
  5. <u-loading mode="circle" size="48"></u-loading>
  6. </view>
  7. <template v-else>
  8. <!-- 状态摘要 -->
  9. <view class="hero card">
  10. <view class="amount" :class="{ plus: isRecharge }">
  11. {{ isRecharge ? '+' : '-' }} {{ formatAmount(Math.abs(detail.amount || 0)) }}
  12. </view>
  13. <view class="status">{{ isRecharge ? '充值成功' : '支出成功' }}</view>
  14. </view>
  15. <!-- 交易详情 -->
  16. <view class="card detail-card">
  17. <template v-if="isRecharge">
  18. <view class="row" v-if="detail.payTime">
  19. <text class="label">支付时间</text>
  20. <text class="value">{{ detail.payTime }}</text>
  21. </view>
  22. <view class="row" v-if="detail.payMethod">
  23. <text class="label">支付方式</text>
  24. <text class="value">{{ detail.payMethod }}</text>
  25. </view>
  26. <view class="row" v-if="detail.storeName">
  27. <text class="label">储值商户</text>
  28. <text class="value">{{ detail.storeName }}</text>
  29. </view>
  30. <view class="row" v-if="detail.orderNo">
  31. <text class="label">订单号</text>
  32. <text class="value">{{ detail.orderNo }}</text>
  33. </view>
  34. <view class="row" v-if="detail.userName">
  35. <text class="label">用户名</text>
  36. <text class="value">{{ detail.userName }}</text>
  37. </view>
  38. <view class="row" v-if="detail.userAccount">
  39. <text class="label">用户账户</text>
  40. <text class="value">{{ detail.userAccount }}</text>
  41. </view>
  42. <view class="row" v-if="detail.paidAmount != null && detail.paidAmount !== ''">
  43. <text class="label">实付金额</text>
  44. <text class="value">{{ detail.paidAmount }}元</text>
  45. </view>
  46. </template>
  47. <template v-else>
  48. <view class="row" v-if="detail.orderNo">
  49. <text class="label">订单号</text>
  50. <text class="value">{{ detail.orderNo }}</text>
  51. </view>
  52. <view class="row" v-if="detail.storeName">
  53. <text class="label">消费门店</text>
  54. <text class="value">{{ detail.storeName }}</text>
  55. </view>
  56. <view class="row" v-if="detail.amount != null">
  57. <text class="label">消费金额</text>
  58. <text class="value">{{ formatAmount(Math.abs(detail.amount)) }}元</text>
  59. </view>
  60. <view class="row" v-if="detail.spendTime">
  61. <text class="label">消费时间</text>
  62. <text class="value">{{ detail.spendTime }}</text>
  63. </view>
  64. <view class="row" v-if="detail.userName">
  65. <text class="label">用户名</text>
  66. <text class="value">{{ detail.userName }}</text>
  67. </view>
  68. <view class="row" v-if="detail.userAccount">
  69. <text class="label">用户账户</text>
  70. <text class="value">{{ detail.userAccount }}</text>
  71. </view>
  72. </template>
  73. </view>
  74. <!-- 赠送信息 -->
  75. <view class="card gift-card" v-if="isRecharge && showGiftSection">
  76. <view class="gift-title">赠送信息</view>
  77. <view class="row" v-if="Number(detail.giftAmount) > 0">
  78. <text class="label">赠送金额</text>
  79. <text class="value">{{ detail.giftAmount }}元</text>
  80. </view>
  81. <view
  82. class="row link"
  83. v-if="couponSummary"
  84. @click="couponExpanded = !couponExpanded"
  85. >
  86. <text class="label">赠送优惠券</text>
  87. <view class="value-wrap">
  88. <text class="value">{{ couponSummary }}</text>
  89. <u-icon
  90. :name="couponExpanded ? 'arrow-up' : 'arrow-down'"
  91. color="#999"
  92. size="14"
  93. ></u-icon>
  94. </view>
  95. </view>
  96. <!-- 优惠券展开列表 -->
  97. <scroll-view
  98. v-if="couponExpanded && coupons.length"
  99. class="coupon-scroll"
  100. scroll-x
  101. :show-scrollbar="false"
  102. >
  103. <view class="coupon-list">
  104. <view class="coupon-item" v-for="(c, idx) in coupons" :key="idx">
  105. <image class="coupon-bg" src="/static/topUp/coupon.png" mode="scaleToFill"></image>
  106. <view class="coupon-body">
  107. <view class="coupon-top">
  108. <text class="c-name">{{ formatCouponName(c.name) }}</text>
  109. <text class="c-value">{{ c.display }}</text>
  110. </view>
  111. <view class="coupon-bottom">
  112. <text class="c-qty">x{{ c.qty }}张</text>
  113. </view>
  114. </view>
  115. </view>
  116. </view>
  117. </scroll-view>
  118. </view>
  119. </template>
  120. </view>
  121. </template>
  122. <script>
  123. import prepaidApi from '@/api/memberPrepaid.js'
  124. export default {
  125. data() {
  126. return {
  127. recordId: '',
  128. recordType: 'recharge',
  129. detail: {},
  130. couponExpanded: false,
  131. loading: false
  132. };
  133. },
  134. computed: {
  135. isRecharge() {
  136. return this.recordType !== 'spend';
  137. },
  138. pageTitle() {
  139. return this.isRecharge ? '充值详情' : '支出详情';
  140. },
  141. coupons() {
  142. return Array.isArray(this.detail.coupons) ? this.detail.coupons : [];
  143. },
  144. couponSummary() {
  145. if (!this.coupons.length) return '';
  146. const totalQty = this.coupons.reduce((s, c) => s + (Number(c.qty) || 0), 0);
  147. if (!totalQty) return '';
  148. const face = this.detail.couponFaceText;
  149. return face ? `${totalQty}张/${face}` : `${totalQty}张优惠券`;
  150. },
  151. showGiftSection() {
  152. return Number(this.detail.giftAmount) > 0 || !!this.couponSummary;
  153. }
  154. },
  155. onLoad(options) {
  156. this.recordId = options.id || '';
  157. this.recordType = options.type === 'spend' ? 'spend' : 'recharge';
  158. this.loadDetail();
  159. },
  160. methods: {
  161. formatAmount(val) {
  162. const n = Number(val) || 0;
  163. return Number.isInteger(n) ? String(n) : n.toFixed(2);
  164. },
  165. formatCouponName(name) {
  166. const s = String(name || '');
  167. return s.length > 6 ? `${s.slice(0, 6)}...` : s;
  168. },
  169. loadDetail() {
  170. if (!this.recordId) {
  171. uni.showToast({ title: '缺少明细ID', icon: 'none' });
  172. return;
  173. }
  174. this.loading = true;
  175. prepaidApi
  176. .getLedgerDetail(this.recordId)
  177. .then((res) => {
  178. if (res.data.code !== 200 || !res.data.result) {
  179. uni.showToast({ title: res.data.message || '加载失败', icon: 'none' });
  180. return;
  181. }
  182. const data = res.data.result;
  183. const isRecharge = data.transactionType === 'RECHARGE';
  184. this.recordType = isRecharge ? 'recharge' : 'spend';
  185. const coupons = (data.coupons || []).map((c) => {
  186. const isDiscount = String(c.couponType) === '2';
  187. return {
  188. name: c.couponName || '',
  189. display: isDiscount
  190. ? c.contentInfo != null
  191. ? `${c.contentInfo}折`
  192. : '折扣'
  193. : c.contentInfo != null
  194. ? `${c.contentInfo}元`
  195. : '优惠',
  196. qty: Number(c.quantity) || 1
  197. };
  198. });
  199. const couponTotal = Number(data.couponTotalAmount) || 0;
  200. this.detail = {
  201. id: data.ledgerId,
  202. type: this.recordType,
  203. amount: isRecharge
  204. ? Number(data.transactionAmount != null ? data.transactionAmount : data.payAmount) || 0
  205. : Math.abs(Number(data.transactionAmount != null ? data.transactionAmount : data.payAmount) || 0),
  206. payTime: data.paidTime || data.successTime || data.createTime || '',
  207. spendTime: data.successTime || data.paidTime || data.createTime || '',
  208. payMethod: data.payChannel,
  209. storeName: isRecharge
  210. ? data.issuerMerchantName || data.transactionStoreName || ''
  211. : data.transactionStoreName || data.issuerMerchantName || '',
  212. orderNo: data.orderNo || '',
  213. userName: data.userName || '',
  214. userAccount: data.userAccount || '',
  215. paidAmount: data.payAmount != null ? data.payAmount : '',
  216. giftAmount: data.giftAmount != null ? data.giftAmount : 0,
  217. coupons,
  218. couponFaceText: couponTotal > 0 ? `${this.formatAmount(couponTotal)}元优惠券` : ''
  219. };
  220. this.couponExpanded = false;
  221. })
  222. .catch(() => {
  223. uni.showToast({ title: '网络异常,请稍后重试', icon: 'none' });
  224. })
  225. .finally(() => {
  226. this.loading = false;
  227. });
  228. }
  229. }
  230. };
  231. </script>
  232. <style scoped lang="scss">
  233. .page {
  234. min-height: 100vh;
  235. background: #f7f7f7;
  236. padding: 24rpx;
  237. padding-bottom: calc(40rpx + env(safe-area-inset-bottom));
  238. box-sizing: border-box;
  239. }
  240. .loading {
  241. padding-top: 200rpx;
  242. display: flex;
  243. justify-content: center;
  244. }
  245. .card {
  246. background: #fff;
  247. border-radius: 16rpx;
  248. margin-bottom: 24rpx;
  249. }
  250. .hero {
  251. display: flex;
  252. flex-direction: column;
  253. align-items: center;
  254. justify-content: center;
  255. padding: 56rpx 24rpx 48rpx;
  256. .amount {
  257. font-size: 56rpx;
  258. font-weight: 700;
  259. color: #333;
  260. line-height: 1.2;
  261. &.plus {
  262. color: #2b85e4;
  263. }
  264. }
  265. .status {
  266. margin-top: 16rpx;
  267. font-size: 28rpx;
  268. color: #333;
  269. }
  270. }
  271. .detail-card,
  272. .gift-card {
  273. padding: 8rpx 28rpx 16rpx;
  274. }
  275. .gift-title {
  276. padding: 28rpx 0 8rpx;
  277. font-size: 30rpx;
  278. font-weight: 600;
  279. color: #333;
  280. }
  281. .row {
  282. display: flex;
  283. align-items: flex-start;
  284. justify-content: space-between;
  285. padding: 24rpx 0;
  286. gap: 24rpx;
  287. .label {
  288. font-size: 28rpx;
  289. color: #999;
  290. flex-shrink: 0;
  291. width: 180rpx;
  292. }
  293. .value {
  294. flex: 1;
  295. text-align: right;
  296. font-size: 28rpx;
  297. color: #333;
  298. word-break: break-all;
  299. }
  300. &.link .value-wrap {
  301. flex: 1;
  302. display: flex;
  303. align-items: center;
  304. justify-content: flex-end;
  305. gap: 8rpx;
  306. .value {
  307. flex: none;
  308. }
  309. }
  310. }
  311. .coupon-scroll {
  312. width: 100%;
  313. margin: 8rpx 0 24rpx;
  314. white-space: nowrap;
  315. }
  316. .coupon-list {
  317. display: inline-flex;
  318. flex-direction: row;
  319. gap: 24rpx;
  320. padding-right: 8rpx;
  321. }
  322. /* coupon.png 原图 198x162,按比例铺底,文字分区对齐白卡/口袋 */
  323. .coupon-item {
  324. position: relative;
  325. width: 198rpx;
  326. height: 162rpx;
  327. flex-shrink: 0;
  328. }
  329. .coupon-bg {
  330. position: absolute;
  331. left: 0;
  332. top: 0;
  333. width: 100%;
  334. height: 100%;
  335. z-index: 0;
  336. }
  337. .coupon-body {
  338. position: relative;
  339. z-index: 1;
  340. width: 100%;
  341. height: 100%;
  342. display: flex;
  343. flex-direction: column;
  344. box-sizing: border-box;
  345. }
  346. .coupon-top {
  347. height: 58%;
  348. display: flex;
  349. flex-direction: column;
  350. align-items: center;
  351. justify-content: center;
  352. padding: 8rpx 12rpx 0;
  353. box-sizing: border-box;
  354. .c-name {
  355. font-size: 22rpx;
  356. color: #333;
  357. line-height: 1.2;
  358. text-align: center;
  359. max-width: 100%;
  360. overflow: hidden;
  361. text-overflow: ellipsis;
  362. white-space: nowrap;
  363. }
  364. .c-value {
  365. margin-top: 6rpx;
  366. font-size: 34rpx;
  367. font-weight: 700;
  368. color: #ff3b5c;
  369. line-height: 1.15;
  370. }
  371. }
  372. .coupon-bottom {
  373. height: 42%;
  374. display: flex;
  375. align-items: center;
  376. justify-content: center;
  377. padding-bottom: 4rpx;
  378. box-sizing: border-box;
  379. .c-qty {
  380. font-size: 24rpx;
  381. color: #fff;
  382. font-weight: 500;
  383. line-height: 1;
  384. }
  385. }
  386. </style>