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