report.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554
  1. <template>
  2. <cwg-page-wrapper class="create-page" :isHeaderFixed="true">
  3. <cwg-header :title="t('Home.page_ib.item3')" />
  4. <uni-loading v-if="loading"/>
  5. <view v-else class="account-content">
  6. <view class="search-content">
  7. <view class="search-bar">
  8. <cwg-complex-search :fields="filterFields" v-model="searchParams" @search="handleSearch"
  9. @reset="handleReset" />
  10. </view>
  11. </view>
  12. <cwg-tabel
  13. ref="tableRef"
  14. :columns="columns"
  15. :mobilePrimaryFields="mobilePrimaryFields"
  16. :queryParams="search"
  17. :api="listApi"
  18. :show-operation="false"
  19. :showPagination="true"
  20. :showSummary="true"
  21. :summaryMethod="getSummaries"
  22. >
  23. </cwg-tabel>
  24. </view>
  25. </cwg-page-wrapper>
  26. </template>
  27. <script setup lang="ts">
  28. // 报告
  29. import { ref, computed, onMounted, watch, nextTick } from 'vue'
  30. import { useI18n } from 'vue-i18n'
  31. import Config from '@/config/index'
  32. import { ibApi } from '@/service/ib'
  33. import { useReportConst } from '@/pages/ib/const/report'
  34. import { useFilters } from '@/composables/useFilters'
  35. import { isAfterJuly28 } from '@/utils/dateUtils'
  36. import useUserStore from '@/stores/use-user-store'
  37. const { numberFormat } = useFilters()
  38. const { t } = useI18n()
  39. const { columnList, mobileList, platformOptions, customTypeList, groupCurrency1, groupTypeName } = useReportConst()
  40. let { Code } = Config
  41. const { userInfo } = useUserStore()
  42. const tableRef = ref(null)
  43. const loading = ref(false)
  44. const typeList = computed(() => [
  45. { text: t('Ib.Report.Title1'), value: 1 },
  46. { text: t('Ib.Report.Title2'), value: 2 },
  47. { text: t('Ib.Report.Title3'), value: 3 },
  48. { text: t('Ib.Report.Title6'), value: 4 },
  49. { text: t('Ib.Report.Title5'), value: 5 },
  50. { text: t('news_add_field.IbReport.Title6'), value: 6 },
  51. { text: t('Ib.Report.Title7'), value: 7 },
  52. { text: t('Ib.Report.Title8'), value: 24 },
  53. ])
  54. const detailTypeList = computed(() => [
  55. { text: t('Ib.Report.Tit1'), value: 1 },
  56. { text: t('Ib.Report.Tit2'), value: 2 },
  57. { text: t('Ib.Report.Tit3'), value: 3 },
  58. { text: t('Ib.Report.Tit4'), value: 4 },
  59. ])
  60. const isShortList = computed(() => [
  61. { text: t('State.All'), value: 0 },
  62. { text: t('Ib.Report.item1'), value: 1 },
  63. { text: t('Ib.Report.item2'), value: 2 },
  64. ])
  65. const now = new Date()
  66. const year = now.getFullYear()
  67. const month = String(now.getMonth() + 1).padStart(2, '0')
  68. const day = String(now.getDate()).padStart(2, '0')
  69. const defaultDateRange = [`${year}-${month}-01`, `${year}-${month}-${day}`]
  70. const searchParams = ref<any>({
  71. reportType: 1,
  72. detail_type: null,
  73. customType: 0,
  74. platform: 'MT4',
  75. agentId: '',
  76. login: '',
  77. cId: '',
  78. isShort: 0,
  79. date: defaultDateRange,
  80. })
  81. const filterFields = ref([])
  82. const search = ref({
  83. reportType: 1,
  84. detail_type: null as number | null,
  85. customType: 0,
  86. platform: 'MT4',
  87. startDate: defaultDateRange[0],
  88. endDate: defaultDateRange[1],
  89. agentId: '',
  90. login: '',
  91. cId: '',
  92. isShort: 0,
  93. })
  94. const country = computed(() => {
  95. return userInfo.customInfo.country
  96. })
  97. const agentLevels = ref<Array<{ key: string, options: any[] }>>([
  98. {
  99. key: 'agentId_0',
  100. options: [
  101. { value: 0, text: t('news_add_field.IbReport.ALL') },
  102. { value: -1, text: t('news_add_field.IbReport.DirectlyUnder') },
  103. ],
  104. },
  105. ])
  106. const handleAgentChange = async (val: any, levelIndex: number) => {
  107. // 截断当前层级之后的所有层级
  108. agentLevels.value.splice(levelIndex + 1)
  109. // 清理 searchParams 中被移除层级的值
  110. for (let key in searchParams.value) {
  111. if (key.startsWith('agentId_')) {
  112. const idx = parseInt(key.split('_')[1])
  113. if (idx > levelIndex) {
  114. delete searchParams.value[key]
  115. }
  116. }
  117. }
  118. if (val === 0 || val === -1 || val === '') {
  119. return
  120. }
  121. try {
  122. const res = await ibApi.ibTree({ pid: val })
  123. if (res.code === Code.StatusOK && res.data && res.data.length > 0) {
  124. const nextOptions = []
  125. res.data.forEach((item: any) => {
  126. if (item.ibNo) {
  127. nextOptions.push({
  128. value: item.id,
  129. text: item.name ? `${item.ibNo} - ${item.name}` : item.ibNo,
  130. })
  131. }
  132. })
  133. if (nextOptions.length > 0) {
  134. agentLevels.value.push({
  135. key: `agentId_${levelIndex + 1}`,
  136. options: nextOptions,
  137. })
  138. }
  139. }
  140. setFields()
  141. } catch (error) {
  142. uni.showToast({ title: 'Error', icon: 'none' })
  143. }
  144. }
  145. const getSummaries = (param: any) => {
  146. const { columns, summaryData } = param
  147. const sums: string[] = []
  148. if (!summaryData || Object.keys(summaryData).length === 0) return sums
  149. columns.forEach((column: any, index: number) => {
  150. if (index === 0) {
  151. sums[index] = t('Label.Total')
  152. return
  153. }
  154. const type = search.value.reportType
  155. const detailType = search.value.detail_type
  156. // 根据不同的列 prop 进行合计数据显示和格式化
  157. const prop = column.prop
  158. if (!prop) {
  159. sums[index] = ''
  160. return
  161. }
  162. if (type == 1) {
  163. if (['deposit', 'withdrawal', 'credit'].includes(prop)) {
  164. sums[index] = summaryData[prop] ? numberFormat(summaryData[prop]) : '0'
  165. } else {
  166. sums[index] = ''
  167. }
  168. } else if (type == 2) {
  169. if (['volume', 'rebateAmount', 'commissionAmount'].includes(prop)) {
  170. sums[index] = summaryData[prop] ? numberFormat(summaryData[prop]) : '0'
  171. } else {
  172. sums[index] = ''
  173. }
  174. } else if (type == 3) {
  175. if (detailType == 4) {
  176. if (['volume', 'storage', 'taxes', 'profit'].includes(prop)) {
  177. sums[index] = summaryData[prop] ? numberFormat(summaryData[prop]) : '0'
  178. } else {
  179. sums[index] = ''
  180. }
  181. } else {
  182. if (['commission', 'volume', 'storage', 'taxes', 'profit', 'totalProfit'].includes(prop)) {
  183. sums[index] = summaryData[prop] ? numberFormat(summaryData[prop]) : '0'
  184. } else {
  185. sums[index] = ''
  186. }
  187. }
  188. } else if (type == 4) {
  189. if (['credit', 'balance', 'equity', 'floating'].includes(prop)) {
  190. sums[index] = summaryData[prop] ? numberFormat(summaryData[prop]) : '0'
  191. } else {
  192. sums[index] = ''
  193. }
  194. } else if (type == 6) {
  195. if (prop === 'amount') {
  196. sums[index] = summaryData[prop] ? numberFormat(summaryData[prop]) : '0'
  197. } else {
  198. sums[index] = ''
  199. }
  200. } else if (type == 7) {
  201. if (['fxVolume', 'cfdVolume', 'indexVolume', 'metalVolume'].includes(prop)) {
  202. sums[index] = summaryData[prop] ? numberFormat(summaryData[prop]) : '0'
  203. } else {
  204. sums[index] = ''
  205. }
  206. } else if (type == 24) {
  207. if (prop === 'volume') {
  208. sums[index] = summaryData[prop] ? numberFormat(summaryData[prop]) + ' /手' : '0'
  209. } else if (prop === 'rebate') {
  210. sums[index] = summaryData[prop] ? '$' + numberFormat(summaryData[prop]) : '0'
  211. } else {
  212. sums[index] = ''
  213. }
  214. } else {
  215. sums[index] = ''
  216. }
  217. })
  218. return sums
  219. }
  220. const handleSearch = (params: any) => {
  221. const payload: any = { ...params }
  222. let finalAgentId = payload.agentId_0
  223. for (let i = agentLevels.value.length - 1; i >= 0; i--) {
  224. const val = payload[`agentId_${i}`]
  225. if (val !== undefined && val !== '') {
  226. finalAgentId = val
  227. break
  228. }
  229. }
  230. payload.agentId = finalAgentId
  231. const type = Number(payload.reportType)
  232. if (![1, 3, 4, 7, 24].includes(type)) payload.platform = ''
  233. if (![1, 2, 3, 4, 7].includes(type)) payload.login = ''
  234. if (type !== 7) payload.cId = ''
  235. if (![3, 7].includes(type)) payload.isShort = 0
  236. if (type !== 3) payload.detail_type = null
  237. if (type !== 24) payload.customType = 0
  238. search.value = {
  239. reportType: payload.reportType,
  240. detail_type: payload.detail_type,
  241. customType: payload.customType,
  242. platform: payload.platform,
  243. startDate: payload.startDate,
  244. endDate: payload.endDate,
  245. agentId: payload.agentId,
  246. login: payload.login,
  247. cId: payload.cId,
  248. isShort: payload.isShort,
  249. }
  250. nextTick(() => {
  251. tableRef.value?.refreshTable?.()
  252. })
  253. }
  254. const handleReset = (emptyParams: any) => {
  255. // 重置时清理级联菜单到只有第一层
  256. agentLevels.value.splice(1)
  257. handleSearch(emptyParams)
  258. }
  259. const initIbTree = async () => {
  260. const res = await ibApi.ibTree({ pid: 0 })
  261. if (res.code === Code.StatusOK) {
  262. if (res.data && res.data.length > 0) {
  263. res.data.forEach((item: any) => {
  264. if (item.ibNo) {
  265. let option = {
  266. value: item.id,
  267. text: item.name ? `${item.ibNo} - ${item.name}` : item.ibNo,
  268. }
  269. agentLevels.value[0].options.push(option)
  270. }
  271. })
  272. } else {
  273. uni.showToast({
  274. title: res.msg, icon: 'none',
  275. })
  276. }
  277. }
  278. }
  279. // 表格列配置 根据types 切换
  280. const columns = computed(() => {
  281. if (search.value.reportType === 3) {
  282. return columnList.value[`3_${search.value.detail_type}`] || []
  283. }
  284. return columnList.value[search.value.reportType] || []
  285. })
  286. const mobilePrimaryFields = computed(() => {
  287. let list: any[] = []
  288. if (search.value.reportType === 3) {
  289. list = mobileList.value[`3_${search.value.detail_type}`] || []
  290. } else {
  291. list = mobileList.value[search.value.reportType] || []
  292. }
  293. return [
  294. ...list,
  295. {
  296. prop: 'more',
  297. type: 'more',
  298. width: 20,
  299. align: 'right',
  300. },
  301. ]
  302. })
  303. // 接口 根据types 切换(动态代理不同类型报表API)
  304. const listApi = computed(() => {
  305. return async (params: any) => {
  306. let apiFn: any
  307. const type = search.value.reportType
  308. const detailType = search.value.detail_type
  309. if (type == 1) apiFn = ibApi.tradeDw
  310. else if (type == 2) apiFn = ibApi.tradeAgentCommission
  311. else if (type == 3) {
  312. if (detailType == 1) apiFn = ibApi.tradeHistory
  313. else if (detailType == 2) apiFn = ibApi.tradePendingHistory
  314. else if (detailType == 3) apiFn = ibApi.tradePending
  315. else if (detailType == 4) apiFn = ibApi.tradePosition
  316. } else if (type == 4) apiFn = ibApi.tradeAccount
  317. else if (type == 5) apiFn = ibApi.tradeIb
  318. else if (type == 6) apiFn = ibApi.ibReportBalance
  319. else if (type == 7) apiFn = ibApi.tradeSymbolCategory
  320. else if (type == 24) apiFn = ibApi.tradeSalesHidden
  321. if (apiFn) {
  322. if (type == 2) {
  323. const isVietnam = country.value === 'VN' // 这里需要你实际的取国家逻辑
  324. return await apiFn(params, isVietnam)
  325. }
  326. return await apiFn(params)
  327. }
  328. return Promise.reject('No API found')
  329. }
  330. })
  331. watch(() => searchParams.value.reportType, (val) => {
  332. const type = Number(val)
  333. search.value.reportType = type
  334. if (type === 24) {
  335. searchParams.value.customType = 0
  336. searchParams.value.detail_type = null
  337. search.value.customType = 0
  338. search.value.detail_type = null
  339. } else if (type === 3) {
  340. if (searchParams.value.detail_type == null) searchParams.value.detail_type = 1
  341. if (search.value.detail_type == null) search.value.detail_type = 1
  342. } else {
  343. searchParams.value.detail_type = null
  344. search.value.detail_type = null
  345. searchParams.value.customType = 0
  346. search.value.customType = 0
  347. }
  348. }, { immediate: true })
  349. watch(() => searchParams.value.detail_type, (val) => {
  350. search.value.detail_type = val == null ? null : Number(val)
  351. })
  352. watch(() => searchParams.value.platform, (val) => {
  353. search.value.platform = val
  354. })
  355. watch(() => searchParams.value.customType, (val) => {
  356. search.value.customType = val
  357. })
  358. watch(() => searchParams.value.isShort, (val) => {
  359. search.value.isShort = val
  360. })
  361. onMounted(async () => {
  362. loading.value = true
  363. await initIbTree()
  364. setFields()
  365. loading.value = false
  366. })
  367. const setFields = () => {
  368. const type = Number(searchParams.value.reportType ?? 1)
  369. const fields: any[] = [
  370. {
  371. key: 'reportType',
  372. type: 'select',
  373. label: t('Home.page_ib.item3'),
  374. placeholder: t('placeholder.choose'),
  375. options: typeList.value,
  376. defaultValue: 1,
  377. isSelect: true,
  378. },
  379. ]
  380. if (type === 3) {
  381. fields.push({
  382. key: 'detail_type',
  383. type: 'select',
  384. label: t('placeholder.choose'),
  385. placeholder: t('placeholder.choose'),
  386. options: detailTypeList.value,
  387. defaultValue: 1,
  388. isSelect: true,
  389. })
  390. }
  391. if ([1, 3, 4, 7, 24].includes(type)) {
  392. fields.push({
  393. key: 'platform',
  394. type: 'select',
  395. label: t('Label.Platform'),
  396. placeholder: t('placeholder.choose'),
  397. options: platformOptions,
  398. defaultValue: 'MT4',
  399. })
  400. }
  401. if (type === 24) {
  402. fields.push({
  403. key: 'customType',
  404. type: 'select',
  405. label: t('placeholder.choose'),
  406. placeholder: t('placeholder.choose'),
  407. options: customTypeList.value,
  408. defaultValue: 0,
  409. isSelect: true,
  410. })
  411. }
  412. console.log(agentLevels.value)
  413. agentLevels.value.forEach((level, index) => {
  414. fields.push({
  415. key: level.key,
  416. type: 'select',
  417. label: t('State.All'),
  418. options: level.options,
  419. placeholder: t('State.All'),
  420. onChange: (val: any) => handleAgentChange(val, index),
  421. defaultValue: index === 0 ? 0 : '',
  422. })
  423. })
  424. if ([1, 2, 3, 4, 7].includes(type)) {
  425. fields.push({
  426. key: 'login',
  427. type: 'input',
  428. label: t('Label.TradingAccount'),
  429. placeholder: t('Label.TradingAccount'),
  430. defaultValue: '',
  431. })
  432. }
  433. if (type === 7) {
  434. fields.push({ key: 'cId', type: 'input', label: 'CID', placeholder: 'CID', defaultValue: '' })
  435. }
  436. if ([3, 7].includes(type)) {
  437. fields.push({
  438. key: 'isShort',
  439. type: 'select',
  440. label: t('placeholder.choose'),
  441. placeholder: t('placeholder.choose'),
  442. options: isShortList.value,
  443. defaultValue: 0,
  444. isSelect: true,
  445. })
  446. }
  447. fields.push({ key: 'date', label: t('placeholder.Start') + ' - ' + t('placeholder.End'), type: 'daterange' })
  448. filterFields.value = fields
  449. }
  450. </script>
  451. <style lang="scss" scoped>
  452. @import "@/uni.scss";
  453. .search-content {
  454. display: flex;
  455. justify-content: space-between;
  456. }
  457. .report-platform {
  458. display: flex;
  459. align-items: center;
  460. .checklist-box {
  461. cursor: pointer;
  462. box-sizing: border-box;
  463. padding: 0 px2rpx(20);
  464. border: 1px solid #DCDFE6;
  465. background-color: #f5f5f5;
  466. height: px2rpx(35);
  467. line-height: px2rpx(35);
  468. border-radius: px2rpx(4) 0 0 px2rpx(4);
  469. &:last-child {
  470. border-radius: 0 px2rpx(4) px2rpx(4) 0;
  471. }
  472. &.active {
  473. color: var(--color-white);
  474. background-color: var(--color-error);
  475. border-color: var(--color-error);
  476. }
  477. }
  478. }
  479. .search-input-box {
  480. .uni-input {
  481. height: px2rpx(35);
  482. border: 1px solid #DCDFE6;
  483. padding: 0 px2rpx(20);
  484. border-radius: px2rpx(4);
  485. background-color: #fff;
  486. }
  487. }
  488. .agent-select {
  489. width: px2rpx(240);
  490. }
  491. .search-btn {
  492. height: px2rpx(36);
  493. line-height: px2rpx(36);
  494. margin: 0;
  495. }
  496. </style>