report.vue 18 KB

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