cwg-sidebar.vue 14 KB

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