AccountList.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494
  1. <template>
  2. <view class="account-card">
  3. <view class="content-title">
  4. <view v-t="'Custom.Index.AccountList'"></view>
  5. <view class="content-title-btns">
  6. <view class="btn-primary btn-primary1" @click="createAccount()">
  7. <cwg-icon icon="crm-plus" :size="16" color="#fff" />
  8. <text v-t="'Custom.Index.AddAccount'" />
  9. </view>
  10. </view>
  11. </view>
  12. <view class="tabs-container">
  13. <view class="tabs-class">
  14. <cwg-tabs v-model:cativeIndex="cativeIndex" :tabs="tabs" />
  15. </view>
  16. <view class="btn-class">
  17. <view class="btn-primary" :class="{ 'btn-primary2': isGridLayout }"
  18. @click="isGridLayout || toggleLayout()">
  19. <cwg-icon icon="crm-card" :size="16" color="#141d2299" />
  20. </view>
  21. <view class="btn-primary" :class="{ 'btn-primary2': !isGridLayout }"
  22. @click="!isGridLayout || toggleLayout()">
  23. <cwg-icon icon="crm-list" :size="16" color="#141d2299" />
  24. </view>
  25. </view>
  26. </view>
  27. <view v-if="accounts.length" :class="{ 'grid-layout': isGridLayout }">
  28. <AccountCard v-for="acc in accounts" :zhtype="cativeIndex" :key="acc.accountNumber" :account="acc"
  29. :is-grid-layout="isGridLayout" @action="handleAction" @copy="handleCopy"
  30. @change-password="handleChangePassword" />
  31. </view>
  32. <view class="table-loading-mask">
  33. <uni-loading v-if="loading" />
  34. </view>
  35. <cwg-empty-state v-if="!loading && accounts.length == 0" />
  36. <DeleteAccountDialogs ref="deleteAccountDialogRef" v-model:visible="deleteAccountDialogVisible" />
  37. </view>
  38. </template>
  39. <script setup lang="ts">
  40. import { computed, ref, onMounted, watch } from 'vue';
  41. import { useI18n } from 'vue-i18n';
  42. const { t, locale } = useI18n();
  43. import useRouter from "@/hooks/useRouter";
  44. const router = useRouter();
  45. import { customApi } from '@/service/custom';
  46. import { userApi } from '@/api/user';
  47. import useUserStore from "@/stores/use-user-store";
  48. const userStore = useUserStore();
  49. import AccountCard from './AccountCard.vue'
  50. import DeleteAccountDialogs from './DeleteAccountDialogs.vue'
  51. import { useFilters } from '@/composables/useFilters'
  52. const { numberFormat, numberDecimal } = useFilters()
  53. const search = ref({ platform: 'MT4' })
  54. const isAfterJuly28 = () => {
  55. const now = new Date();
  56. const july28 = new Date(2025, 6, 28, 0, 0, 0); // 月份从0开始,所以7月是6
  57. return now >= july28;
  58. }
  59. const handleAction = (type) => { /* 处理交易/入金等 */ };
  60. const handleCopy = (text: string) => {
  61. uni.setClipboardData({
  62. data: text,
  63. success: function () {
  64. uni.showToast({
  65. title: t('Btn.item8'),
  66. icon: 'none',
  67. duration: 2000
  68. });
  69. }
  70. });
  71. }
  72. const handleChangePassword = () => { /* 跳转修改密码 */ };
  73. const typeMap = computed(() => ({
  74. 1: t('AccountType.ClassicAccount'),
  75. 2: t('AccountType.SeniorAccount'),
  76. 3: !isAfterJuly28() ? t('AccountType.AgencyAccount') : '',
  77. 5: t('AccountType.SpeedAccount'),
  78. 6: t('AccountType.SpeedAccount'),
  79. 7: t('AccountType.StandardAccount'),
  80. 8: t('AccountType.CentAccount')
  81. }));
  82. const cativeIndex = ref(0)
  83. const isGridLayout = ref(true)
  84. const tabs = computed(() => ([
  85. { id: 'real', name: t('vu.item1') },
  86. { id: 'demo', name: t('vu.item2') }
  87. ]))
  88. const toggleLayout = () => {
  89. isGridLayout.value = !isGridLayout.value
  90. }
  91. const tableRef = ref(null)
  92. const expanded = ref(null)
  93. const toggleRowExpand = (row) => {
  94. expanded.value = row.expanded ? row.rowIndex : null
  95. }
  96. const toggleExpand = (index) => {
  97. tableRef?.value.toggleRowExpand(index)
  98. }
  99. const createActionButtons = (row) => {
  100. console.log(row, 'row');
  101. return computed(() => [
  102. {
  103. icon: 'crm-circle-dollar-to-slot',
  104. text: t('Custom.Index.Deposit'),
  105. action: 'deposit',
  106. disabled: row.closeFunctions?.indexOf('1') !== -1,
  107. show: true,
  108. class: 'deposit-btn'
  109. },
  110. {
  111. icon: 'crm-credit-card',
  112. text: t('Custom.Index.Withdrawals'),
  113. action: 'withdraw',
  114. disabled: row.closeFunctions?.indexOf('2') !== -1,
  115. show: true,
  116. class: 'withdraw-btn'
  117. },
  118. {
  119. icon: 'crm-money-bill-transfer',
  120. text: t('Custom.Index.Transfer'),
  121. action: 'transfer',
  122. disabled: (
  123. row.closeFunctions?.indexOf('5') !== -1 ||
  124. row.closeFunctions?.indexOf('6') !== -1 ||
  125. row.closeFunctions?.indexOf('3') !== -1
  126. ),
  127. show: true,
  128. class: 'transfer-btn'
  129. },
  130. {
  131. icon: 'crm-gear',
  132. text: t('Custom.Index.Settings'),
  133. action: 'settings',
  134. disabled: row.closeFunctions?.indexOf('4') !== -1,
  135. show: true,
  136. class: 'settings-btn'
  137. },
  138. {
  139. icon: 'crm-award',
  140. text: t('standardRebate.item1'),
  141. action: 'standardRebate',
  142. disabled: false,
  143. show: row.type === 7,
  144. class: 'rebate-btn'
  145. }
  146. ])
  147. }
  148. // 处理按钮点击
  149. const handleActionBtn = (action, row) => {
  150. switch (action) {
  151. case 'deposit':
  152. toDeposit(row)
  153. break
  154. case 'withdraw':
  155. toWithdraw(row)
  156. break
  157. case 'transfer':
  158. toTransfer(row)
  159. break
  160. case 'settings':
  161. toSettings(row)
  162. break
  163. case 'standardRebate':
  164. toStandardRebate(row)
  165. break
  166. }
  167. }
  168. const deleteAccountDialogVisible = ref(false)
  169. const openDeleteAccountDialogs = () => {
  170. deleteAccountDialogVisible.value = true
  171. }
  172. const createAccount = () => {
  173. getCustomLoginInfo()
  174. }
  175. const isZh = computed(() => ['cn', 'zh', 'zhHant'].includes(locale.value));
  176. watch(cativeIndex, (newVal) => {
  177. // search.value.platform = tabs.value[newVal].id
  178. getAccountList()
  179. })
  180. const loading = ref(false)
  181. // 获取客户登录信息
  182. async function getCustomLoginInfo() {
  183. try {
  184. const res = await userApi.getUserInfo();
  185. userStore.saveUserInfo(res.data);
  186. if (res.code === 200) {
  187. if (
  188. res.data.customInfo.status == 2 &&
  189. res.data.customInfo.applyRealStatus == 2
  190. ) {
  191. router.push(`/pages/customer/account-select?server=${cativeIndex.value == 1 ? 'demo' : 'real'}`)
  192. } else {
  193. // this.dialogCheck = true;
  194. }
  195. }
  196. } catch (error) {
  197. // console.log(error, 111);
  198. }
  199. }
  200. const AccountList = ref([])
  201. const getAccountList = async () => {
  202. AccountList.value = []
  203. loading.value = true
  204. const api = cativeIndex.value == 1 ? customApi.demoList : customApi.AccountAllList
  205. const res = await api({
  206. page: {
  207. current: 1,
  208. size: 100
  209. }
  210. })
  211. if (res.code === 200) {
  212. AccountList.value = res.data
  213. }
  214. loading.value = false
  215. }
  216. // 格式化数值函数
  217. function formatMoney(value) {
  218. if (value === null || value === undefined) value = 0;
  219. const sign = value >= 0 ? '' : '-';
  220. const absoluteValue = Math.abs(value);
  221. return sign + '$' + absoluteValue.toFixed(2);
  222. }
  223. // 转换数组
  224. const accounts = computed(() =>
  225. AccountList.value && AccountList.value.length != 0 ? AccountList.value.map((acc, index) => {
  226. const currency = acc.currency || 'USD';
  227. const floating = acc.floating ?? 0;
  228. let labels = [t('vu.item1'), 'MT4', 'Standard'];
  229. labels[0] = cativeIndex.value == 1 ? t('vu.item2') : t('vu.item1');
  230. labels[1] = acc.platform || 'MT4';
  231. labels[2] = typeMap.value[acc.type];
  232. let nickname = typeMap.value[acc.type];
  233. let fwq = acc.platform == 'MT4' ? 'MT4 CWGMarketsLtd-Live' : 'MT5 CWGMarketsSVG-Live';
  234. const balance = acc.balance
  235. return {
  236. ...acc,
  237. labels,
  238. isExpanded: index == 0,
  239. balance,
  240. accountNumber: acc.login.toString(),
  241. nickname,
  242. fwq,
  243. balanceWithSymbol: acc.balanceWithSymbol ?? '$0', // 余额
  244. creditWithSymbol: acc.creditWithSymbol ?? '$0',//信用
  245. equityWithSymbol: acc.equityWithSymbol ?? '$0',//净值
  246. currency,
  247. actualLeverage: '1:' + (acc.leverage ?? 0), // 实际杠杆
  248. floatingPL: formatMoney(floating), // 盈亏
  249. platform: acc.platform || 'MT4',
  250. server: acc.groupCode || '',
  251. login: acc.login.toString(),
  252. listType: cativeIndex.value == 1 ? 'demo' : 'real'
  253. };
  254. }) : []
  255. )
  256. onMounted(async () => {
  257. await getAccountList()
  258. })
  259. </script>
  260. <style scoped lang="scss">
  261. @import "@/uni.scss";
  262. .account-card {
  263. width: 100%;
  264. background-color: var(--color-white);
  265. box-sizing: border-box;
  266. }
  267. .tabs-container {
  268. display: flex;
  269. justify-content: space-between;
  270. align-items: center;
  271. gap: px2rpx(12);
  272. .tabs-class {
  273. width: px2rpx(200);
  274. margin: px2rpx(20) 0;
  275. }
  276. .btn-primary {
  277. width: px2rpx(26);
  278. height: px2rpx(26);
  279. border-radius: px2rpx(2);
  280. border: none;
  281. font-size: px2rpx(14);
  282. text-align: center;
  283. cursor: pointer;
  284. display: flex;
  285. align-items: center;
  286. justify-content: center;
  287. gap: px2rpx(8);
  288. }
  289. .btn-primary2 {
  290. background-color: rgba(108, 133, 149, 0.08);
  291. }
  292. .btn-class {
  293. display: flex;
  294. justify-content: center;
  295. align-items: center;
  296. border: 1px solid #f3f4f6;
  297. font-size: px2rpx(14);
  298. height: px2rpx(34);
  299. text-align: center;
  300. cursor: pointer;
  301. display: flex;
  302. align-items: center;
  303. justify-content: center;
  304. gap: px2rpx(8);
  305. padding: px2rpx(4) px2rpx(8);
  306. box-sizing: border-box;
  307. }
  308. .btn-primary:active {}
  309. }
  310. .content-title {
  311. display: flex;
  312. justify-content: space-between;
  313. align-items: center;
  314. font-size: px2rpx(22);
  315. font-weight: 500;
  316. color: var(--color-slate-800);
  317. background-color: rgba(255, 255, 255, 0);
  318. .content-title-btns {
  319. display: flex;
  320. align-items: center;
  321. justify-content: center;
  322. gap: px2rpx(12);
  323. .btn-primary {
  324. min-width: px2rpx(120);
  325. background-color: var(--color-error);
  326. color: var(--color-slate-150);
  327. padding: 0 px2rpx(12);
  328. border: none;
  329. font-size: px2rpx(14);
  330. text-align: center;
  331. cursor: pointer;
  332. display: flex;
  333. align-items: center;
  334. justify-content: center;
  335. gap: px2rpx(8);
  336. }
  337. .btn-primary1 {
  338. background-color: var(--color-navy-700);
  339. }
  340. .btn-primary2 {
  341. background-color: var(--color-secondary-focus);
  342. }
  343. }
  344. }
  345. /* 网格布局样式 */
  346. .grid-layout {
  347. display: grid;
  348. grid-template-columns: repeat(auto-fill, minmax(25%, 1fr));
  349. gap: px2rpx(100);
  350. @media (max-width: 1200px) {
  351. grid-template-columns: repeat(auto-fill, minmax(33.33%, 1fr));
  352. }
  353. @media (max-width: 768px) {
  354. grid-template-columns: repeat(auto-fill, minmax(100%, 1fr));
  355. gap: px2rpx(20);
  356. }
  357. .account-card {
  358. margin-bottom: 0;
  359. height: 100%;
  360. display: flex;
  361. flex-direction: column;
  362. }
  363. .account-card .main-content {
  364. flex: 1;
  365. }
  366. }
  367. .operation-btn {
  368. :deep(span) {
  369. display: flex;
  370. align-items: center;
  371. justify-content: center;
  372. gap: px2rpx(4);
  373. cursor: pointer;
  374. background-color: var(--color-slate-150);
  375. padding: px2rpx(8) 0;
  376. }
  377. }
  378. .operation-btn.disabled {
  379. cursor: not-allowed;
  380. opacity: 0.5;
  381. }
  382. .search-bar {
  383. display: flex;
  384. align-items: center;
  385. justify-content: flex-start;
  386. flex-wrap: wrap;
  387. gap: px2rpx(16);
  388. margin: px2rpx(16) 0;
  389. .cwg-combox,
  390. .uni-easyinput,
  391. .uni-date {
  392. width: px2rpx(240) !important;
  393. flex: none;
  394. }
  395. }
  396. .expand-btn {
  397. display: flex;
  398. align-items: center;
  399. justify-self: center;
  400. gap: 4px;
  401. cursor: pointer;
  402. width: px2rpx(32);
  403. height: px2rpx(32);
  404. justify-content: center;
  405. .icon {
  406. transition: transform 0.3s ease;
  407. }
  408. &:hover {
  409. background-color:
  410. color-mix(in oklab, var(--color-slate-300) 20%, transparent);
  411. }
  412. &.expanded {
  413. background-color:
  414. color-mix(in oklab, var(--color-slate-300) 20%, transparent);
  415. }
  416. &.expanded .icon {
  417. transform: rotate(180deg);
  418. }
  419. }
  420. .action-buttons {
  421. display: flex;
  422. flex-wrap: wrap;
  423. gap: px2rpx(8);
  424. justify-content: flex-end;
  425. padding: px2rpx(16) px2rpx(20);
  426. background-color: var(--color-slate-100);
  427. .action-btn {
  428. display: inline-flex;
  429. align-items: center;
  430. height: px2rpx(24);
  431. padding: 0 px2rpx(16);
  432. border: none;
  433. background-color: var(--color-secondary-focus);
  434. color: var(--color-white);
  435. font-size: px2rpx(13);
  436. font-weight: 500;
  437. cursor: pointer;
  438. transition: all 0.2s ease;
  439. .icon {
  440. margin-right: px2rpx(4);
  441. }
  442. }
  443. .action-btn.disabled {
  444. cursor: not-allowed;
  445. opacity: 0.5;
  446. }
  447. }
  448. </style>