report.vue 16 KB

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