money.vue 8.0 KB

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