AccountList.vue 11 KB

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