wallet.vue 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372
  1. <template>
  2. <view class="page flex-column">
  3. <navigation-bar
  4. autoFixedStyle="background-color:#fff;"
  5. title="我的钱包"
  6. @ready="ready"
  7. ></navigation-bar>
  8. <view class="head flex-shrink">
  9. <view>
  10. <image class="bg" src="../static/wallet-banner.png"></image>
  11. <view class="fg pt-48 pl-48 pr-48">
  12. <view class="flex-align-center">
  13. <uni-icons
  14. type="wallet-filled"
  15. size="24"
  16. color="#ffffff"
  17. ></uni-icons>
  18. <view class="fs-36 color-fff fw-500 ml-16">我的钱包</view>
  19. <view
  20. class="btn flex-center fs-28 ml-auto"
  21. @click="to(`/pages-user/wallet-refund/wallet-refund`)"
  22. >退款
  23. </view
  24. >
  25. </view>
  26. <view class="price mt-50" v-if="user">
  27. <text class="color-fff fw-600 fs-48" style="vertical-align: top"
  28. >¥
  29. </text
  30. >
  31. <text
  32. class="color-fff fw-600 ml-12"
  33. style="font-size: 46px; line-height: 46px"
  34. >{{ user.balance }}
  35. </text
  36. >
  37. </view>
  38. </view>
  39. </view>
  40. </view>
  41. <view class="body flex-grow flex-column">
  42. <view class="tabs flex-shrink flex-align-center">
  43. <view
  44. v-for="(item, index) in tabs"
  45. :key="index"
  46. class="flex-align-center fs-30 mr-60"
  47. :style="{
  48. color:
  49. tab === item.value ? 'rgba(0, 0, 0, 1);' : 'rgba(0, 0, 0, 0.6);',
  50. }"
  51. @click="changeTab(index)"
  52. >{{
  53. item.label
  54. }}
  55. <view
  56. :style="{ opacity: tab === item.value ? '1' : '0' }"
  57. class="active"
  58. ></view
  59. >
  60. </view>
  61. </view>
  62. <view class="list pl-30 pr-30">
  63. <view
  64. class="item flex-align-center"
  65. v-for="(item, index) in dataList"
  66. :key="index"
  67. @click="detail(index)"
  68. >
  69. <view>
  70. <view class="fs-30 fw-500" key="title" duration="300">{{
  71. typeMap[item.type - 1]
  72. }}
  73. </view>
  74. <view v-if="item.type!==2">
  75. <view class="fs-24" style="color: rgba(0, 0, 0, 0.4)">余额</view>
  76. </view>
  77. <view v-else>
  78. <text class="refund-status" :style="refundStyle(item.status)">{{ refundLabel(item.status) }}</text>
  79. </view>
  80. </view>
  81. <view class="ml-auto" style="text-align: right">
  82. <view class="fs-30 fw-500">
  83. <text>{{ item.type == 3 ? "- " : "" }}{{ item.amount }}</text>
  84. <text class="fs-24 ml-6">元</text>
  85. </view>
  86. <view class="fs-24" style="color: rgba(0, 0, 0, 0.4)">{{
  87. item.transactionTime
  88. }}
  89. </view>
  90. </view>
  91. <view class="ml-32" v-if="item.type === 3">
  92. <uni-icons
  93. type="right"
  94. size="12"
  95. color="rgba(0,0,0,0.4)"
  96. ></uni-icons>
  97. </view>
  98. <view class="ml-32" v-else>&nbsp;&nbsp;&nbsp;</view>
  99. </view>
  100. </view>
  101. <view style="height: 170rpx"></view>
  102. </view>
  103. <style-bottom-view background="#ffffff">
  104. <view class="pl-40 pr-40 pb-30 pt-30">
  105. <style-button
  106. type="primary"
  107. @click="to(`/pages-user/wallet-recharge/wallet-recharge`)"
  108. >充值
  109. </style-button
  110. >
  111. </view>
  112. </style-bottom-view>
  113. </view>
  114. </template>
  115. <script setup lang="ts">
  116. import {useInfiniteScroll} from "../../utils/infinite-scroll";
  117. import {onReachBottom, onPullDownRefresh, onShow} from "@dcloudio/uni-app";
  118. import {fetchWallet, listRefund} from "../../api/user";
  119. import {to} from "../../utils/navigate";
  120. import {ref} from "vue";
  121. import {rpxToPx} from "@/utils/device";
  122. import { requireAuth } from "@/utils/auth";
  123. const user = ref();
  124. const dataList = ref([])
  125. const tab = ref(0);
  126. const tabs = ref([
  127. {
  128. label: "全部",
  129. value: 0,
  130. },
  131. {
  132. label: "充值",
  133. value: 1,
  134. },
  135. {
  136. label: "消费",
  137. value: 3,
  138. },
  139. {
  140. label: "退款",
  141. value: 2,
  142. },
  143. ]);
  144. const refundStatusMap = ref([
  145. {label: '退款成功 ', value: 'SUCCESS', color: '#4cd964'},
  146. {label: '退款关闭 ', value: 'CLOSED', color: '#000000'},
  147. {label: '退款处理中 ', value: 'PROCESSING', color: '#007aff'},
  148. {label: '退款异常 ', value: 'ABNORMAL', color: '#dd524d'},
  149. {label: '退款已申请 ', value: 'NEW', color: '#f0ad4e'},
  150. ])
  151. const typeMap = ref(["充值", "退款", "消费"]);
  152. /*const infiniteScroller = useInfiniteScroll(10, (page) => {
  153. return fetchWallet(tab.value, page, 10).then((res: any) => {
  154. if (res && res.length) {
  155. res.forEach((item: any) => {
  156. item.amount = (Number(item.amount) / 100).toFixed(2);
  157. });
  158. }
  159. return res;
  160. });
  161. });*/
  162. const scrollViewHeight = ref(0);
  163. onShow(() => {
  164. if (!requireAuth()) {
  165. return;
  166. }
  167. loadData();
  168. if (getApp<any>().globalData.user) {
  169. user.value = getApp<any>().globalData.user;
  170. }
  171. })
  172. onReachBottom(() => {
  173. // if(tab.value!==2){
  174. // infiniteScroller.next();
  175. // }
  176. loadData();
  177. });
  178. onPullDownRefresh(() => {
  179. // if(tab.value!==2){
  180. // infiniteScroller.refresh();
  181. // }
  182. loadData();
  183. });
  184. const ready = (e: any) => {
  185. scrollViewHeight.value =
  186. getApp<any>().globalData.device.windowHeight -
  187. (e.detail.navigationBarHeight + rpxToPx(380));
  188. };
  189. const refundLabel = (value: string) => {
  190. return refundStatusMap.value.find((item: any) => item.value === value)?.label
  191. }
  192. const refundStyle = (value: string) => {
  193. let rf = refundStatusMap.value.find((item: any) => item.value === value);
  194. return setupLabelColorStyle(rf?.color)
  195. }
  196. const setupLabelColorStyle = (hex: string = "#000000", opacity = 0.2) => {
  197. if (!hex) {
  198. hex = "#000000"
  199. }
  200. hex = hex.replace("#", "");
  201. // Convert the hex value to RGB values
  202. const r = parseInt(hex.substring(0, 2), 16);
  203. const g = parseInt(hex.substring(2, 4), 16);
  204. const b = parseInt(hex.substring(4, 6), 16);
  205. return {
  206. /* 'text-shadow': `2px 2px 3px rgba(${r},${g},${b},${opacity})`,
  207. 'background-color': `rgba(${r},${g},${b},${opacity})`,*/
  208. 'color': `rgb(${r},${g},${b})`
  209. }
  210. }
  211. const changeTab = (index: number) => {
  212. tab.value = tabs.value[index].value;
  213. loadData();
  214. /* if (tab.value === 2) {
  215. let user = getApp<any>().globalData.user;
  216. if (user) {
  217. listRefund({userId: user.id,pageSize:1000}).then((res: any) => {
  218. console.log(res)
  219. let dataList = (res.list || []).map(item => {
  220. item.amount = (Number(item.refund) / 100).toFixed(2);
  221. item.type = 2;
  222. if (item.successTime) {
  223. item.transactionTime = item.successTime.slice(0, 3).join("-") + " " + item.successTime.slice(3, 6).join(":")
  224. }
  225. return item;
  226. })
  227. infiniteScroller.setList(dataList);
  228. })
  229. } else {
  230. infiniteScroller.refresh();
  231. }
  232. }*/
  233. }
  234. const loadData = () => {
  235. if (!user) return;
  236. if (tab.value !== 2) {
  237. fetchWallet(tab.value, 1, 1000).then((res: any) => {
  238. if (res && res.length) {
  239. res.forEach((item: any) => {
  240. item.amount = (Number(item.amount) / 100).toFixed(2);
  241. });
  242. }
  243. dataList.value = res;
  244. });
  245. } else {
  246. listRefund({userId: user.value.id, pageSize: 1000}).then((res: any) => {
  247. console.log(res)
  248. let list = (res.list || []).map(item => {
  249. item.amount = (Number(item.refund) / 100).toFixed(2);
  250. item.type = 2;
  251. if (item.successTime) {
  252. item.transactionTime = item.successTime.slice(0, 3).join("-") + " " + item.successTime.slice(3, 6).join(":")
  253. }
  254. return item;
  255. })
  256. dataList.value = list;
  257. })
  258. }
  259. }
  260. const detail = (index: number) => {
  261. if (!dataList.value) {
  262. return;
  263. }
  264. if (dataList.value[index].type === 3) {
  265. uni.navigateTo({
  266. url: `/pages-charge/order/order?id=${dataList.value[index]?.orderNo}`,
  267. });
  268. }
  269. };
  270. </script>
  271. <style lang="scss">
  272. .page {
  273. height: 100vh;
  274. width: 100vw;
  275. background: linear-gradient(
  276. 180deg,
  277. #d9efec 0%,
  278. rgba(255, 255, 255, 0) 60.13%
  279. );
  280. .head {
  281. padding: 30rpx 40rpx;
  282. & > view {
  283. position: relative;
  284. height: 320rpx;
  285. border-radius: 40rpx;
  286. overflow: hidden;
  287. .bg {
  288. height: 100%;
  289. width: 100%;
  290. }
  291. .fg {
  292. position: absolute;
  293. left: 0px;
  294. top: 0px;
  295. height: 100%;
  296. width: 100%;
  297. .btn {
  298. width: 120rpx;
  299. height: 64rpx;
  300. border-radius: 40rpx;
  301. background: rgba(255, 255, 255, 0.3);
  302. color: var(--color-primary-deep);
  303. }
  304. }
  305. }
  306. }
  307. .body {
  308. .tabs {
  309. padding: 0 40rpx;
  310. & > view {
  311. position: relative;
  312. height: 72rpx;
  313. .active {
  314. position: absolute;
  315. left: 50%;
  316. bottom: 0px;
  317. transform: translateX(-50%);
  318. width: 40rpx;
  319. height: 4rpx;
  320. border-radius: 4rpx;
  321. background-color: var(--color-primary);
  322. }
  323. }
  324. }
  325. .list {
  326. .item {
  327. height: 130rpx;
  328. border-bottom: 1rpx solid rgba(0, 0, 0, 0.1);
  329. &:last-child {
  330. border-bottom: none;
  331. }
  332. }
  333. }
  334. }
  335. }
  336. .refund-status {
  337. display: inline-block;
  338. //padding: 8rpx;
  339. font-size: 22rpx;
  340. font-weight: 500;
  341. }
  342. </style>