小说小程序前端代码仓库(小程序)
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.

367 lines
8.0 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. },
  93. onShow() {
  94. this.getFlowList();
  95. },
  96. onReachBottom() {
  97. this.loadMore()
  98. },
  99. methods: {
  100. // 获取账户余额
  101. getAccountBalance() {
  102. this.$fetch('getMyMoneyNum').then(res => {
  103. this.accountBalance = res || 0;
  104. }).catch(err => {
  105. console.error('获取账户余额失败:', err);
  106. this.accountBalance = 0;
  107. });
  108. },
  109. // 切换tab
  110. switchTab(tab) {
  111. // uv-tabs组件传递的可能是对象,需要获取index
  112. const tabIndex = typeof tab === 'object' ? tab.index : tab;
  113. if (this.activeTab === tabIndex) return;
  114. this.activeTab = tabIndex;
  115. this.pageNo = 1;
  116. this.noMore = false;
  117. // 清空对应列表
  118. if (tabIndex === 0) {
  119. this.rechargeList = [];
  120. } else {
  121. this.payList = [];
  122. }
  123. this.getFlowList();
  124. },
  125. // 获取流水列表
  126. getFlowList() {
  127. if (this.loading || this.noMore) return;
  128. this.loading = true;
  129. // 根据当前tab确定流水类型:0-充值,1-支付
  130. const logType = this.activeTab === 0 ? 0 : 1;
  131. this.$fetch('getMyMoneyLogPage', {
  132. pageNo: this.pageNo,
  133. pageSize: this.pageSize,
  134. type: logType // 0-充值记录,1-支付记录
  135. }).then(res => {
  136. const records = res.records || [];
  137. if (records.length === 0) {
  138. this.noMore = true;
  139. } else {
  140. if (this.activeTab === 0) {
  141. // 充值记录
  142. if (this.pageNo === 1) {
  143. this.rechargeList = records;
  144. } else {
  145. this.rechargeList = [...this.rechargeList, ...records];
  146. }
  147. } else {
  148. // 支付记录
  149. if (this.pageNo === 1) {
  150. this.payList = records;
  151. } else {
  152. this.payList = [...this.payList, ...records];
  153. }
  154. }
  155. // 如果返回的记录数少于pageSize,说明没有更多了
  156. if (records.length < this.pageSize) {
  157. this.noMore = true;
  158. }
  159. }
  160. this.loading = false;
  161. }).catch(err => {
  162. console.error('获取流水列表失败:', err);
  163. this.loading = false;
  164. uni.showToast({
  165. title: '获取流水失败',
  166. icon: 'none'
  167. });
  168. });
  169. },
  170. // 加载更多
  171. loadMore() {
  172. if (this.loading || this.noMore) return;
  173. this.pageNo++;
  174. this.getFlowList();
  175. },
  176. // 格式化日期
  177. formatDate(dateString) {
  178. if (!dateString) return '';
  179. const date = new Date(dateString);
  180. const year = date.getFullYear();
  181. const month = (date.getMonth() + 1).toString().padStart(2, '0');
  182. const day = date.getDate().toString().padStart(2, '0');
  183. return `${year}.${month}.${day}`;
  184. },
  185. goRecharge() {
  186. uni.navigateTo({
  187. url: '/pages_order/mine/recharge'
  188. })
  189. }
  190. }
  191. }
  192. </script>
  193. <style lang="scss" scoped>
  194. .walletflow-page {
  195. min-height: 100vh;
  196. background: linear-gradient(180deg, #f8f8fc 0%, #fff 100%);
  197. padding-bottom: 30rpx;
  198. }
  199. .balance-card {
  200. background: linear-gradient(90deg, #f7f2fa 0%, #fbeaf2 100%);
  201. border-radius: 18rpx;
  202. margin: 24rpx 12rpx 0 12rpx;
  203. padding: 18rpx 24rpx 14rpx 24rpx;
  204. box-shadow: none;
  205. border: 1rpx solid #ede7ef;
  206. position: relative;
  207. display: flex;
  208. flex-direction: column;
  209. min-height: 130rpx;
  210. justify-content: center;
  211. .balance-label {
  212. color: #bbb;
  213. font-size: 26rpx;
  214. margin-bottom: 8rpx;
  215. }
  216. .balance-row {
  217. display: flex;
  218. align-items: center;
  219. margin-top: 0;
  220. position: relative;
  221. .balance-amount {
  222. color: #e94f7a;
  223. font-size: 48rpx;
  224. font-weight: bold;
  225. }
  226. .recharge-btn {
  227. position: absolute;
  228. right: 0;
  229. top: 50%;
  230. transform: translateY(-50%);
  231. background: linear-gradient(90deg, #ffb6c1 0%, #fa5a99 100%);
  232. color: #fff;
  233. font-size: 28rpx;
  234. border-radius: 32rpx;
  235. padding: 0 40rpx;
  236. height: 56rpx;
  237. line-height: 56rpx;
  238. font-weight: 500;
  239. border: none;
  240. box-shadow: none;
  241. display: flex;
  242. align-items: center;
  243. justify-content: center;
  244. }
  245. }
  246. }
  247. .flow-card {
  248. background: #fff;
  249. border-radius: 20rpx;
  250. margin: 32rpx 16rpx 0 16rpx;
  251. box-shadow: 0 4rpx 24rpx 0 rgba(0, 0, 0, 0.06);
  252. padding-bottom: 8rpx;
  253. overflow: hidden;
  254. // uv-tabs组件样式调整
  255. :deep(.uv-tabs) {
  256. background: #fff;
  257. border-top-left-radius: 20rpx;
  258. border-top-right-radius: 20rpx;
  259. }
  260. :deep(.uv-tabs__wrapper__nav__line) {
  261. border-radius: 2rpx !important;
  262. }
  263. }
  264. .flow-list {
  265. margin: 0;
  266. padding: 0 16rpx;
  267. max-height: calc(75vh - 88rpx);
  268. background: #fff;
  269. }
  270. .flow-item {
  271. border-bottom: 1px solid #f5f5f5;
  272. padding: 18rpx 0 8rpx 0;
  273. &:last-child {
  274. border-bottom: none;
  275. }
  276. .flow-item-row {
  277. display: flex;
  278. align-items: flex-start;
  279. justify-content: space-between;
  280. padding-right: 45rpx;
  281. padding-left: 15rpx;
  282. }
  283. .flow-item-left {
  284. display: flex;
  285. flex-direction: column;
  286. align-items: flex-start;
  287. .flow-title {
  288. font-size: 28rpx;
  289. color: #222;
  290. font-weight: 500;
  291. margin-bottom: 2rpx;
  292. }
  293. .flow-date {
  294. color: #bbb;
  295. font-size: 22rpx;
  296. margin-top: 0;
  297. }
  298. }
  299. .flow-amount {
  300. font-size: 26rpx;
  301. font-weight: 500;
  302. margin-left: 24rpx;
  303. margin-top: 2rpx;
  304. &.plus {
  305. color: #223a7a;
  306. }
  307. &.minus {
  308. color: #e94f7a;
  309. }
  310. }
  311. }
  312. // 提示文字样式
  313. .empty-tip,
  314. .loading-tip,
  315. .no-more-tip {
  316. text-align: center;
  317. padding: 40rpx 0;
  318. color: #999;
  319. font-size: 26rpx;
  320. }
  321. .loading-tip {
  322. color: #666;
  323. }
  324. </style>