report.vue 16 KB

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