AccountList.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347
  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="cativeIndex = 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 } 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('Tips.ArchivedAccount') },
  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. // 获取客户登录信息
  208. const dialogCheck = ref(false)
  209. async function getCustomLoginInfo() {
  210. try {
  211. const res = await userApi.getUserInfo();
  212. userStore.saveUserInfo(res.data);
  213. if (res.code === 200) {
  214. if (
  215. res.data.customInfo.status == 2 &&
  216. res.data.customInfo.applyRealStatus == 2
  217. ) {
  218. router.push(`/pages/customer/account-select?server=${cativeIndex.value}`)
  219. } else {
  220. dialogCheck.value = true;
  221. }
  222. }
  223. } catch (error) {
  224. // console.log(error, 111);
  225. }
  226. }
  227. const confirm = () => {
  228. dialogCheck.value = false;
  229. router.push(`/pages/mine/improveImmediately`)
  230. }
  231. const AccountList = ref([])
  232. const getAccountList = async () => {
  233. AccountList.value = []
  234. loading.value = true
  235. var api
  236. switch (cativeIndex.value) {
  237. case 'real':
  238. api = customApi.AccountAllList
  239. break;
  240. case 'demo':
  241. api = customApi.demoList
  242. break;
  243. case 'del':
  244. api = customApi.deleteAccountList
  245. break;
  246. }
  247. const res = await api({
  248. page: {
  249. current: 1,
  250. size: 100
  251. }
  252. })
  253. if (res.code === 200) {
  254. AccountList.value = res.data
  255. }
  256. loading.value = false
  257. }
  258. // 格式化数值函数
  259. function formatMoney(value) {
  260. if (value === null || value === undefined) value = 0;
  261. const sign = value >= 0 ? '' : '-';
  262. const absoluteValue = Math.abs(value);
  263. return '$' + sign + numberDecimal(absoluteValue);
  264. }
  265. // 转换数组
  266. const accounts = computed(() => {
  267. if (!AccountList.value || AccountList.value.length == 0) return []
  268. let filteredAccounts = AccountList.value
  269. if (platformActive.value !== 'All') {
  270. filteredAccounts = filteredAccounts.filter(acc =>
  271. (acc.platform || 'MT4') === platformActive.value
  272. )
  273. }
  274. return filteredAccounts.map((acc, index) => {
  275. const currency = acc.currency || 'USD';
  276. const floating = acc.floating ?? 0;
  277. let labels = [t('vu.item1'), 'MT4', 'Standard'];
  278. labels[0] = cativeIndex.value == 'demo' ? t('vu.item2') : t('vu.item1');
  279. labels[1] = acc.platform || 'MT4';
  280. labels[2] = typeMap.value[acc.type];
  281. let nickname = typeMap.value[acc.type];
  282. let fwq
  283. if (cativeIndex.value != 'demo') {
  284. fwq = acc.platform == 'MT4' ? 'CWGMarketsLtd-Live' : 'CWGMarketsSVG-Live';
  285. } else {
  286. fwq = acc.platform == 'MT4' ? 'CWGMarketsLtd-Demo' : 'CWGMarketsSVG-Demo';
  287. }
  288. const balance = acc.balance
  289. return {
  290. ...acc,
  291. labels,
  292. isExpanded: index == 0,
  293. balance,
  294. accountNumber: acc.login.toString(),
  295. nickname,
  296. fwq,
  297. balanceWithSymbol: acc.balanceWithSymbol ?? '$0.00',
  298. creditWithSymbol: acc.creditWithSymbol ?? '$0.00',
  299. equityWithSymbol: acc.equityWithSymbol ?? '$0.00',
  300. currency,
  301. actualLeverage: '1:' + (acc.leverage ?? 0),
  302. floatingPL: formatMoney(floating),
  303. platform: acc.platform || 'MT4',
  304. server: acc.groupCode || '',
  305. login: acc.login.toString(),
  306. listType: cativeIndex.value
  307. };
  308. })
  309. })
  310. onMounted(async () => {
  311. await getAccountList()
  312. })
  313. watch(cativeIndex, (newVal) => {
  314. // search.value.platform = tabs.value[newVal].id
  315. getAccountList()
  316. platformActive.value = 'All'
  317. })
  318. // watch(platformActive, (newVal) => {
  319. // setAccountList()
  320. // })
  321. </script>
  322. <style scoped lang="scss">
  323. @import "@/uni.scss";
  324. .btn {
  325. margin: 0;
  326. }
  327. </style>