AccountList.vue 10 KB

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