cwg-payment.vue 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334
  1. <template>
  2. <view class="notice-container">
  3. <cwg-dropdown ref="dropdownRef" :menu-list="[]" @menuClick="handleMenuClick">
  4. <view class="pc-header-btn pc-payment-btn">
  5. <cwg-icon name="crm-payment" color="#141d22" @click="openNotice" />
  6. <text class="balance-text">{{ formattedBalance }} USD</text>
  7. </view>
  8. <template #btn>
  9. <view class="right-drawer custom-payment-drawer">
  10. <view class="drawer-header">
  11. <text class="drawer-title">隐藏余额</text>
  12. <switch :checked="!isShow" @change="toggleShow" color="#6c8595" style="transform:scale(0.7)" />
  13. </view>
  14. <view class="drawer-content">
  15. <view class="balance-amount">{{ formattedBalance }} USD</view>
  16. <view class="account-type">交易账户</view>
  17. <view class="account-number">#{{ userStore.userInfo.customInfo?.cId || '--' }}</view>
  18. </view>
  19. <view class="drawer-actions">
  20. <button class="action-btn" @click.stop="goPages(1)">转账</button>
  21. <button class="action-btn" @click.stop="goPages(2)">出金</button>
  22. </view>
  23. </view>
  24. </template>
  25. </cwg-dropdown>
  26. </view>
  27. </template>
  28. <script setup lang="ts">
  29. import { computed, ref, onMounted } from 'vue'
  30. import { newsApi } from '@/service/news'
  31. import useRouter from "@/hooks/useRouter";
  32. import { drawApi } from "@/service/draw";
  33. import { useI18n } from 'vue-i18n'
  34. import useUserStore from '@/stores/use-user-store'
  35. const { t, locale } = useI18n()
  36. const userStore = useUserStore()
  37. import { userToken } from "@/composables/config";
  38. const isRed = ref(false)
  39. const dropdownRef = ref(null)
  40. const close = () => {
  41. dropdownRef.value.close()
  42. }
  43. const router = useRouter();
  44. const menuList = []
  45. const customMenuList = computed(() =>
  46. [{
  47. label: t('wallet.item6'),
  48. type: 1
  49. },
  50. {
  51. label: t('wallet.item7'),
  52. type: 2
  53. },
  54. ])
  55. const handleMenuClick = ({ value }) => {
  56. goPages(value)
  57. }
  58. const NumberDecimal = (value) => {
  59. let realVal = ''
  60. if (!isNaN(value) && value !== '') {
  61. // 截取当前数据到小数点后两位
  62. realVal = parseFloat(value).toFixed(2)
  63. } else {
  64. realVal = '0'
  65. }
  66. return realVal
  67. };
  68. const NumberDesensitization = (value) => {
  69. let realVal = ''
  70. if (!isNaN(value) && value !== '') {
  71. value = value.toString();
  72. realVal = value.substr(0, 2) + '****' + value.substr(-2);
  73. } else {
  74. realVal = '--'
  75. }
  76. return realVal
  77. };
  78. const isShow = ref(true)
  79. const walletbalance = ref(0)
  80. const pendingWithdrawAmount = ref(0)
  81. const formattedBalance = computed(() => {
  82. const value = walletbalance.value || "0"
  83. const decimalValue = NumberDecimal(value)
  84. return isShow.value ? decimalValue : NumberDesensitization(decimalValue)
  85. })
  86. const formattedPendingWithdrawAmount = computed(() => {
  87. const value = pendingWithdrawAmount.value || "0"
  88. const decimalValue = NumberDecimal(value)
  89. return isShow.value ? decimalValue : NumberDesensitization(decimalValue)
  90. })
  91. const getWalletList = async () => {
  92. let res = await drawApi.walletbalance({});
  93. if (res.code == 200) {
  94. if (res.data != null) {
  95. walletbalance.value = res.data;
  96. }
  97. } else {
  98. uni.showToast({
  99. title: res.msg,
  100. icon: 'none'
  101. });
  102. }
  103. }
  104. //获取处理中出金金额
  105. const getPendingWithdrawAmount = async () => {
  106. let res = await drawApi.pendingWithdrawAmount({});
  107. if (res.code == 200) {
  108. if (res.data != null) {
  109. pendingWithdrawAmount.value = res.data;
  110. }
  111. } else {
  112. uni.showToast({
  113. title: res.msg,
  114. icon: 'none'
  115. });
  116. }
  117. }
  118. const toggleShow = (e) => {
  119. isShow.value = !e.detail.value
  120. }
  121. const goPages = (type) => {
  122. let path
  123. if (type == 1) {
  124. path = '/pages/customer/wallet-transfer'
  125. } else if (type == 2) {
  126. path = '/pages/customer/wallet-history' // 此处根据实际“出金”路由修改
  127. }
  128. router.push(path)
  129. close()
  130. }
  131. const goMore = () => {
  132. router.push({
  133. path: '/pages/common/notice'
  134. })
  135. close()
  136. }
  137. onMounted(() => {
  138. if (!userToken.value) return
  139. getWalletList()
  140. getPendingWithdrawAmount()
  141. })
  142. </script>
  143. <style scoped lang="scss">
  144. @import "@/uni.scss";
  145. .notice-container {
  146. :deep(.cwg-dropdown-menu-container) {
  147. //left: px2rpx(-280) !important;
  148. //right: px2rpx(0) !important;
  149. }
  150. @media screen and (max-width: 991px) {
  151. :deep(.cwg-dropdown-menu-container) {
  152. left: px2rpx(-270) !important;
  153. //max-width: px2rpx(400);
  154. }
  155. }
  156. .pc-header-btn {
  157. position: relative;
  158. width: fit-content;
  159. display: flex;
  160. align-items: center;
  161. justify-content: center;
  162. padding: 0 px2rpx(12);
  163. &.has-dot::after {
  164. content: '';
  165. position: absolute;
  166. top: px2rpx(4);
  167. right: px2rpx(4);
  168. width: px2rpx(8);
  169. height: px2rpx(8);
  170. background-color: #f56c6c;
  171. border-radius: 50%;
  172. }
  173. }
  174. .pc-payment-btn {
  175. background-color: #e4e9ec;
  176. border: 1px solid #141d22;
  177. border-radius: px2rpx(4);
  178. padding: px2rpx(4) px2rpx(12);
  179. height: px2rpx(36);
  180. cursor: pointer;
  181. .balance-text {
  182. margin-left: px2rpx(6);
  183. font-size: px2rpx(14);
  184. font-weight: 500;
  185. color: #141d22;
  186. }
  187. }
  188. .custom-payment-drawer {
  189. width: px2rpx(260);
  190. background-color: var(--color-white);
  191. padding: 0;
  192. border-radius: px2rpx(8);
  193. box-shadow: 0 4px 12px rgba(0,0,0,0.1);
  194. .drawer-header {
  195. display: flex;
  196. justify-content: space-between;
  197. align-items: center;
  198. padding: px2rpx(12) px2rpx(16);
  199. border-bottom: 1px solid #f0f0f0;
  200. .drawer-title {
  201. font-size: px2rpx(14);
  202. color: #333;
  203. }
  204. }
  205. .drawer-content {
  206. padding: px2rpx(20) px2rpx(16);
  207. .balance-amount {
  208. font-size: px2rpx(18);
  209. font-weight: bold;
  210. color: #141d22;
  211. margin-bottom: px2rpx(8);
  212. }
  213. .account-type {
  214. font-size: px2rpx(13);
  215. color: #666;
  216. margin-bottom: px2rpx(4);
  217. }
  218. .account-number {
  219. font-size: px2rpx(13);
  220. color: #999;
  221. }
  222. }
  223. .drawer-actions {
  224. display: flex;
  225. gap: px2rpx(12);
  226. padding: 0 px2rpx(16) px2rpx(20);
  227. .action-btn {
  228. flex: 1;
  229. height: px2rpx(36);
  230. line-height: px2rpx(36);
  231. background-color: #f5f7fa;
  232. color: #333;
  233. font-size: px2rpx(13);
  234. border-radius: px2rpx(4);
  235. margin: 0;
  236. &::after {
  237. border: none;
  238. }
  239. &:active {
  240. background-color: #e4e7ed;
  241. }
  242. }
  243. }
  244. }
  245. .notification-list {
  246. width: 100%;
  247. }
  248. .notification-item {
  249. display: flex;
  250. align-items: center;
  251. justify-content: space-between;
  252. padding: px2rpx(12) px2rpx(16);
  253. border-bottom: 1px solid #f0f0f0;
  254. cursor: pointer;
  255. transition: all 0.3s;
  256. &:hover {
  257. background-color: rgba(0, 0, 0, 0.05);
  258. }
  259. .item-content {
  260. flex: 1;
  261. .item-title {
  262. font-size: px2rpx(14);
  263. color: #333;
  264. line-height: 1.4;
  265. margin-bottom: px2rpx(4);
  266. }
  267. .item-time {
  268. font-size: px2rpx(12);
  269. color: #999;
  270. }
  271. }
  272. .item-badge {
  273. margin-left: px2rpx(12);
  274. .dot {
  275. width: px2rpx(8);
  276. height: px2rpx(8);
  277. background-color: #f56c6c;
  278. border-radius: 50%;
  279. }
  280. }
  281. }
  282. .logout-wrap {
  283. margin-top: auto;
  284. padding: 20px 16px;
  285. margin-bottom: 20px;
  286. }
  287. .logout-btn {
  288. height: 44px;
  289. background: #f4eadf;
  290. display: flex;
  291. align-items: center;
  292. justify-content: center;
  293. gap: 8px;
  294. color: #ff9800;
  295. font-weight: 600;
  296. cursor: pointer;
  297. }
  298. }
  299. </style>