money.vue 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373
  1. <!-- 我的钱包 -->
  2. <template>
  3. <s-layout class="wallet-wrap" title="钱包">
  4. <!-- 钱包卡片 -->
  5. <view class="header-box ss-flex ss-row-center ss-col-center">
  6. <view class="card-box ui-BG-Main ui-Shadow-Main">
  7. <view class="card-head ss-flex ss-col-center">
  8. <view class="card-title ss-m-r-10">钱包余额(元)</view>
  9. <view
  10. @tap="state.showMoney = !state.showMoney"
  11. class="ss-eye-icon"
  12. :class="state.showMoney ? 'cicon-eye' : 'cicon-eye-off'"
  13. />
  14. </view>
  15. <view class="ss-flex ss-row-between ss-col-center ss-m-t-64">
  16. <view class="money-num">{{ state.showMoney ? fen2yuan(userWallet.balance) : '*****' }}</view>
  17. <button class="ss-reset-button topup-btn" @tap="sheep.$router.go('/pages/pay/recharge')">
  18. 充值
  19. </button>
  20. </view>
  21. </view>
  22. </view>
  23. <su-sticky>
  24. <!-- 统计 -->
  25. <view class="filter-box ss-p-x-30 ss-flex ss-col-center ss-row-between">
  26. <uni-datetime-picker v-model="state.data" type="daterange" @change="onChangeTime" :end="state.today">
  27. <button class="ss-reset-button date-btn">
  28. <text>{{ dateFilterText }}</text>
  29. <text class="cicon-drop-down ss-seldate-icon"></text>
  30. </button>
  31. </uni-datetime-picker>
  32. <view class="total-box">
  33. <view class="ss-m-b-10">总收入¥{{ fen2yuan(state.summary.totalIncome) }}</view>
  34. <view>总支出¥{{ fen2yuan(state.summary.totalExpense) }}</view>
  35. </view>
  36. </view>
  37. <su-tabs
  38. :list="tabMaps"
  39. @change="onChange"
  40. :scrollable="false"
  41. :current="state.currentTab"
  42. ></su-tabs>
  43. </su-sticky>
  44. <s-empty v-if="state.pagination.total === 0" text="暂无数据" icon="/static/data-empty.png" />
  45. <!-- 钱包记录 -->
  46. <view v-if="state.pagination.total > 0">
  47. <view
  48. class="wallet-list ss-flex border-bottom"
  49. v-for="item in state.pagination.list"
  50. :key="item.id"
  51. >
  52. <view class="list-content">
  53. <view class="title-box ss-flex ss-row-between ss-m-b-20">
  54. <text class="title ss-line-1">
  55. {{ item.title }}
  56. </text>
  57. <view class="money">
  58. <text v-if="item.price >= 0" class="add">+{{ fen2yuan(item.price) }}</text>
  59. <text v-else class="minus">{{ fen2yuan(item.price) }}</text>
  60. </view>
  61. </view>
  62. <text class="time">
  63. {{ sheep.$helper.timeFormat(state.createTime, 'yyyy-mm-dd hh:MM:ss') }}
  64. </text>
  65. </view>
  66. </view>
  67. </view>
  68. <uni-load-more
  69. v-if="state.pagination.total > 0"
  70. :status="state.loadStatus"
  71. :content-text="{
  72. contentdown: '上拉加载更多',
  73. }"
  74. />
  75. </s-layout>
  76. </template>
  77. <script setup>
  78. import { computed, reactive } from 'vue';
  79. import { onLoad, onReachBottom } from '@dcloudio/uni-app';
  80. import sheep from '@/sheep';
  81. import dayjs from 'dayjs';
  82. import _ from 'lodash';
  83. import PayWalletApi from '@/sheep/api/pay/wallet';
  84. import { fen2yuan } from '@/sheep/hooks/useGoods';
  85. import { resetPagination } from '@/sheep/util';
  86. const headerBg = sheep.$url.css('/static/img/shop/user/wallet_card_bg.png');
  87. // 数据
  88. const state = reactive({
  89. showMoney: false,
  90. date: [], // 筛选的时间段
  91. currentTab: 0,
  92. pagination: {
  93. list: [],
  94. total: 0,
  95. pageNo: 1,
  96. pageSize: 8
  97. },
  98. summary: {
  99. totalIncome: 0,
  100. totalExpense: 0,
  101. },
  102. loadStatus: '',
  103. today: '',
  104. });
  105. const tabMaps = [
  106. {
  107. name: '全部',
  108. value: '',
  109. },
  110. {
  111. name: '收入',
  112. value: '1',
  113. },
  114. {
  115. name: '支出',
  116. value: '2',
  117. },
  118. ];
  119. const userWallet = computed(() => sheep.$store('user').userWallet);
  120. // 格式化时间段
  121. const dateFilterText = computed(() => {
  122. if (state.date[0] === state.date[1]) {
  123. return state.date[0];
  124. } else {
  125. return state.date.join('~');
  126. }
  127. });
  128. // 获得钱包记录分页
  129. async function getLogList() {
  130. state.loadStatus = 'loading';
  131. const { data, code } = await PayWalletApi.getWalletTransactionPage({
  132. pageNo: state.pagination.pageNo,
  133. pageSize: state.pagination.pageSize,
  134. type: tabMaps[state.currentTab].value,
  135. 'createTime[0]': state.date[0] + ' 00:00:00',
  136. 'createTime[1]': state.date[1] + ' 23:59:59',
  137. });
  138. if (code !== 0) {
  139. return;
  140. }
  141. state.pagination.list = _.concat(state.pagination.list, data.list);
  142. state.pagination.total = data.total;
  143. state.loadStatus = state.pagination.list.length < state.pagination.total ? 'more' : 'noMore';
  144. }
  145. // 获得钱包统计
  146. async function getSummary() {
  147. const { data, code } = await PayWalletApi.getWalletTransactionSummary({
  148. 'createTime': [state.date[0] + ' 00:00:00', state.date[1] + ' 23:59:59'],
  149. });
  150. if (code !== 0) {
  151. return;
  152. }
  153. state.summary = data;
  154. }
  155. onLoad(() => {
  156. state.today = dayjs().format('YYYY-MM-DD');
  157. state.date = [state.today, state.today];
  158. getLogList();
  159. getSummary();
  160. // 刷新钱包的缓存
  161. sheep.$store('user').getWallet();
  162. });
  163. // 处理 tab 切换
  164. function onChange(e) {
  165. state.currentTab = e.index;
  166. // 重新加载列表
  167. resetPagination(state.pagination);
  168. getLogList();
  169. getSummary();
  170. }
  171. // 处理时间筛选
  172. function onChangeTime(e) {
  173. state.date[0] = e[0];
  174. state.date[1] = e[e.length - 1];
  175. // 重新加载列表
  176. resetPagination(state.pagination);
  177. getLogList();
  178. getSummary();
  179. }
  180. onReachBottom(() => {
  181. if (state.loadStatus === 'noMore') {
  182. return;
  183. }
  184. state.pagination.pageNo++;
  185. getLogList();
  186. });
  187. </script>
  188. <style lang="scss" scoped>
  189. // 钱包
  190. .header-box {
  191. background-color: $white;
  192. padding: 30rpx;
  193. .card-box {
  194. width: 100%;
  195. min-height: 300rpx;
  196. padding: 40rpx;
  197. background-size: 100% 100%;
  198. border-radius: 30rpx;
  199. overflow: hidden;
  200. position: relative;
  201. z-index: 1;
  202. box-sizing: border-box;
  203. &::after {
  204. content: '';
  205. display: block;
  206. width: 100%;
  207. height: 100%;
  208. z-index: 2;
  209. position: absolute;
  210. top: 0;
  211. left: 0;
  212. background: v-bind(headerBg)
  213. no-repeat;
  214. pointer-events: none;
  215. }
  216. .card-head {
  217. color: $white;
  218. font-size: 30rpx;
  219. }
  220. .ss-eye-icon {
  221. font-size: 40rpx;
  222. color: $white;
  223. }
  224. .money-num {
  225. font-size: 70rpx;
  226. line-height: 70rpx;
  227. font-weight: 500;
  228. color: $white;
  229. font-family: OPPOSANS;
  230. }
  231. .reduce-num {
  232. font-size: 26rpx;
  233. font-weight: 400;
  234. color: $white;
  235. }
  236. .topup-btn {
  237. width: 120rpx;
  238. height: 60rpx;
  239. line-height: 60rpx;
  240. border-radius: 30px;
  241. font-size: 26rpx;
  242. font-weight: 500;
  243. background-color: $white;
  244. color: var(--ui-BG-Main);
  245. }
  246. }
  247. }
  248. // 筛选
  249. .filter-box {
  250. height: 114rpx;
  251. background-color: $bg-page;
  252. .total-box {
  253. font-size: 24rpx;
  254. font-weight: 500;
  255. color: $dark-9;
  256. }
  257. .date-btn {
  258. background-color: $white;
  259. line-height: 54rpx;
  260. border-radius: 27rpx;
  261. padding: 0 20rpx;
  262. font-size: 24rpx;
  263. font-weight: 500;
  264. color: $dark-6;
  265. .ss-seldate-icon {
  266. font-size: 50rpx;
  267. color: $dark-9;
  268. }
  269. }
  270. }
  271. .tabs-box {
  272. background: $white;
  273. border-bottom: 2rpx solid #eeeeee;
  274. }
  275. // tab
  276. .wallet-tab-card {
  277. .tab-item {
  278. height: 80rpx;
  279. position: relative;
  280. .tab-title {
  281. font-size: 30rpx;
  282. }
  283. .cur-tab-title {
  284. font-weight: $font-weight-bold;
  285. }
  286. .tab-line {
  287. width: 60rpx;
  288. height: 6rpx;
  289. border-radius: 6rpx;
  290. position: absolute;
  291. left: 50%;
  292. transform: translateX(-50%);
  293. bottom: 2rpx;
  294. background-color: var(--ui-BG-Main);
  295. }
  296. }
  297. }
  298. // 钱包记录
  299. .wallet-list {
  300. padding: 30rpx;
  301. background-color: #ffff;
  302. .head-img {
  303. width: 70rpx;
  304. height: 70rpx;
  305. border-radius: 50%;
  306. background: $gray-c;
  307. }
  308. .list-content {
  309. justify-content: space-between;
  310. align-items: flex-start;
  311. flex: 1;
  312. .title {
  313. font-size: 28rpx;
  314. color: $dark-3;
  315. width: 400rpx;
  316. }
  317. .time {
  318. color: $gray-c;
  319. font-size: 22rpx;
  320. }
  321. }
  322. .money {
  323. font-size: 28rpx;
  324. font-weight: bold;
  325. font-family: OPPOSANS;
  326. .add {
  327. color: var(--ui-BG-Main);
  328. }
  329. .minus {
  330. color: $dark-3;
  331. }
  332. }
  333. }
  334. </style>