reportTrade.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495
  1. <template>
  2. <cwg-page-wrapper class="create-page" :isHeaderFixed="true">
  3. <cwg-header :title="titleList[detailType]" />
  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, locale } = 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.Tit1'),
  52. 4: t('Ib.Report.Tit4'),
  53. }
  54. })
  55. const isShortList = computed(() => [
  56. { text: t('State.All'), value: 0 },
  57. { text: t('Ib.Report.item1'), value: 1 },
  58. { text: t('Ib.Report.item2'), value: 2 },
  59. ])
  60. const now = new Date()
  61. const year = now.getFullYear()
  62. const month = String(now.getMonth() + 1).padStart(2, '0')
  63. const day = String(now.getDate()).padStart(2, '0')
  64. const defaultDateRange = [`${year}-${month}-01`, `${year}-${month}-${day}`]
  65. const detailType = ref(1)
  66. const searchParams = ref<any>({
  67. detail_type: null,
  68. customType: 0,
  69. platform: 'MT4',
  70. agentId: '',
  71. login: '',
  72. cId: '',
  73. isShort: 0,
  74. date: defaultDateRange,
  75. })
  76. const search = reactive({
  77. detail_type: 1,
  78. customType: 0,
  79. platform: 'MT4',
  80. startDate: defaultDateRange[0],
  81. endDate: defaultDateRange[1],
  82. date: defaultDateRange,
  83. agentId: '',
  84. login: '',
  85. cId: '',
  86. isShort: 0,
  87. })
  88. const country = computed(() => {
  89. return userInfo.customInfo.country
  90. })
  91. const agentLevels = ref<Array<{ key: string, options: any[] }>>([
  92. {
  93. key: 'agentId_0',
  94. options: [
  95. { value: 0, text: t('news_add_field.IbReport.ALL') },
  96. { value: -1, text: t('news_add_field.IbReport.DirectlyUnder') },
  97. ],
  98. },
  99. ])
  100. const handleAgentChange = async (val: any, levelIndex: number) => {
  101. console.log(val, 'change1')
  102. // 截断当前层级之后的所有层级
  103. agentLevels.value.splice(levelIndex + 1)
  104. // 清理 searchParams 中被移除层级的值
  105. const params = { ...searchParams.value }
  106. for (let key in params) {
  107. if (key.startsWith('agentId_')) {
  108. const idx = parseInt(key.split('_')[1])
  109. if (idx > levelIndex) {
  110. delete params[key]
  111. }
  112. }
  113. }
  114. // 更新当前选中的代理ID
  115. params[`agentId_${levelIndex}`] = val
  116. // 同步更新 searchParams
  117. searchParams.value = { ...params }
  118. // 确保更新完成后再执行搜索
  119. await nextTick()
  120. handleSearch(searchParams.value)
  121. if (val === 0 || val === -1 || val === '') {
  122. return
  123. }
  124. try {
  125. const res = await ibApi.ibTree({ pid: val })
  126. if (res.code === Code.StatusOK && res.data && res.data.length > 0) {
  127. const nextOptions = []
  128. res.data.forEach((item: any) => {
  129. if (item.ibNo) {
  130. nextOptions.push({
  131. value: item.id,
  132. text: item.name ? `${item.ibNo} - ${item.name}` : item.ibNo,
  133. })
  134. }
  135. })
  136. if (nextOptions.length > 0) {
  137. agentLevels.value.push({
  138. key: `agentId_${levelIndex + 1}`,
  139. options: nextOptions,
  140. })
  141. }
  142. }
  143. } catch (error) {
  144. uni.showToast({ title: 'Error', icon: 'none' })
  145. }
  146. }
  147. const getSummaries = (param: any) => {
  148. const { columns, summaryData } = param
  149. const sums: string[] = []
  150. if (!summaryData || Object.keys(summaryData).length === 0) return sums
  151. columns.forEach((column: any, index: number) => {
  152. if (index === 0) {
  153. sums[index] = t('Label.Total')
  154. return
  155. }
  156. const type = reportType.value
  157. const detailType = search.detail_type
  158. // 根据不同的列 prop 进行合计数据显示和格式化
  159. const prop = column.prop
  160. if (!prop) {
  161. sums[index] = ''
  162. return
  163. }
  164. if (type == 1) {
  165. if (['deposit', 'withdrawal', 'credit'].includes(prop)) {
  166. sums[index] = summaryData[prop] ? numberFormat(summaryData[prop]) : '0'
  167. } else {
  168. sums[index] = ''
  169. }
  170. } else if (type == 2) {
  171. if (['volume', 'rebateAmount', 'commissionAmount'].includes(prop)) {
  172. sums[index] = summaryData[prop] ? numberFormat(summaryData[prop]) : '0'
  173. } else {
  174. sums[index] = ''
  175. }
  176. } else if (type == 3) {
  177. if (detailType == 4) {
  178. if (['volume', 'storage', 'taxes', 'profit'].includes(prop)) {
  179. sums[index] = summaryData[prop] ? numberFormat(summaryData[prop]) : '0'
  180. } else {
  181. sums[index] = ''
  182. }
  183. } else {
  184. if (['commission', 'volume', 'storage', 'taxes', 'profit', 'totalProfit'].includes(prop)) {
  185. sums[index] = summaryData[prop] ? numberFormat(summaryData[prop]) : '0'
  186. } else {
  187. sums[index] = ''
  188. }
  189. }
  190. } else if (type == 4) {
  191. if (['credit', 'balance', 'equity', 'floating'].includes(prop)) {
  192. sums[index] = summaryData[prop] ? numberFormat(summaryData[prop]) : '0'
  193. } else {
  194. sums[index] = ''
  195. }
  196. } else if (type == 6) {
  197. if (prop === 'amount') {
  198. sums[index] = summaryData[prop] ? numberFormat(summaryData[prop]) : '0'
  199. } else {
  200. sums[index] = ''
  201. }
  202. } else if (type == 7) {
  203. if (['fxVolume', 'cfdVolume', 'indexVolume', 'metalVolume'].includes(prop)) {
  204. sums[index] = summaryData[prop] ? numberFormat(summaryData[prop]) : '0'
  205. } else {
  206. sums[index] = ''
  207. }
  208. } else if (type == 24) {
  209. if (prop === 'volume') {
  210. sums[index] = summaryData[prop] ? numberFormat(summaryData[prop]) + ' /手' : '0'
  211. } else if (prop === 'rebate') {
  212. sums[index] = summaryData[prop] ? '$' + numberFormat(summaryData[prop]) : '0'
  213. } else {
  214. sums[index] = ''
  215. }
  216. } else {
  217. sums[index] = ''
  218. }
  219. })
  220. return sums
  221. }
  222. const handleSearch = (params: any) => {
  223. console.log(params, 'params')
  224. // 默认类型为页面参数
  225. const payload: any = { ...params, reportType: 3 }
  226. let finalAgentId = payload.agentId_0
  227. for (let i = agentLevels.value.length - 1; i >= 0; i--) {
  228. const val = payload[`agentId_${i}`]
  229. if (val !== undefined && val !== '') {
  230. finalAgentId = val
  231. break
  232. }
  233. }
  234. console.log(finalAgentId, 'finalAgentId')
  235. payload.agentId = finalAgentId
  236. if (payload.date?.length) {
  237. payload.startDate = payload.date[0]
  238. payload.endDate = payload.date[1]
  239. }
  240. const type = Number(payload.reportType)
  241. if (![1, 3, 4, 7, 24].includes(type)) payload.platform = ''
  242. if (![1, 2, 3, 4, 7].includes(type)) payload.login = ''
  243. if (type !== 7) payload.cId = ''
  244. if (![3, 7].includes(type)) payload.isShort = 0
  245. if (type !== 3) payload.detail_type = null
  246. if (type !== 24) payload.customType = 0
  247. Object.assign(search, payload)
  248. // search.reportType = payload.reportType
  249. // search.detail_type = payload.detail_type
  250. // search.customType = payload.customType
  251. // search.platform = payload.platform
  252. // search.startDate = payload.startDate
  253. // search.endDate = payload.endDate
  254. // search.date = payload.date
  255. // search.agentId = payload.agentId
  256. // search.login = payload.login
  257. // search.cId = payload.cId
  258. // search.isShort = payload.isShort
  259. nextTick(() => {
  260. tableRef.value?.refreshTable?.()
  261. })
  262. }
  263. const handleReset = (emptyParams: any) => {
  264. // 重置时清理级联菜单到只有第一层
  265. agentLevels.value.splice(1)
  266. handleSearch(emptyParams)
  267. }
  268. const initIbTree = async () => {
  269. const res = await ibApi.ibTree({ pid: 0 })
  270. if (res.code === Code.StatusOK) {
  271. if (res.data && res.data.length > 0) {
  272. res.data.forEach((item: any) => {
  273. if (item.ibNo) {
  274. let option = {
  275. value: item.id,
  276. text: item.name ? `${item.ibNo} - ${item.name}` : item.ibNo,
  277. }
  278. agentLevels.value[0].options.push(option)
  279. }
  280. })
  281. } else {
  282. uni.showToast({
  283. title: res.msg, icon: 'none',
  284. })
  285. }
  286. }
  287. }
  288. // 表格列配置 根据types 切换
  289. const columns = computed(() => {
  290. // console.log(detailType.value, '23')
  291. // console.log(columnList.value[`3_${detailType.value}`])
  292. return columnList.value[`3_${detailType.value}`] || []
  293. })
  294. const mobilePrimaryFields = computed(() => {
  295. let list: any[] = []
  296. list = mobileList.value[`3_${detailType.value}`] || []
  297. return [
  298. ...list,
  299. {
  300. prop: 'more',
  301. type: 'more',
  302. width: 20,
  303. align: 'center',
  304. },
  305. ]
  306. })
  307. // 接口 根据types 切换(动态代理不同类型报表API)
  308. const listApi = computed(() => {
  309. return async (params: any) => {
  310. let apiFn = ibApi.tradeDw
  311. const type = detailType.value
  312. if (type == 1) apiFn = ibApi.tradeHistory
  313. else if (type == 4) apiFn = ibApi.tradePosition
  314. if (apiFn) {
  315. return await apiFn(params)
  316. }
  317. }
  318. })
  319. onLoad((options) => {
  320. console.log(options?.type, 'type')
  321. // search.reportType = options?.type;
  322. // searchParams.value.reportType = options?.type;
  323. detailType.value = options?.detailType
  324. })
  325. onMounted(async () => {
  326. loading.value = true
  327. await initIbTree()
  328. loading.value = false
  329. })
  330. const filterFields = computed(() => {
  331. const fields = []
  332. fields.push({
  333. key: 'platform',
  334. type: 'select',
  335. label: t('Label.Platform'),
  336. placeholder: t('placeholder.choose'),
  337. options: platformOptions,
  338. defaultValue: 'MT4',
  339. })
  340. agentLevels.value.forEach((level, index) => {
  341. fields.push({
  342. key: level.key,
  343. type: 'select',
  344. label: t('State.All'),
  345. options: level.options,
  346. placeholder: t('State.All'),
  347. onChange: (val: any) => handleAgentChange(val, index),
  348. defaultValue: index === 0 ? 0 : '',
  349. })
  350. })
  351. fields.push({
  352. key: 'login',
  353. type: 'input',
  354. label: t('Label.TradingAccount'),
  355. placeholder: t('Label.TradingAccount'),
  356. defaultValue: '',
  357. })
  358. fields.push({
  359. key: 'isShort',
  360. type: 'select',
  361. label: t('placeholder.choose'),
  362. placeholder: t('placeholder.choose'),
  363. options: isShortList.value,
  364. defaultValue: 0,
  365. isSelect: true,
  366. })
  367. fields.push({ key: 'date', label: t('placeholder.Start') + ' - ' + t('placeholder.End'), type: 'daterange' })
  368. return fields
  369. })
  370. watch(locale, () => {
  371. agentLevels.value = [
  372. {
  373. key: 'agentId_0',
  374. options: [
  375. { value: 0, text: t('news_add_field.IbReport.ALL') },
  376. { value: -1, text: t('news_add_field.IbReport.DirectlyUnder') },
  377. ],
  378. },
  379. ]
  380. nextTick(() => {
  381. setFields()
  382. })
  383. })
  384. </script>
  385. <style lang="scss" scoped>
  386. @import "@/uni.scss";
  387. .search-content {
  388. display: flex;
  389. justify-content: space-between;
  390. }
  391. .report-platform {
  392. display: flex;
  393. align-items: center;
  394. .checklist-box {
  395. cursor: pointer;
  396. box-sizing: border-box;
  397. padding: 0 px2rpx(20);
  398. border: 1px solid #DCDFE6;
  399. background-color: #f5f5f5;
  400. height: px2rpx(35);
  401. line-height: px2rpx(35);
  402. border-radius: px2rpx(4) 0 0 px2rpx(4);
  403. &:last-child {
  404. border-radius: 0 px2rpx(4) px2rpx(4) 0;
  405. }
  406. &.active {
  407. color: var(--color-white);
  408. background-color: var(--color-error);
  409. border-color: var(--color-error);
  410. }
  411. }
  412. }
  413. .search-input-box {
  414. .uni-input {
  415. height: px2rpx(35);
  416. border: 1px solid #DCDFE6;
  417. padding: 0 px2rpx(20);
  418. border-radius: px2rpx(4);
  419. background-color: rgba(var(--bs-body-bg-rgb), var(--bs-bg-opacity)) !important;
  420. }
  421. }
  422. .agent-select {
  423. width: px2rpx(240);
  424. }
  425. .search-btn {
  426. height: px2rpx(36);
  427. line-height: px2rpx(36);
  428. margin: 0;
  429. }
  430. </style>