小说小程序前端代码仓库(小程序)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

362 lines
7.9 KiB

  1. <!-- 钱包流水页面 -->
  2. <template>
  3. <view class="walletflow-page">
  4. <!-- 顶部导航栏 -->
  5. <navbar title="钱包流水" leftClick @leftClick="$utils.navigateBack" />
  6. <!-- 账户余额卡片 -->
  7. <view class="balance-card">
  8. <view class="balance-label">账户</view>
  9. <view class="balance-row">
  10. <text class="balance-amount">{{ accountBalance }}</text>
  11. <button class="recharge-btn" @click="goRecharge">充值</button>
  12. </view>
  13. </view>
  14. <!-- tab和流水列表卡片 -->
  15. <view class="flow-card">
  16. <uv-tabs
  17. :list="tabList"
  18. :current="activeTab"
  19. @change="switchTab"
  20. :scrollable="false"
  21. activeColor="#223a7a"
  22. inactiveColor="#888"
  23. lineColor="#223a7a"
  24. lineWidth="44rpx"
  25. lineHeight="4rpx"
  26. :itemStyle="{
  27. height: '88rpx',
  28. fontSize: '30rpx',
  29. fontWeight: 'bold'
  30. }"
  31. ></uv-tabs>
  32. <scroll-view scroll-y class="flow-list" @scrolltolower="loadMore">
  33. <view v-if="activeTab === 0">
  34. <view class="flow-item" v-for="(item, idx) in rechargeList" :key="idx">
  35. <view class="flow-item-row">
  36. <view class="flow-item-left">
  37. <view class="flow-title">{{ item.title || item.type || '充值' }}</view>
  38. <view class="flow-date">{{ formatDate(item.createTime) }}</view>
  39. </view>
  40. <view class="flow-amount plus">+{{ item.money }}</view>
  41. </view>
  42. </view>
  43. <view v-if="rechargeList.length == 0 && !loading" class="empty-tip">暂无记录</view>
  44. </view>
  45. <view v-else>
  46. <view class="flow-item" v-for="(item, idx) in payList" :key="idx">
  47. <view class="flow-item-row">
  48. <view class="flow-item-left">
  49. <view class="flow-title">{{ item.title || item.type || '支付' }}</view>
  50. <view class="flow-date">{{ formatDate(item.createTime) }}</view>
  51. </view>
  52. <view class="flow-amount minus">-{{ item.money }}</view>
  53. </view>
  54. </view>
  55. <view v-if="payList.length == 0 && !loading" class="empty-tip">暂无记录</view>
  56. </view>
  57. <view v-if="loading" class="loading-tip">加载中...</view>
  58. </scroll-view>
  59. </view>
  60. </view>
  61. </template>
  62. <script>
  63. import mixinsList from '@/mixins/list.js'
  64. export default {
  65. mixins: [mixinsList],
  66. components: {
  67. },
  68. data() {
  69. return {
  70. accountBalance: 0,
  71. activeTab: 0,
  72. rechargeList: [],
  73. payList: [],
  74. loading: false,
  75. noMore: false,
  76. pageNo: 1,
  77. pageSize: 20,
  78. tabList: [
  79. {
  80. name: '收入',
  81. value: 0
  82. },
  83. {
  84. name: '支出',
  85. value: 1
  86. }
  87. ]
  88. }
  89. },
  90. onLoad() {
  91. this.getAccountBalance();
  92. this.getFlowList();
  93. },
  94. methods: {
  95. // 获取账户余额
  96. getAccountBalance() {
  97. this.$fetch('getMyMoneyNum').then(res => {
  98. this.accountBalance = res || 0;
  99. }).catch(err => {
  100. console.error('获取账户余额失败:', err);
  101. this.accountBalance = 0;
  102. });
  103. },
  104. // 切换tab
  105. switchTab(tab) {
  106. // uv-tabs组件传递的可能是对象,需要获取index
  107. const tabIndex = typeof tab === 'object' ? tab.index : tab;
  108. if (this.activeTab === tabIndex) return;
  109. this.activeTab = tabIndex;
  110. this.pageNo = 1;
  111. this.noMore = false;
  112. // 清空对应列表
  113. if (tabIndex === 0) {
  114. this.rechargeList = [];
  115. } else {
  116. this.payList = [];
  117. }
  118. this.getFlowList();
  119. },
  120. // 获取流水列表
  121. getFlowList() {
  122. if (this.loading || this.noMore) return;
  123. this.loading = true;
  124. // 根据当前tab确定流水类型:0-充值,1-支付
  125. const logType = this.activeTab === 0 ? 0 : 1;
  126. this.$fetch('getMyMoneyLogPage', {
  127. pageNo: this.pageNo,
  128. pageSize: this.pageSize,
  129. type: logType // 0-充值记录,1-支付记录
  130. }).then(res => {
  131. const records = res.records || [];
  132. if (records.length === 0) {
  133. this.noMore = true;
  134. } else {
  135. if (this.activeTab === 0) {
  136. // 充值记录
  137. if (this.pageNo === 1) {
  138. this.rechargeList = records;
  139. } else {
  140. this.rechargeList = [...this.rechargeList, ...records];
  141. }
  142. } else {
  143. // 支付记录
  144. if (this.pageNo === 1) {
  145. this.payList = records;
  146. } else {
  147. this.payList = [...this.payList, ...records];
  148. }
  149. }
  150. // 如果返回的记录数少于pageSize,说明没有更多了
  151. if (records.length < this.pageSize) {
  152. this.noMore = true;
  153. }
  154. }
  155. this.loading = false;
  156. }).catch(err => {
  157. console.error('获取流水列表失败:', err);
  158. this.loading = false;
  159. uni.showToast({
  160. title: '获取流水失败',
  161. icon: 'none'
  162. });
  163. });
  164. },
  165. // 加载更多
  166. loadMore() {
  167. if (this.loading || this.noMore) return;
  168. this.pageNo++;
  169. this.getFlowList();
  170. },
  171. // 格式化日期
  172. formatDate(dateString) {
  173. if (!dateString) return '';
  174. const date = new Date(dateString);
  175. const year = date.getFullYear();
  176. const month = (date.getMonth() + 1).toString().padStart(2, '0');
  177. const day = date.getDate().toString().padStart(2, '0');
  178. return `${year}.${month}.${day}`;
  179. },
  180. goRecharge() {
  181. uni.navigateTo({
  182. url: '/pages_order/mine/recharge'
  183. })
  184. }
  185. }
  186. }
  187. </script>
  188. <style lang="scss" scoped>
  189. .walletflow-page {
  190. min-height: 100vh;
  191. background: linear-gradient(180deg, #f8f8fc 0%, #fff 100%);
  192. padding-bottom: 30rpx;
  193. }
  194. .balance-card {
  195. background: linear-gradient(90deg, #f7f2fa 0%, #fbeaf2 100%);
  196. border-radius: 18rpx;
  197. margin: 24rpx 12rpx 0 12rpx;
  198. padding: 18rpx 24rpx 14rpx 24rpx;
  199. box-shadow: none;
  200. border: 1rpx solid #ede7ef;
  201. position: relative;
  202. display: flex;
  203. flex-direction: column;
  204. min-height: 130rpx;
  205. justify-content: center;
  206. .balance-label {
  207. color: #bbb;
  208. font-size: 26rpx;
  209. margin-bottom: 8rpx;
  210. }
  211. .balance-row {
  212. display: flex;
  213. align-items: center;
  214. margin-top: 0;
  215. position: relative;
  216. .balance-amount {
  217. color: #e94f7a;
  218. font-size: 48rpx;
  219. font-weight: bold;
  220. }
  221. .recharge-btn {
  222. position: absolute;
  223. right: 0;
  224. top: 50%;
  225. transform: translateY(-50%);
  226. background: linear-gradient(90deg, #ffb6c1 0%, #fa5a99 100%);
  227. color: #fff;
  228. font-size: 28rpx;
  229. border-radius: 32rpx;
  230. padding: 0 40rpx;
  231. height: 56rpx;
  232. line-height: 56rpx;
  233. font-weight: 500;
  234. border: none;
  235. box-shadow: none;
  236. display: flex;
  237. align-items: center;
  238. justify-content: center;
  239. }
  240. }
  241. }
  242. .flow-card {
  243. background: #fff;
  244. border-radius: 20rpx;
  245. margin: 32rpx 16rpx 0 16rpx;
  246. box-shadow: 0 4rpx 24rpx 0 rgba(0, 0, 0, 0.06);
  247. padding-bottom: 8rpx;
  248. overflow: hidden;
  249. // uv-tabs组件样式调整
  250. :deep(.uv-tabs) {
  251. background: #fff;
  252. border-top-left-radius: 20rpx;
  253. border-top-right-radius: 20rpx;
  254. }
  255. :deep(.uv-tabs__wrapper__nav__line) {
  256. border-radius: 2rpx !important;
  257. }
  258. }
  259. .flow-list {
  260. margin: 0;
  261. padding: 0 16rpx;
  262. max-height: calc(75vh - 88rpx);
  263. background: #fff;
  264. }
  265. .flow-item {
  266. border-bottom: 1px solid #f5f5f5;
  267. padding: 18rpx 0 8rpx 0;
  268. &:last-child {
  269. border-bottom: none;
  270. }
  271. .flow-item-row {
  272. display: flex;
  273. align-items: flex-start;
  274. justify-content: space-between;
  275. padding-right: 45rpx;
  276. padding-left: 15rpx;
  277. }
  278. .flow-item-left {
  279. display: flex;
  280. flex-direction: column;
  281. align-items: flex-start;
  282. .flow-title {
  283. font-size: 28rpx;
  284. color: #222;
  285. font-weight: 500;
  286. margin-bottom: 2rpx;
  287. }
  288. .flow-date {
  289. color: #bbb;
  290. font-size: 22rpx;
  291. margin-top: 0;
  292. }
  293. }
  294. .flow-amount {
  295. font-size: 26rpx;
  296. font-weight: 500;
  297. margin-left: 24rpx;
  298. margin-top: 2rpx;
  299. &.plus {
  300. color: #223a7a;
  301. }
  302. &.minus {
  303. color: #e94f7a;
  304. }
  305. }
  306. }
  307. // 提示文字样式
  308. .empty-tip,
  309. .loading-tip,
  310. .no-more-tip {
  311. text-align: center;
  312. padding: 40rpx 0;
  313. color: #999;
  314. font-size: 26rpx;
  315. }
  316. .loading-tip {
  317. color: #666;
  318. }
  319. </style>