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