money.vue 8.7 KB

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