cwg-sidebar.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438
  1. <template>
  2. <view class="cwg-sidebar">
  3. <view class="wallet-widget">
  4. <view class="wallet-header" :class="{ 'header-bottom': isWalletOpen }"
  5. @click="isWalletOpen = !isWalletOpen">
  6. <view class="wallet-header-left">
  7. <cwg-icon name="crm-payment" :size="16" color="#141d22" />
  8. <text class="wallet-header-text">{{ mode === 'customer' ? formattedBalance : ibBalance }} USD</text>
  9. </view>
  10. <view class="wallet-header-right" :class="{ 'expanded': isWalletOpen }">
  11. <cwg-icon name="crm-chevron-down" :size="16" color="#6c8595" />
  12. </view>
  13. </view>
  14. <view class="wallet-body" v-if="isWalletOpen">
  15. <view class="wallet-body-header">
  16. <text class="drawer-title">隐藏余额</text>
  17. <switch :checked="!isShow" @change="toggleShow" color="#6c8595"
  18. style="transform:scale(0.7); margin-right: -10px;" />
  19. </view>
  20. <view class="wallet-body-content">
  21. <view class="balance-amount">{{ mode === 'customer' ? formattedBalance : ibBalance }} USD</view>
  22. <view class="wallet-type">{{ mode === 'customer' ? t('wallet.pendingWithdraw') :
  23. t('Ib.Index.TotalRevenue') }}</view>
  24. <view class="wallet-id-box">
  25. {{ mode === 'customer' ? formattedPendingWithdrawAmount : ibTotalBalance }}
  26. </view>
  27. </view>
  28. <view class="wallet-actions" v-if="mode === 'customer'">
  29. <button class="action-btn" @click.stop="goPages(1)" v-t="'wallet.item6'"></button>
  30. <button class="action-btn" @click.stop="goPages(2)" v-t="'wallet.item7'"></button>
  31. </view>
  32. <view class="wallet-actions" v-if="mode === 'ib'">
  33. <button class="action-btn" @click.stop="goIbPages(1)" v-t="'Custom.Index.Withdrawals'"></button>
  34. <button class="action-btn" @click.stop="goIbPages(2)" v-t="'Home.page_ib.item4'"></button>
  35. <!-- <button class="action-btn" @click.stop="goIbPages(3)" v-t="'Ib.Transfer.CommissionIssue'"></button>-->
  36. </view>
  37. </view>
  38. </view>
  39. <view class="menu-list">
  40. <view class="menu" v-for="(item, index) in menus" :key="item.path">
  41. <view class="menu-item" @click="handleClick(index)">
  42. <cwg-icon :name="item.icon" :size="20" color="#6c8595" />
  43. <view class="menu-label" v-t="item.label" />
  44. <view class="chevron-icon" :class="{ 'expanded': item.isOpenMenu }">
  45. <cwg-icon v-if="item.children && item.children.length" name="crm-chevron-down" :size="20"
  46. color="#6c8595" />
  47. </view>
  48. </view>
  49. <view :ref="(el) => setSubmenuRef(index, el)" class="submenu-box" :a="index" :key1="item.path + index"
  50. :b="item" :style="{
  51. height: !(item.children && item.children.length) ? '0px' : item.isOpenMenu ? item.submenuHeight + 'px' : '0px',
  52. transition: 'height 281ms cubic-bezier(0.4, 0, 0.2, 1)'
  53. }" :class="{ 'active': item.isOpenMenu }">
  54. <cwg-submenu v-if="item.children && item.children.length" :submenu-items="item.children"
  55. @submenu-click="handleClick1" />
  56. </view>
  57. </view>
  58. </view>
  59. <view class="menu fixed">
  60. <view class="menu-item ib-box" @click="setMode('ib')" v-if="mode !== 'ib' && ibStatus">
  61. <cwg-icon name="crm-ib" :size="20" color="#6c8595" />
  62. <view class="menu-label" v-t="'Home.msg.Ib'" />
  63. </view>
  64. <view class="menu-item ib-box" @click="setMode('customer')" v-if="mode !== 'customer'">
  65. <cwg-icon name="crm-trade" :size="20" color="#6c8595" />
  66. <view class="menu-label" v-t="'Home.msg.Custom'" />
  67. </view>
  68. </view>
  69. </view>
  70. </template>
  71. <script lang="ts" setup>
  72. import { ref, computed, watch, onMounted } from 'vue'
  73. import useUserStore from '@/stores/use-user-store'
  74. import { useMenuSplit } from '@/composables/useMenuSplit'
  75. import { storeToRefs } from 'pinia'
  76. import { drawApi } from '@/service/draw'
  77. import { ibApi } from '@/service/ib'
  78. import { userToken } from '@/composables/config'
  79. import useRouter from '@/hooks/useRouter'
  80. import { useI18n } from 'vue-i18n'
  81. const { t } = useI18n()
  82. const router = useRouter()
  83. const handleClick1 = (item: MenuItem) => {
  84. emit('handle-click', item)
  85. }
  86. const { menus, setSubmenuRef, setMode, handleClick, handleSubmenuClick, mode } = useMenuSplit(handleClick1)
  87. const userStore = useUserStore()
  88. const { userInfo } = storeToRefs(userStore)
  89. const emit = defineEmits(['handle-click'])
  90. // ib按钮展示
  91. const ibStatus = computed(() => {
  92. const info: any = userInfo.value
  93. return !!info && !!info.customInfo && info.customInfo.ibInvalid == 0 && !!info.ibInfo
  94. })
  95. const isWalletOpen = ref(true)
  96. const isShow = ref(true)
  97. const walletbalance = ref(0)
  98. const pendingWithdrawAmount = ref(0)
  99. const ibData = ref({} as any)
  100. const NumberDecimal = (value: any) => {
  101. let realVal = ''
  102. if (!isNaN(value) && value !== '') {
  103. realVal = parseFloat(value).toFixed(2)
  104. } else {
  105. realVal = '0.00'
  106. }
  107. return realVal
  108. }
  109. const NumberDesensitization = (value: any) => {
  110. let realVal = ''
  111. if (!isNaN(value) && value !== '') {
  112. value = value.toString()
  113. realVal = value.substr(0, 2) + '****' + value.substr(-2)
  114. } else {
  115. realVal = '--'
  116. }
  117. return realVal
  118. }
  119. const formattedBalance = computed(() => {
  120. const value = walletbalance.value || '0'
  121. const decimalValue = NumberDecimal(value)
  122. return isShow.value ? decimalValue : NumberDesensitization(decimalValue)
  123. })
  124. const ibBalance = computed(() => {
  125. const value = NumberDecimal(ibData.value?.balance || 0)
  126. return isShow.value ? value : NumberDesensitization(value)
  127. })
  128. const formattedPendingWithdrawAmount = computed(() => {
  129. const value = pendingWithdrawAmount.value || '0'
  130. const decimalValue = NumberDecimal(value)
  131. return isShow.value ? decimalValue : NumberDesensitization(decimalValue)
  132. })
  133. const ibTotalBalance = computed(() => {
  134. const value = NumberDecimal(ibData.value?.all || 0)
  135. return isShow.value ? value : NumberDesensitization(value)
  136. })
  137. const getWalletList = async () => {
  138. let res = await drawApi.walletbalance({})
  139. if (res.code == 200) {
  140. if (res.data != null) {
  141. walletbalance.value = res.data
  142. }
  143. } else {
  144. uni.showToast({ title: res.msg, icon: 'none' })
  145. }
  146. }
  147. //获取处理中出金金额
  148. const getPendingWithdrawAmount = async () => {
  149. let res = await drawApi.pendingWithdrawAmount({})
  150. if (res.code == 200) {
  151. if (res.data != null) {
  152. pendingWithdrawAmount.value = res.data
  153. }
  154. } else {
  155. uni.showToast({
  156. title: res.msg,
  157. icon: 'none',
  158. })
  159. }
  160. }
  161. const getIbData = async () => {
  162. const res = await ibApi.IbData()
  163. if (res.code === 200) {
  164. if (res.data != null) ibData.value = res.data
  165. } else {
  166. uni.showToast({ title: res.msg, icon: 'none' })
  167. }
  168. }
  169. watch(() => mode.value, (newMode) => {
  170. if (!userToken.value) return
  171. if (newMode == 'customer') {
  172. getWalletList()
  173. getPendingWithdrawAmount()
  174. } else if (newMode == 'ib') {
  175. getIbData()
  176. }
  177. }, { immediate: true })
  178. const toggleShow = (e: any) => {
  179. isShow.value = !e.detail.value
  180. }
  181. const goPages = (type: number) => {
  182. let path = ''
  183. if (type == 1) {
  184. path = '/pages/customer/wallet-transfer'
  185. } else if (type == 2) {
  186. path = '/pages/customer/wallet-history'
  187. }
  188. if (path) router.push(path)
  189. }
  190. const goIbPages = (type: number) => {
  191. let path = ''
  192. let query = {}
  193. if (type == 1) {
  194. path = '/pages/ib/withdraw-select'
  195. } else if (type == 2) {
  196. path = '/pages/ib/transfer'
  197. } else if (type == 3) {
  198. path = '/pages/ib/transfer'
  199. query = { tab: 2 }
  200. }
  201. if (path) router.push({ path, query })
  202. }
  203. </script>
  204. <style scoped lang="scss">
  205. @import "@/uni.scss";
  206. .cwg-sidebar {
  207. width: px2rpx(280);
  208. color: #6c8595;
  209. height: calc(100vh - 56px);
  210. overflow: auto;
  211. display: flex;
  212. flex-direction: column;
  213. align-items: center;
  214. padding: px2rpx(8);
  215. padding-top: px2rpx(20);
  216. box-sizing: border-box;
  217. gap: px2rpx(8);
  218. border-right: 1px solid rgba(108, 133, 149, 0.12);
  219. .wallet-widget {
  220. width: 100%;
  221. //border-radius: px2rpx(4);
  222. border-top: 1px solid rgba(108, 133, 149, 0.12);
  223. border-bottom: 1px solid rgba(108, 133, 149, 0.12);
  224. overflow: hidden;
  225. margin-bottom: px2rpx(4);
  226. .header-bottom {
  227. border-bottom: 1px solid rgba(108, 133, 149, 0.12);
  228. }
  229. .wallet-header {
  230. display: flex;
  231. align-items: center;
  232. justify-content: space-between;
  233. padding: px2rpx(10) px2rpx(12);
  234. //background: #f4f6f8;
  235. cursor: pointer;
  236. .wallet-header-left {
  237. display: flex;
  238. align-items: center;
  239. gap: px2rpx(8);
  240. }
  241. .wallet-header-text {
  242. font-size: 14px;
  243. color: #141d22;
  244. font-weight: 500;
  245. }
  246. .wallet-header-right {
  247. transition: transform 0.3s;
  248. &.expanded {
  249. transform: rotate(180deg);
  250. }
  251. }
  252. }
  253. .wallet-body {
  254. padding: px2rpx(12);
  255. background: #ffffff;
  256. .wallet-body-header {
  257. display: flex;
  258. align-items: center;
  259. justify-content: space-between;
  260. margin-bottom: px2rpx(12);
  261. .drawer-title {
  262. font-size: 13px;
  263. color: #6c8595;
  264. }
  265. }
  266. .wallet-body-content {
  267. margin-bottom: px2rpx(16);
  268. .balance-amount {
  269. font-size: 16px;
  270. font-weight: 600;
  271. color: #141d22;
  272. margin-bottom: px2rpx(4);
  273. }
  274. .wallet-type {
  275. font-size: 12px;
  276. color: #999;
  277. margin-bottom: px2rpx(4);
  278. }
  279. .wallet-id-box {
  280. display: flex;
  281. align-items: center;
  282. gap: px2rpx(4);
  283. .wallet-id {
  284. font-size: 12px;
  285. color: #999;
  286. }
  287. }
  288. }
  289. .wallet-actions {
  290. display: flex;
  291. gap: px2rpx(8);
  292. .action-btn {
  293. flex: 1;
  294. height: px2rpx(32);
  295. line-height: px2rpx(32);
  296. background-color: #f5f7fa;
  297. color: #141d22;
  298. font-size: 13px;
  299. border-radius: px2rpx(4);
  300. margin: 0;
  301. &::after {
  302. border: none;
  303. }
  304. &:active {
  305. background-color: #e4e7ed;
  306. }
  307. }
  308. }
  309. }
  310. }
  311. .logo {
  312. width: px2rpx(54);
  313. }
  314. .menu-list {
  315. flex: 1;
  316. width: 100%;
  317. overflow-y: auto;
  318. display: flex;
  319. flex-direction: column;
  320. gap: px2rpx(8);
  321. }
  322. .submenu-box {
  323. width: 100%;
  324. height: 0;
  325. overflow: hidden;
  326. }
  327. .menu {
  328. width: 100%;
  329. position: relative;
  330. display: flex;
  331. flex-direction: column;
  332. align-items: center;
  333. box-sizing: border-box;
  334. }
  335. .menu-item {
  336. width: 100%;
  337. height: px2rpx(40);
  338. cursor: pointer;
  339. display: flex;
  340. align-items: center;
  341. justify-content: space-between;
  342. gap: px2rpx(8);
  343. padding: px2rpx(10);
  344. box-sizing: border-box;
  345. font-size: 14px;
  346. .menu-label {
  347. flex: 1;
  348. }
  349. &:hover {
  350. background: rgba(108, 133, 149, 0.12) !important;
  351. border: 1px solid rgb(145, 163, 176) !important;
  352. border-radius: px2rpx(4);
  353. }
  354. .expanded .icon {
  355. transform: rotate(180deg);
  356. }
  357. }
  358. .ib-box {
  359. background: rgba(140, 69, 246, 0.08) !important;
  360. border: 1px solid rgba(140, 69, 246, 0.2) !important;
  361. font-size: px2rpx(18);
  362. font-weight: 600;
  363. color: #141d22;
  364. &:hover {
  365. background: rgba(140, 69, 246, 0.08) !important;
  366. border: 1px solid rgba(140, 69, 246, 0.2) !important;
  367. }
  368. }
  369. .zy-box {
  370. display: flex;
  371. align-items: center;
  372. justify-content: center;
  373. }
  374. .fixed {
  375. position: relative;
  376. width: 100%;
  377. display: flex;
  378. align-items: center;
  379. justify-content: center;
  380. gap: px2rpx(8);
  381. }
  382. }
  383. </style>