| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523 |
- <template>
- <cwg-page-wrapper class="create-page" :isHeaderFixed="true">
- <cwg-header :title="t('Home.page_ib.item3')" />
- <view class="account-content">
- <view class="search-content">
- <view class="search-bar">
- <cwg-complex-search :fields="filterFields" v-model="searchParams" @search="handleSearch" @reset="handleReset" />
- </view>
- </view>
- <cwg-tabel
- ref="tableRef"
- :columns="columns"
- :mobilePrimaryFields="mobilePrimaryFields"
- :queryParams="search"
- :api="listApi"
- :show-operation="false"
- :showPagination="true"
- :showSummary="true"
- :summaryMethod="getSummaries"
- >
- </cwg-tabel>
- </view>
- </cwg-page-wrapper>
- </template>
- <script setup lang="ts">
- // 报告
- import { ref, computed, onMounted, watch } from 'vue'
- import { useI18n } from 'vue-i18n'
- import Config from '@/config/index'
- import { ibApi } from '@/service/ib'
- import { columnList, mobileList, platformOptions, customTypeList } from '@/pages/ib/const/report'
- import { useFilters } from '@/composables/useFilters'
- import { isAfterJuly28 } from '@/utils/dateUtils'
- import useUserStore from '@/stores/use-user-store'
- const { numberFormat } = useFilters()
- const { t } = useI18n()
- let { Code } = Config
- const { userInfo } = useUserStore()
- const tableRef = ref(null)
- const typeList = ref([
- { text: t('Ib.Report.Title1'), value: 1 },
- { text: t('Ib.Report.Title2'), value: 2 },
- { text: t('Ib.Report.Title3'), value: 3 },
- { text: t('Ib.Report.Title6'), value: 4 },
- { text: t('Ib.Report.Title5'), value: 5 },
- { text: t('news_add_field.IbReport.Title6'), value: 6 },
- { text: t('Ib.Report.Title7'), value: 7 },
- { text: t('Ib.Report.Title8'), value: 24 },
- ])
- const detailTypeList = ref([
- { text: t('Ib.Report.Tit1'), value: 1 },
- { text: t('Ib.Report.Tit2'), value: 2 },
- { text: t('Ib.Report.Tit3'), value: 3 },
- { text: t('Ib.Report.Tit4'), value: 4 },
- ])
- const isShortList = ref([
- { text: t('State.All'), value: 0 },
- { text: t('Ib.Report.item1'), value: 1 },
- { text: t('Ib.Report.item2'), value: 2 },
- ])
- const now = new Date()
- const year = now.getFullYear()
- const month = String(now.getMonth() + 1).padStart(2, '0')
- const day = String(now.getDate()).padStart(2, '0')
- const defaultDateRange = [`${year}-${month}-01`, `${year}-${month}-${day}`]
- const searchParams = ref<any>({
- reportType: 1,
- detail_type: null,
- customType: 0,
- platform: 'MT4',
- agentId: '',
- login: '',
- cId: '',
- isShort: 0,
- date: defaultDateRange,
- })
- const search = ref({
- reportType: 1,
- detail_type: null as number | null,
- customType: 0,
- platform: 'MT4',
- startDate: defaultDateRange[0],
- endDate: defaultDateRange[1],
- agentId: '',
- login: '',
- cId: '',
- isShort: 0,
- })
- const country = computed(() => {
- return userInfo.customInfo.country
- })
- const agentIdOpts = ref<any[]>([
- { value: 0, label: t('news_add_field.IbReport.ALL'), children: [] },
- {
- value: -1,
- label: t('news_add_field.IbReport.DirectlyUnder'),
- children: [],
- },
- ])
- const handleItemChange = (e: any) => {}
- const getSummaries = (param: any) => {
- const { columns, summaryData } = param
- const sums: string[] = []
- if (!summaryData || Object.keys(summaryData).length === 0) return sums
- columns.forEach((column: any, index: number) => {
- if (index === 0) {
- sums[index] = t("Label.Total")
- return
- }
- const type = search.value.reportType
- const detailType = search.value.detail_type
- // 根据不同的列 prop 进行合计数据显示和格式化
- const prop = column.prop
- if (!prop) {
- sums[index] = ""
- return
- }
- if (type == 1) {
- if (['deposit', 'withdrawal', 'credit'].includes(prop)) {
- sums[index] = summaryData[prop] ? numberFormat(summaryData[prop]) : "0"
- } else {
- sums[index] = ""
- }
- } else if (type == 2) {
- if (['volume', 'rebateAmount', 'commissionAmount'].includes(prop)) {
- sums[index] = summaryData[prop] ? numberFormat(summaryData[prop]) : "0"
- } else {
- sums[index] = ""
- }
- } else if (type == 3) {
- if (detailType == 4) {
- if (['volume', 'storage', 'taxes', 'profit'].includes(prop)) {
- sums[index] = summaryData[prop] ? numberFormat(summaryData[prop]) : "0"
- } else {
- sums[index] = ""
- }
- } else {
- if (['commission', 'volume', 'storage', 'taxes', 'profit', 'totalProfit'].includes(prop)) {
- sums[index] = summaryData[prop] ? numberFormat(summaryData[prop]) : "0"
- } else {
- sums[index] = ""
- }
- }
- } else if (type == 4) {
- if (['credit', 'balance', 'equity', 'floating'].includes(prop)) {
- sums[index] = summaryData[prop] ? numberFormat(summaryData[prop]) : "0"
- } else {
- sums[index] = ""
- }
- } else if (type == 6) {
- if (prop === 'amount') {
- sums[index] = summaryData[prop] ? numberFormat(summaryData[prop]) : "0"
- } else {
- sums[index] = ""
- }
- } else if (type == 7) {
- if (['fxVolume', 'cfdVolume', 'indexVolume', 'metalVolume'].includes(prop)) {
- sums[index] = summaryData[prop] ? numberFormat(summaryData[prop]) : "0"
- } else {
- sums[index] = ""
- }
- } else if (type == 24) {
- if (prop === 'volume') {
- sums[index] = summaryData[prop] ? numberFormat(summaryData[prop]) + " /手" : "0"
- } else if (prop === 'rebate') {
- sums[index] = summaryData[prop] ? "$" + numberFormat(summaryData[prop]) : "0"
- } else {
- sums[index] = ""
- }
- } else {
- sums[index] = ""
- }
- })
- return sums
- }
- const normalizePickerValue = (val: any) => {
- if (Array.isArray(val)) return val[val.length - 1]
- return val
- }
- const handleSearch = (params: any) => {
- const payload: any = { ...params }
- if (payload.date && Array.isArray(payload.date) && payload.date.length === 2) {
- payload.startDate = payload.date[0]
- payload.endDate = payload.date[1]
- } else {
- payload.startDate = ''
- payload.endDate = ''
- }
- delete payload.date
- payload.agentId = normalizePickerValue(payload.agentId)
- const type = Number(payload.reportType)
- if (![1, 3, 4, 7, 24].includes(type)) payload.platform = ''
- if (![1, 2, 3, 4, 7].includes(type)) payload.login = ''
- if (type !== 7) payload.cId = ''
- if (![3, 7].includes(type)) payload.isShort = 0
- if (type !== 3) payload.detail_type = null
- if (type !== 24) payload.customType = 0
- search.value = {
- reportType: payload.reportType,
- detail_type: payload.detail_type,
- customType: payload.customType,
- platform: payload.platform,
- startDate: payload.startDate,
- endDate: payload.endDate,
- agentId: payload.agentId,
- login: payload.login,
- cId: payload.cId,
- isShort: payload.isShort,
- }
- tableRef.value?.refreshTable?.()
- }
- const handleReset = (emptyParams: any) => {
- handleSearch(emptyParams)
- }
- const initIbTree = async () => {
- const res = await ibApi.ibTree({ pid: 0 })
- if (res.code === Code.StatusOK) {
- if (res.data && res.data.length > 0) {
- res.data.forEach((item: any) => {
- if (item.ibNo) {
- let option = {
- value: item.id,
- label: item.name ? `${item.ibNo} - ${item.name}` : item.ibNo,
- name: item.name,
- children: [],
- }
- agentIdOpts.value.push(option)
- }
- })
- } else {
- uni.showToast({
- title: res.msg, icon: 'none',
- })
- }
- }
- }
- const onnodeclick = async (node: any) => {
- const val = node.value
- if (node.children && node.children.length > 0) {
- return
- }
- try {
- // uni.showLoading({ title: t('Msg.Loading') || 'Loading...', mask: true })
- const res = await ibApi.ibTree({ pid: val })
- if (res.code === Code.StatusOK) {
- if (res.data && res.data.length > 0) {
- const newChildren: any[] = []
- res.data.forEach((item: any) => {
- if (item.ibNo) {
- newChildren.push({
- value: item.id,
- label: item.name ? `${item.ibNo} - ${item.name}` : item.ibNo,
- name: item.name,
- children: [],
- })
- }
- })
- node.children = newChildren
- } else {
- delete node.children
- }
- } else {
- uni.showToast({
- title: res.msg || 'Error',
- icon: 'none',
- })
- }
- } catch (error) {
- uni.showToast({ title: 'Error', icon: 'none' })
- } finally {
- // uni.hideLoading()
- }
- }
- // 表格列配置 根据types 切换
- const columns = computed(() => {
- if (search.value.reportType === 3) {
- return columnList[`3_${search.value.detail_type}` as keyof typeof columnList] || []
- }
- return columnList[search.value.reportType as keyof typeof columnList] || []
- })
- const mobilePrimaryFields = computed(() => {
- let list: any[] = []
- if (search.value.reportType === 3) {
- list = mobileList[`3_${search.value.detail_type}` as keyof typeof mobileList] || []
- } else {
- list = mobileList[search.value.reportType as keyof typeof mobileList] || []
- }
- return [
- ...list,
- {
- prop: 'more',
- type: 'more',
- width: 20,
- align: 'right',
- },
- ]
- })
- // 接口 根据types 切换(动态代理不同类型报表API)
- const listApi = computed(() => {
- return async (params: any) => {
- let apiFn: any
- const type = search.value.reportType
- const detailType = search.value.detail_type
- if (type == 1) apiFn = ibApi.tradeDw
- else if (type == 2) apiFn = ibApi.tradeAgentCommission
- else if (type == 3) {
- if (detailType == 1) apiFn = ibApi.tradeHistory
- else if (detailType == 2) apiFn = ibApi.tradePendingHistory
- else if (detailType == 3) apiFn = ibApi.tradePending
- else if (detailType == 4) apiFn = ibApi.tradePosition
- } else if (type == 4) apiFn = ibApi.tradeAccount
- else if (type == 5) apiFn = ibApi.tradeIb
- else if (type == 6) apiFn = ibApi.ibReportBalance
- else if (type == 7) apiFn = ibApi.tradeSymbolCategory
- else if (type == 24) apiFn = ibApi.tradeSalesHidden
- if (apiFn) {
- if (type == 2) {
- const isVietnam = country.value === 'VN' // 这里需要你实际的取国家逻辑
- return await apiFn(params, isVietnam)
- }
- return await apiFn(params)
- }
- return Promise.reject('No API found')
- }
- })
- const groupCurrency1 = (type: string) => {
- if (type == 'GBP') return '£'
- if (type == 'USD') return '$'
- if (type == 'EUR') return '€'
- if (type == 'USC') return '¢'
- return '$'
- }
- const groupTypeName = (type: string | number) => {
- if (type == '1') return t('AccountType.ClassicAccount')
- if (type == '2') return t('AccountType.SeniorAccount')
- if (type == '3') return isAfterJuly28() ? '--' : t('AccountType.AgencyAccount')
- if (type == '5') return t('AccountType.SpeedAccount')
- if (type == '6') return t('AccountType.SpeedAccount')
- if (type == '7') return t('AccountType.StandardAccount')
- if (type == '8') return t('AccountType.CentAccount')
- return '--'
- }
- watch(() => searchParams.value.reportType, (val) => {
- const type = Number(val)
- search.value.reportType = type
- if (type === 24) {
- searchParams.value.customType = 0
- searchParams.value.detail_type = null
- search.value.customType = 0
- search.value.detail_type = null
- } else if (type === 3) {
- if (searchParams.value.detail_type == null) searchParams.value.detail_type = 1
- if (search.value.detail_type == null) search.value.detail_type = 1
- } else {
- searchParams.value.detail_type = null
- search.value.detail_type = null
- searchParams.value.customType = 0
- search.value.customType = 0
- }
- }, { immediate: true })
- watch(() => searchParams.value.detail_type, (val) => {
- search.value.detail_type = val == null ? null : Number(val)
- })
- watch(() => searchParams.value.platform, (val) => {
- search.value.platform = val
- })
- watch(() => searchParams.value.customType, (val) => {
- search.value.customType = val
- })
- watch(() => searchParams.value.isShort, (val) => {
- search.value.isShort = val
- })
- onMounted(() => {
- initIbTree()
- })
- const filterFields = computed(() => {
- const type = Number(searchParams.value.reportType ?? 1)
- const fields: any[] = [
- { key: 'reportType', type: 'select', label: t('Home.page_ib.item3'), placeholder: t('placeholder.choose'), options: typeList.value, defaultValue: 1, isSelect: true },
- ]
- if (type === 3) {
- fields.push({ key: 'detail_type', type: 'select', label: t('placeholder.choose'), placeholder: t('placeholder.choose'), options: detailTypeList.value, defaultValue: 1, isSelect: true })
- }
- if ([1, 3, 4, 7, 24].includes(type)) {
- fields.push({ key: 'platform', type: 'select', label: t('Label.Platform'), placeholder: t('placeholder.choose'), options: platformOptions, defaultValue: 'MT4' })
- }
- if (type === 24) {
- fields.push({ key: 'customType', type: 'select', label: t('placeholder.choose'), placeholder: t('placeholder.choose'), options: customTypeList, defaultValue: 0, isSelect: true })
- }
- fields.push({
- key: 'agentId',
- type: 'picker',
- label: t('State.All'),
- options: agentIdOpts.value,
- popupTitle: t('State.All'),
- map: { value: 'value', text: 'label' },
- onChange: handleItemChange,
- onNodeClick: onnodeclick,
- defaultValue: '',
- })
- if ([1, 2, 3, 4, 7].includes(type)) {
- fields.push({ key: 'login', type: 'input', label: t('Label.TradingAccount'), placeholder: t('Label.TradingAccount'), defaultValue: '' })
- }
- if (type === 7) {
- fields.push({ key: 'cId', type: 'input', label: 'CID', placeholder: 'CID', defaultValue: '' })
- }
- if ([3, 7].includes(type)) {
- fields.push({ key: 'isShort', type: 'select', label: t('placeholder.choose'), placeholder: t('placeholder.choose'), options: isShortList.value, defaultValue: 0, isSelect: true })
- }
- fields.push({ key: 'date', label: t('placeholder.Start') + ' - ' + t('placeholder.End'), type: 'daterange' })
- return fields
- })
- </script>
- <style lang="scss" scoped>
- @import "@/uni.scss";
- .search-content {
- display: flex;
- justify-content: space-between;
- }
- .report-platform {
- display: flex;
- align-items: center;
- .checklist-box {
- cursor: pointer;
- box-sizing: border-box;
- padding: 0 px2rpx(20);
- border: 1px solid #DCDFE6;
- background-color: #f5f5f5;
- height: px2rpx(35);
- line-height: px2rpx(35);
- border-radius: px2rpx(4) 0 0 px2rpx(4);
- &:last-child {
- border-radius: 0 px2rpx(4) px2rpx(4) 0;
- }
- &.active {
- color: var(--color-white);
- background-color: var(--color-error);
- border-color: var(--color-error);
- }
- }
- }
- .search-input-box {
- .uni-input {
- height: px2rpx(35);
- border: 1px solid #DCDFE6;
- padding: 0 px2rpx(20);
- border-radius: px2rpx(4);
- background-color: #fff;
- }
- }
- .agent-select {
- width: px2rpx(240);
- }
- .search-btn {
- height: px2rpx(36);
- line-height: px2rpx(36);
- margin: 0;
- }
- </style>
|