cwg-sidebar.vue 13 KB

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