reportTrade.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452
  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 = detailType.value
  157. // 根据不同的列 prop 进行合计数据显示和格式化
  158. const prop = column.prop
  159. if (!prop) {
  160. sums[index] = ''
  161. return
  162. }
  163. if (type == 4) {
  164. if (['volume', 'storage', 'taxes', 'profit'].includes(prop)) {
  165. sums[index] = summaryData[prop] ? numberFormat(summaryData[prop]) : '0'
  166. } else {
  167. sums[index] = ''
  168. }
  169. } else {
  170. if (['commission', 'volume', 'storage', 'taxes', 'profit', 'totalProfit'].includes(prop)) {
  171. sums[index] = summaryData[prop] ? numberFormat(summaryData[prop]) : '0'
  172. } else {
  173. sums[index] = ''
  174. }
  175. }
  176. })
  177. return sums
  178. }
  179. const handleSearch = (params: any) => {
  180. console.log(params, 'params')
  181. // 默认类型为页面参数
  182. const payload: any = { ...params, reportType: 3 }
  183. let finalAgentId = payload.agentId_0
  184. for (let i = agentLevels.value.length - 1; i >= 0; i--) {
  185. const val = payload[`agentId_${i}`]
  186. if (val !== undefined && val !== '') {
  187. finalAgentId = val
  188. break
  189. }
  190. }
  191. console.log(finalAgentId, 'finalAgentId')
  192. payload.agentId = finalAgentId
  193. if (payload.date?.length) {
  194. payload.startDate = payload.date[0]
  195. payload.endDate = payload.date[1]
  196. }
  197. const type = Number(payload.reportType)
  198. if (![1, 3, 4, 7, 24].includes(type)) payload.platform = ''
  199. if (![1, 2, 3, 4, 7].includes(type)) payload.login = ''
  200. if (type !== 7) payload.cId = ''
  201. if (![3, 7].includes(type)) payload.isShort = 0
  202. if (type !== 3) payload.detail_type = null
  203. if (type !== 24) payload.customType = 0
  204. Object.assign(search, payload)
  205. // search.reportType = payload.reportType
  206. // search.detail_type = payload.detail_type
  207. // search.customType = payload.customType
  208. // search.platform = payload.platform
  209. // search.startDate = payload.startDate
  210. // search.endDate = payload.endDate
  211. // search.date = payload.date
  212. // search.agentId = payload.agentId
  213. // search.login = payload.login
  214. // search.cId = payload.cId
  215. // search.isShort = payload.isShort
  216. nextTick(() => {
  217. tableRef.value?.refreshTable?.()
  218. })
  219. }
  220. const handleReset = (emptyParams: any) => {
  221. // 重置时清理级联菜单到只有第一层
  222. agentLevels.value.splice(1)
  223. handleSearch(emptyParams)
  224. }
  225. const initIbTree = async () => {
  226. const res = await ibApi.ibTree({ pid: 0 })
  227. if (res.code === Code.StatusOK) {
  228. if (res.data && res.data.length > 0) {
  229. res.data.forEach((item: any) => {
  230. if (item.ibNo) {
  231. let option = {
  232. value: item.id,
  233. text: item.name ? `${item.ibNo} - ${item.name}` : item.ibNo,
  234. }
  235. agentLevels.value[0].options.push(option)
  236. }
  237. })
  238. } else {
  239. uni.showToast({
  240. title: res.msg, icon: 'none',
  241. })
  242. }
  243. }
  244. }
  245. // 表格列配置 根据types 切换
  246. const columns = computed(() => {
  247. // console.log(detailType.value, '23')
  248. // console.log(columnList.value[`3_${detailType.value}`])
  249. return columnList.value[`3_${detailType.value}`] || []
  250. })
  251. const mobilePrimaryFields = computed(() => {
  252. let list: any[] = []
  253. list = mobileList.value[`3_${detailType.value}`] || []
  254. return [
  255. ...list,
  256. {
  257. prop: 'more',
  258. type: 'more',
  259. width: 20,
  260. align: 'center',
  261. },
  262. ]
  263. })
  264. // 接口 根据types 切换(动态代理不同类型报表API)
  265. const listApi = computed(() => {
  266. return async (params: any) => {
  267. let apiFn = ibApi.tradeDw
  268. const type = detailType.value
  269. if (type == 1) apiFn = ibApi.tradeHistory
  270. else if (type == 4) apiFn = ibApi.tradePosition
  271. if (apiFn) {
  272. return await apiFn(params)
  273. }
  274. }
  275. })
  276. onLoad((options) => {
  277. console.log(options?.type, 'type')
  278. // search.reportType = options?.type;
  279. // searchParams.value.reportType = options?.type;
  280. detailType.value = options?.detailType
  281. })
  282. onMounted(async () => {
  283. loading.value = true
  284. await initIbTree()
  285. loading.value = false
  286. })
  287. const filterFields = computed(() => {
  288. const fields = []
  289. fields.push({
  290. key: 'platform',
  291. type: 'select',
  292. label: t('Label.Platform'),
  293. placeholder: t('placeholder.choose'),
  294. options: platformOptions,
  295. defaultValue: 'MT4',
  296. })
  297. agentLevels.value.forEach((level, index) => {
  298. fields.push({
  299. key: level.key,
  300. type: 'select',
  301. label: t('State.All'),
  302. options: level.options,
  303. placeholder: t('State.All'),
  304. onChange: (val: any) => handleAgentChange(val, index),
  305. defaultValue: index === 0 ? 0 : '',
  306. })
  307. })
  308. fields.push({
  309. key: 'login',
  310. type: 'input',
  311. label: t('Label.TradingAccount'),
  312. placeholder: t('Label.TradingAccount'),
  313. defaultValue: '',
  314. })
  315. fields.push({
  316. key: 'isShort',
  317. type: 'select',
  318. label: t('placeholder.choose'),
  319. placeholder: t('placeholder.choose'),
  320. options: isShortList.value,
  321. defaultValue: 0,
  322. isSelect: true,
  323. })
  324. fields.push({ key: 'date', label: t('placeholder.Start') + ' - ' + t('placeholder.End'), type: 'daterange' })
  325. return fields
  326. })
  327. watch(locale, () => {
  328. agentLevels.value = [
  329. {
  330. key: 'agentId_0',
  331. options: [
  332. { value: 0, text: t('news_add_field.IbReport.ALL') },
  333. { value: -1, text: t('news_add_field.IbReport.DirectlyUnder') },
  334. ],
  335. },
  336. ]
  337. nextTick(() => {
  338. setFields()
  339. })
  340. })
  341. </script>
  342. <style lang="scss" scoped>
  343. @import "@/uni.scss";
  344. .search-content {
  345. display: flex;
  346. justify-content: space-between;
  347. }
  348. .report-platform {
  349. display: flex;
  350. align-items: center;
  351. .checklist-box {
  352. cursor: pointer;
  353. box-sizing: border-box;
  354. padding: 0 px2rpx(20);
  355. border: 1px solid #DCDFE6;
  356. background-color: #f5f5f5;
  357. height: px2rpx(35);
  358. line-height: px2rpx(35);
  359. border-radius: px2rpx(4) 0 0 px2rpx(4);
  360. &:last-child {
  361. border-radius: 0 px2rpx(4) px2rpx(4) 0;
  362. }
  363. &.active {
  364. color: var(--color-white);
  365. background-color: var(--color-error);
  366. border-color: var(--color-error);
  367. }
  368. }
  369. }
  370. .search-input-box {
  371. .uni-input {
  372. height: px2rpx(35);
  373. border: 1px solid #DCDFE6;
  374. padding: 0 px2rpx(20);
  375. border-radius: px2rpx(4);
  376. background-color: rgba(var(--bs-body-bg-rgb), var(--bs-bg-opacity)) !important;
  377. }
  378. }
  379. .agent-select {
  380. width: px2rpx(240);
  381. }
  382. .search-btn {
  383. height: px2rpx(36);
  384. line-height: px2rpx(36);
  385. margin: 0;
  386. }
  387. </style>