report.vue 16 KB

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