report.vue 16 KB

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