AccountList.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381
  1. <template>
  2. <view class="container">
  3. <view class="row">
  4. <view class="col-12">
  5. <view class="border-0 card-header">
  6. <view class="d-flex flex-wrap gap-3 align-items-center justify-content-between mb-3">
  7. <h3 class="mb-0" style="align-self: flex-start" v-t="'Custom.Index.AccountList'"></h3>
  8. <button type="button" class="btn btn-danger btn-shadow waves-effect"
  9. @click="createAccount">
  10. <view class="d-flex align-items-center">
  11. <cwg-icon name="crm-plus" :size="14" color="#fff" />
  12. <text v-t="'Custom.Index.AddAccount'" />
  13. </view>
  14. </button>
  15. </view>
  16. </view>
  17. </view>
  18. <view class="col-lg-12">
  19. <view class="clearfix">
  20. <view class="card">
  21. <view class="card-header">
  22. <view class="nav nav-underline card-header-tabs">
  23. <view class="nav-item cwg-cursor" v-for="(tab, index) in tabs" :key="index"
  24. @click="handleTabClick(tab.value)">
  25. <view class="nav-link" :class="{ 'active': tab.value === cativeIndex }">{{ tab.text
  26. }}
  27. </view>
  28. </view>
  29. </view>
  30. </view>
  31. <view class="card-body">
  32. <view class="tab-content">
  33. <view class="row mb-4">
  34. <view class="col-lg-4 col-md-6"><cwg-combox v-model:value="platformActive"
  35. :clearable="false" :options="platformOptions" /></view>
  36. </view>
  37. <view class="row">
  38. <AccountCard v-for="acc in accounts" :zhtype="cativeIndex" :key="acc.accountNumber"
  39. :account="acc" :is-grid-layout="isGridLayout" @action="handleAction"
  40. @copy="handleCopy" @change-password="handleChangePassword" />
  41. <view class="table-loading-mask">
  42. <uni-loading v-if="loading" />
  43. </view>
  44. <view v-if="!loading && accounts.length == 0" class="list-empty-state col-12">
  45. <cwg-empty-state />
  46. </view>
  47. <DeleteAccountDialogs ref="deleteAccountDialogRef"
  48. v-model:visible="deleteAccountDialogVisible" />
  49. <cwg-improve-popup v-model:visible="dialogCheck" @confirm="confirm" />
  50. </view>
  51. </view>
  52. </view>
  53. </view>
  54. </view>
  55. </view>
  56. </view>
  57. </view>
  58. </template>
  59. <script setup lang="ts">
  60. import { computed, ref, onMounted, watch, onUnmounted } from 'vue';
  61. import { useI18n } from 'vue-i18n';
  62. const { t, locale } = useI18n();
  63. import useRouter from "@/hooks/useRouter";
  64. const router = useRouter();
  65. import { customApi } from '@/service/custom';
  66. import { userApi } from '@/api/user';
  67. import useUserStore from "@/stores/use-user-store";
  68. const userStore = useUserStore();
  69. import AccountCard from './AccountCard.vue'
  70. import DeleteAccountDialogs from './DeleteAccountDialogs.vue'
  71. import { useFilters } from '@/composables/useFilters'
  72. const { numberFormat, numberDecimal } = useFilters()
  73. const search = ref({ platform: 'MT4' })
  74. import useGlobalStore from '@/stores/use-global-store'
  75. const globalStore = useGlobalStore()
  76. const isDark = computed(() => globalStore.theme === 'dark')
  77. const isAfterJuly28 = () => {
  78. const now = new Date();
  79. const july28 = new Date(2025, 6, 28, 0, 0, 0); // 月份从0开始,所以7月是6
  80. return now >= july28;
  81. }
  82. const platformActive = ref('All')
  83. const platformOptions = computed(() => ([
  84. { value: 'All', text: t('State.All') },
  85. { value: 'MT4', text: 'MT4' },
  86. { value: 'MT5', text: 'MT5' },
  87. ]))
  88. const handleAction = (type) => { /* 处理交易/入金等 */ };
  89. const handleCopy = (text: string) => {
  90. uni.setClipboardData({
  91. data: text,
  92. success: function () {
  93. uni.showToast({
  94. title: t('Btn.item8'),
  95. icon: 'none',
  96. duration: 2000
  97. });
  98. }
  99. });
  100. }
  101. const handleChangePassword = () => { /* 跳转修改密码 */ };
  102. const typeMap = computed(() => ({
  103. 1: t('AccountType.ClassicAccount'),
  104. 2: t('AccountType.SeniorAccount'),
  105. 3: !isAfterJuly28() ? t('AccountType.AgencyAccount') : '',
  106. 5: t('AccountType.SpeedAccount'),
  107. 6: t('AccountType.SpeedAccount'),
  108. 7: t('AccountType.StandardAccount'),
  109. 8: t('AccountType.CentAccount')
  110. }));
  111. const cativeIndex = ref('real')
  112. const isGridLayout = ref(true)
  113. const tabs = computed(() => ([
  114. { value: 'real', text: t('vu.item1') },
  115. { value: 'demo', text: t('vu.item2') },
  116. { value: 'del', text: t('vu.account.item1') },
  117. ]))
  118. const toggleLayout = () => {
  119. isGridLayout.value = !isGridLayout.value
  120. }
  121. const tableRef = ref(null)
  122. const expanded = ref(null)
  123. const toggleRowExpand = (row) => {
  124. expanded.value = row.expanded ? row.rowIndex : null
  125. }
  126. const toggleExpand = (index) => {
  127. tableRef?.value.toggleRowExpand(index)
  128. }
  129. const createActionButtons = (row) => {
  130. console.log(row, 'row');
  131. return computed(() => [
  132. {
  133. icon: 'crm-circle-dollar-to-slot',
  134. text: t('Custom.Index.Deposit'),
  135. action: 'deposit',
  136. disabled: row.closeFunctions?.indexOf('1') !== -1,
  137. show: true,
  138. class: 'deposit-btn'
  139. },
  140. {
  141. icon: 'crm-credit-card',
  142. text: t('Custom.Index.Withdrawals'),
  143. action: 'withdraw',
  144. disabled: row.closeFunctions?.indexOf('2') !== -1,
  145. show: true,
  146. class: 'withdraw-btn'
  147. },
  148. {
  149. icon: 'crm-money-bill-transfer',
  150. text: t('Custom.Index.Transfer'),
  151. action: 'transfer',
  152. disabled: (
  153. row.closeFunctions?.indexOf('5') !== -1 ||
  154. row.closeFunctions?.indexOf('6') !== -1 ||
  155. row.closeFunctions?.indexOf('3') !== -1
  156. ),
  157. show: true,
  158. class: 'transfer-btn'
  159. },
  160. {
  161. icon: 'crm-gear',
  162. text: t('Custom.Index.Settings'),
  163. action: 'settings',
  164. disabled: row.closeFunctions?.indexOf('4') !== -1,
  165. show: true,
  166. class: 'settings-btn'
  167. },
  168. {
  169. icon: 'crm-award',
  170. text: t('standardRebate.item1'),
  171. action: 'standardRebate',
  172. disabled: false,
  173. show: row.type === 7,
  174. class: 'rebate-btn'
  175. }
  176. ])
  177. }
  178. // 处理按钮点击
  179. const handleActionBtn = (action, row) => {
  180. switch (action) {
  181. case 'deposit':
  182. toDeposit(row)
  183. break
  184. case 'withdraw':
  185. toWithdraw(row)
  186. break
  187. case 'transfer':
  188. toTransfer(row)
  189. break
  190. case 'settings':
  191. toSettings(row)
  192. break
  193. case 'standardRebate':
  194. toStandardRebate(row)
  195. break
  196. }
  197. }
  198. const deleteAccountDialogVisible = ref(false)
  199. const openDeleteAccountDialogs = () => {
  200. deleteAccountDialogVisible.value = true
  201. }
  202. const createAccount = () => {
  203. getCustomLoginInfo()
  204. }
  205. const isZh = computed(() => ['cn', 'zh', 'zhHant'].includes(locale.value));
  206. const loading = ref(false)
  207. let debounceTimer: ReturnType<typeof setTimeout> | null = null
  208. const handleTabClick = (value: string) => {
  209. if (loading.value) return
  210. if (debounceTimer) {
  211. clearTimeout(debounceTimer)
  212. }
  213. debounceTimer = setTimeout(() => {
  214. cativeIndex.value = value
  215. debounceTimer = null
  216. }, 200)
  217. }
  218. // 获取客户登录信息
  219. const dialogCheck = ref(false)
  220. async function getCustomLoginInfo() {
  221. try {
  222. const res = await userApi.getUserInfo();
  223. userStore.saveUserInfo(res.data);
  224. if (res.code === 200) {
  225. if (
  226. res.data.customInfo.status == 2 &&
  227. res.data.customInfo.applyRealStatus == 2
  228. ) {
  229. router.push(`/pages/customer/account-select?server=${cativeIndex.value}`)
  230. } else {
  231. dialogCheck.value = true;
  232. }
  233. }
  234. } catch (error) {
  235. // console.log(error, 111);
  236. }
  237. }
  238. const confirm = () => {
  239. dialogCheck.value = false;
  240. router.push(`/pages/mine/improveImmediately`)
  241. }
  242. const AccountList = ref([])
  243. const getAccountList = async () => {
  244. AccountList.value = []
  245. loading.value = true
  246. var api
  247. switch (cativeIndex.value) {
  248. case 'real':
  249. api = customApi.AccountAllList
  250. break;
  251. case 'demo':
  252. api = customApi.demoList
  253. break;
  254. case 'del':
  255. api = customApi.deleteAccountList
  256. break;
  257. }
  258. const res = await api({
  259. page: {
  260. current: 1,
  261. size: 100
  262. }
  263. })
  264. if (res.code === 200) {
  265. AccountList.value = res.data
  266. }
  267. loading.value = false
  268. }
  269. const groupCurrency1 = (type) => {
  270. if (type == "GBP") {
  271. return "£";
  272. } else if (type == "USD") {
  273. return "$";
  274. } else if (type == "EUR") {
  275. return "€";
  276. } else if (type == "USC") {
  277. return "¢";
  278. } else {
  279. return "$";
  280. }
  281. }
  282. // 格式化数值函数
  283. function formatMoney(value,currency) {
  284. if (value === null || value === undefined) value = 0;
  285. const sign = value >= 0 ? '' : '-';
  286. const absoluteValue = Math.abs(value);
  287. return groupCurrency1(currency) + sign + numberDecimal(absoluteValue);
  288. }
  289. // 转换数组
  290. const accounts = computed(() => {
  291. if (!AccountList.value || AccountList.value.length == 0) return []
  292. let filteredAccounts = AccountList.value
  293. if (platformActive.value !== 'All') {
  294. filteredAccounts = filteredAccounts.filter(acc =>
  295. (acc.platform || 'MT4') === platformActive.value
  296. )
  297. }
  298. return filteredAccounts.map((acc, index) => {
  299. const currency = acc.currency || 'USD';
  300. const floating = acc.floating ?? 0;
  301. let labels = [t('vu.item1'), 'MT4', 'Standard'];
  302. labels[0] = cativeIndex.value == 'demo' ? t('vu.item2') : t('vu.item1');
  303. labels[1] = acc.platform || 'MT4';
  304. labels[2] = typeMap.value[acc.type];
  305. let nickname = typeMap.value[acc.type];
  306. let fwq
  307. if (cativeIndex.value != 'demo') {
  308. fwq = acc.platform == 'MT4' ? 'CWGMarketsLtd-Live' : 'CWGMarketsSVG-Live';
  309. } else {
  310. fwq = acc.platform == 'MT4' ? 'CWGMarketsLtd-Demo' : 'CWGMarketsSVG-Demo';
  311. }
  312. const balance = acc.balance
  313. return {
  314. ...acc,
  315. labels,
  316. isExpanded: index == 0,
  317. balance,
  318. accountNumber: acc.login.toString(),
  319. nickname,
  320. fwq,
  321. balanceWithSymbol: acc.balanceWithSymbol ?? '$0.00',
  322. creditWithSymbol: acc.creditWithSymbol ?? '$0.00',
  323. equityWithSymbol: acc.equityWithSymbol ?? '$0.00',
  324. currency,
  325. actualLeverage: '1:' + (acc.leverage ?? 0),
  326. floatingPL: acc.floatingWithSymbol ?? '$0.00',
  327. platform: acc.platform || 'MT4',
  328. server: acc.groupCode || '',
  329. login: acc.login.toString(),
  330. listType: cativeIndex.value
  331. };
  332. })
  333. })
  334. onMounted(async () => {
  335. await getAccountList()
  336. })
  337. onUnmounted(() => {
  338. if (debounceTimer) {
  339. clearTimeout(debounceTimer)
  340. }
  341. })
  342. watch(cativeIndex, (newVal) => {
  343. // search.value.platform = tabs.value[newVal].id
  344. getAccountList()
  345. platformActive.value = 'All'
  346. })
  347. // watch(platformActive, (newVal) => {
  348. // setAccountList()
  349. // })
  350. </script>
  351. <style scoped lang="scss">
  352. @import "@/uni.scss";
  353. .btn {
  354. margin: 0;
  355. }
  356. </style>