money.vue 8.0 KB

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