AccountList.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381
  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" @action="handleAction"
  15. @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: '真实' },
  56. { id: 'demo', name: '模拟' }
  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 = ['真实', 'MT4', 'Standard'];
  193. labels[0] = cativeIndex.value == 1 ? '模拟' : '真实';
  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. padding: px2rpx(16);
  228. box-sizing: border-box;
  229. }
  230. .tabs-class {
  231. width: px2rpx(200);
  232. margin: px2rpx(20) 0;
  233. }
  234. .content-title {
  235. display: flex;
  236. justify-content: space-between;
  237. align-items: center;
  238. font-size: px2rpx(20);
  239. font-weight: 500;
  240. color: var(--color-slate-800);
  241. background-color: rgba(255, 255, 255, 0);
  242. .content-title-btns {
  243. display: flex;
  244. align-items: center;
  245. justify-content: center;
  246. gap: px2rpx(12);
  247. .btn-primary {
  248. min-width: px2rpx(120);
  249. background-color: var(--color-error);
  250. color: var(--color-slate-150);
  251. padding: 0 px2rpx(12);
  252. border: none;
  253. font-size: px2rpx(14);
  254. text-align: center;
  255. cursor: pointer;
  256. display: flex;
  257. align-items: center;
  258. justify-content: center;
  259. gap: px2rpx(8);
  260. }
  261. .btn-primary1 {
  262. background-color: var(--color-navy-700);
  263. }
  264. }
  265. }
  266. .operation-btn {
  267. :deep(span) {
  268. display: flex;
  269. align-items: center;
  270. justify-content: center;
  271. gap: px2rpx(4);
  272. cursor: pointer;
  273. background-color: var(--color-slate-150);
  274. padding: px2rpx(8) 0;
  275. }
  276. }
  277. .operation-btn.disabled {
  278. cursor: not-allowed;
  279. opacity: 0.5;
  280. }
  281. .search-bar {
  282. display: flex;
  283. align-items: center;
  284. justify-content: flex-start;
  285. flex-wrap: wrap;
  286. gap: px2rpx(16);
  287. margin: px2rpx(16) 0;
  288. .cwg-combox,
  289. .uni-easyinput,
  290. .uni-date {
  291. width: px2rpx(240) !important;
  292. flex: none;
  293. }
  294. }
  295. .expand-btn {
  296. display: flex;
  297. align-items: center;
  298. justify-self: center;
  299. gap: 4px;
  300. cursor: pointer;
  301. width: px2rpx(32);
  302. height: px2rpx(32);
  303. justify-content: center;
  304. .icon {
  305. transition: transform 0.3s ease;
  306. }
  307. &:hover {
  308. background-color:
  309. color-mix(in oklab, var(--color-slate-300) 20%, transparent);
  310. }
  311. &.expanded {
  312. background-color:
  313. color-mix(in oklab, var(--color-slate-300) 20%, transparent);
  314. }
  315. &.expanded .icon {
  316. transform: rotate(180deg);
  317. }
  318. }
  319. .action-buttons {
  320. display: flex;
  321. flex-wrap: wrap;
  322. gap: px2rpx(8);
  323. justify-content: flex-end;
  324. padding: px2rpx(16) px2rpx(20);
  325. background-color: var(--color-slate-100);
  326. .action-btn {
  327. display: inline-flex;
  328. align-items: center;
  329. height: px2rpx(24);
  330. padding: 0 px2rpx(16);
  331. border: none;
  332. background-color: var(--color-secondary-focus);
  333. color: var(--color-white);
  334. font-size: px2rpx(13);
  335. font-weight: 500;
  336. cursor: pointer;
  337. transition: all 0.2s ease;
  338. .icon {
  339. margin-right: px2rpx(4);
  340. }
  341. }
  342. .action-btn.disabled {
  343. cursor: not-allowed;
  344. opacity: 0.5;
  345. }
  346. }
  347. </style>