money.vue 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370
  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(userInfo.money) : '*****' }}</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 userInfo = computed(() => sheep.$store('user').userInfo);
  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. // 处理 tab 切换
  162. function onChange(e) {
  163. state.currentTab = e.index;
  164. // 重新加载列表
  165. resetPagination(state.pagination);
  166. getLogList();
  167. getSummary();
  168. }
  169. // 处理时间筛选
  170. function onChangeTime(e) {
  171. state.date[0] = e[0];
  172. state.date[1] = e[e.length - 1];
  173. // 重新加载列表
  174. resetPagination(state.pagination);
  175. getLogList();
  176. getSummary();
  177. }
  178. onReachBottom(() => {
  179. if (state.loadStatus === 'noMore') {
  180. return;
  181. }
  182. state.pagination.pageNo++;
  183. getLogList();
  184. });
  185. </script>
  186. <style lang="scss" scoped>
  187. // 钱包
  188. .header-box {
  189. background-color: $white;
  190. padding: 30rpx;
  191. .card-box {
  192. width: 100%;
  193. min-height: 300rpx;
  194. padding: 40rpx;
  195. background-size: 100% 100%;
  196. border-radius: 30rpx;
  197. overflow: hidden;
  198. position: relative;
  199. z-index: 1;
  200. box-sizing: border-box;
  201. &::after {
  202. content: '';
  203. display: block;
  204. width: 100%;
  205. height: 100%;
  206. z-index: 2;
  207. position: absolute;
  208. top: 0;
  209. left: 0;
  210. background: v-bind(headerBg)
  211. no-repeat;
  212. pointer-events: none;
  213. }
  214. .card-head {
  215. color: $white;
  216. font-size: 30rpx;
  217. }
  218. .ss-eye-icon {
  219. font-size: 40rpx;
  220. color: $white;
  221. }
  222. .money-num {
  223. font-size: 70rpx;
  224. line-height: 70rpx;
  225. font-weight: 500;
  226. color: $white;
  227. font-family: OPPOSANS;
  228. }
  229. .reduce-num {
  230. font-size: 26rpx;
  231. font-weight: 400;
  232. color: $white;
  233. }
  234. .topup-btn {
  235. width: 120rpx;
  236. height: 60rpx;
  237. line-height: 60rpx;
  238. border-radius: 30px;
  239. font-size: 26rpx;
  240. font-weight: 500;
  241. background-color: $white;
  242. color: var(--ui-BG-Main);
  243. }
  244. }
  245. }
  246. // 筛选
  247. .filter-box {
  248. height: 114rpx;
  249. background-color: $bg-page;
  250. .total-box {
  251. font-size: 24rpx;
  252. font-weight: 500;
  253. color: $dark-9;
  254. }
  255. .date-btn {
  256. background-color: $white;
  257. line-height: 54rpx;
  258. border-radius: 27rpx;
  259. padding: 0 20rpx;
  260. font-size: 24rpx;
  261. font-weight: 500;
  262. color: $dark-6;
  263. .ss-seldate-icon {
  264. font-size: 50rpx;
  265. color: $dark-9;
  266. }
  267. }
  268. }
  269. .tabs-box {
  270. background: $white;
  271. border-bottom: 2rpx solid #eeeeee;
  272. }
  273. // tab
  274. .wallet-tab-card {
  275. .tab-item {
  276. height: 80rpx;
  277. position: relative;
  278. .tab-title {
  279. font-size: 30rpx;
  280. }
  281. .cur-tab-title {
  282. font-weight: $font-weight-bold;
  283. }
  284. .tab-line {
  285. width: 60rpx;
  286. height: 6rpx;
  287. border-radius: 6rpx;
  288. position: absolute;
  289. left: 50%;
  290. transform: translateX(-50%);
  291. bottom: 2rpx;
  292. background-color: var(--ui-BG-Main);
  293. }
  294. }
  295. }
  296. // 钱包记录
  297. .wallet-list {
  298. padding: 30rpx;
  299. background-color: #ffff;
  300. .head-img {
  301. width: 70rpx;
  302. height: 70rpx;
  303. border-radius: 50%;
  304. background: $gray-c;
  305. }
  306. .list-content {
  307. justify-content: space-between;
  308. align-items: flex-start;
  309. flex: 1;
  310. .title {
  311. font-size: 28rpx;
  312. color: $dark-3;
  313. width: 400rpx;
  314. }
  315. .time {
  316. color: $gray-c;
  317. font-size: 22rpx;
  318. }
  319. }
  320. .money {
  321. font-size: 28rpx;
  322. font-weight: bold;
  323. font-family: OPPOSANS;
  324. .add {
  325. color: var(--ui-BG-Main);
  326. }
  327. .minus {
  328. color: $dark-3;
  329. }
  330. }
  331. }
  332. </style>