money.vue 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348
  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">
  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 pagination = {
  81. data: [],
  82. current_page: 1,
  83. total: 1,
  84. last_page: 1,
  85. expense: 0,
  86. income: 0,
  87. };
  88. // 数据
  89. const state = reactive({
  90. showMoney: false,
  91. date: [],
  92. currentTab: 0,
  93. pagination,
  94. loadStatus: '',
  95. });
  96. const tabMaps = [
  97. {
  98. name: '全部',
  99. value: 'all',
  100. },
  101. {
  102. name: '收入',
  103. value: 'income',
  104. },
  105. {
  106. name: '支出',
  107. value: 'expense',
  108. },
  109. ];
  110. const userInfo = computed(() => sheep.$store('user').userInfo);
  111. const dateFilterText = computed(() => {
  112. if (state.date[0] === state.date[1]) {
  113. return state.date[0];
  114. } else {
  115. return state.date.join('~');
  116. }
  117. });
  118. async function getLogList(page = 1, list_rows = 8) {
  119. state.loadStatus = 'loading';
  120. let res = await sheep.$api.user.wallet.log({
  121. type: 'money',
  122. tab: tabMaps[state.currentTab].value,
  123. list_rows,
  124. page,
  125. date: appendTimeHMS(state.date),
  126. });
  127. if (res.error === 0) {
  128. let list = _.concat(state.pagination.data, res.data.list.data);
  129. state.pagination = {
  130. ...res.data.list,
  131. data: list,
  132. income: res.data.income,
  133. expense: res.data.expense,
  134. };
  135. if (state.pagination.current_page < state.pagination.last_page) {
  136. state.loadStatus = 'more';
  137. } else {
  138. state.loadStatus = 'noMore';
  139. }
  140. }
  141. }
  142. onLoad(async (options) => {
  143. const today = dayjs().format('YYYY-MM-DD');
  144. state.date = [today, today];
  145. getLogList();
  146. });
  147. function onChange(e) {
  148. state.pagination = pagination;
  149. state.currentTab = e.index;
  150. getLogList();
  151. }
  152. function onChangeTime(e) {
  153. state.date[0] = e[0];
  154. state.date[1] = e[e.length - 1];
  155. state.pagination = pagination;
  156. getLogList();
  157. }
  158. function appendTimeHMS(arr) {
  159. return [arr[0] + ' 00:00:00', arr[1] + ' 23:59:59'];
  160. }
  161. onReachBottom(() => {
  162. if (state.loadStatus !== 'noMore') {
  163. getLogList(state.pagination.current_page + 1);
  164. }
  165. });
  166. </script>
  167. <style lang="scss" scoped>
  168. // 钱包
  169. .header-box {
  170. background-color: $white;
  171. padding: 30rpx;
  172. .card-box {
  173. width: 100%;
  174. min-height: 300rpx;
  175. padding: 40rpx;
  176. background-size: 100% 100%;
  177. border-radius: 30rpx;
  178. overflow: hidden;
  179. position: relative;
  180. z-index: 1;
  181. box-sizing: border-box;
  182. &::after {
  183. content: '';
  184. display: block;
  185. width: 100%;
  186. height: 100%;
  187. z-index: 2;
  188. position: absolute;
  189. top: 0;
  190. left: 0;
  191. background: v-bind("sheep.$url.css('/static/img/shop/user/wallet_card_bg.png')") no-repeat;
  192. pointer-events: none;
  193. }
  194. .card-head {
  195. color: $white;
  196. font-size: 30rpx;
  197. }
  198. .ss-eye-icon {
  199. font-size: 40rpx;
  200. color: $white;
  201. }
  202. .money-num {
  203. font-size: 70rpx;
  204. line-height: 70rpx;
  205. font-weight: 500;
  206. color: $white;
  207. font-family: OPPOSANS;
  208. }
  209. .reduce-num {
  210. font-size: 26rpx;
  211. font-weight: 400;
  212. color: $white;
  213. }
  214. .topup-btn {
  215. width: 120rpx;
  216. height: 60rpx;
  217. line-height: 60rpx;
  218. border-radius: 30px;
  219. font-size: 26rpx;
  220. font-weight: 500;
  221. background-color: $white;
  222. color: var(--ui-BG-Main);
  223. }
  224. }
  225. }
  226. // 筛选
  227. .filter-box {
  228. height: 114rpx;
  229. background-color: $bg-page;
  230. .total-box {
  231. font-size: 24rpx;
  232. font-weight: 500;
  233. color: $dark-9;
  234. }
  235. .date-btn {
  236. background-color: $white;
  237. line-height: 54rpx;
  238. border-radius: 27rpx;
  239. padding: 0 20rpx;
  240. font-size: 24rpx;
  241. font-weight: 500;
  242. color: $dark-6;
  243. .ss-seldate-icon {
  244. font-size: 50rpx;
  245. color: $dark-9;
  246. }
  247. }
  248. }
  249. .tabs-box {
  250. background: $white;
  251. border-bottom: 2rpx solid #eeeeee;
  252. }
  253. // tab
  254. .wallet-tab-card {
  255. .tab-item {
  256. height: 80rpx;
  257. position: relative;
  258. .tab-title {
  259. font-size: 30rpx;
  260. }
  261. .cur-tab-title {
  262. font-weight: $font-weight-bold;
  263. }
  264. .tab-line {
  265. width: 60rpx;
  266. height: 6rpx;
  267. border-radius: 6rpx;
  268. position: absolute;
  269. left: 50%;
  270. transform: translateX(-50%);
  271. bottom: 2rpx;
  272. background-color: var(--ui-BG-Main);
  273. }
  274. }
  275. }
  276. // 钱包记录
  277. .wallet-list {
  278. padding: 30rpx;
  279. background-color: #ffff;
  280. .head-img {
  281. width: 70rpx;
  282. height: 70rpx;
  283. border-radius: 50%;
  284. background: $gray-c;
  285. }
  286. .list-content {
  287. justify-content: space-between;
  288. align-items: flex-start;
  289. flex: 1;
  290. .title {
  291. font-size: 28rpx;
  292. color: $dark-3;
  293. width: 400rpx;
  294. }
  295. .time {
  296. color: $gray-c;
  297. font-size: 22rpx;
  298. }
  299. }
  300. .money {
  301. font-size: 28rpx;
  302. font-weight: bold;
  303. font-family: OPPOSANS;
  304. .add {
  305. color: var(--ui-BG-Main);
  306. }
  307. .minus {
  308. color: $dark-3;
  309. }
  310. }
  311. }
  312. </style>