applyIbDialog.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553
  1. <template>
  2. <cwg-popup :title="t('Ib.Report.Title5')" :visible="visible" @close="closeDia" @confirm="confirmDia">
  3. <view class="dia-content">
  4. <uni-forms ref="formRef" labelWidth="200">
  5. <uni-forms-item v-if="isFormApplyIb" :label="t('Ib.Custom.Manage3')+':'" prop="customerId">
  6. <cwg-combox v-model:value="addAgentForm.customerId" :options="customerList"
  7. :placeholder="t('placeholder.choose')" filterable/>
  8. </uni-forms-item>
  9. <view class="commission-groups">
  10. <view v-for="(group, gIndex) in commissionTemplateTableData" :key="gIndex" class="group-card">
  11. <!-- 头部开关和标题 -->
  12. <view class="group-header" @click="toggleGroup(group)">
  13. <view class="group-title">
  14. <text class="title-text">{{ group.accountGroup }}</text>
  15. </view>
  16. <view class="group-switch" @click.stop>
  17. <switch :checked="group.isOpen" @change="(e) => onGroupSwitchChange(e, group)" color="#2b5aed" style="transform:scale(0.8)"/>
  18. </view>
  19. </view>
  20. <!-- 展开的内容区 -->
  21. <view v-show="group.isOpen" class="group-body">
  22. <view v-for="(item, iIndex) in group.items" :key="iIndex" class="item-row">
  23. <view class="item-title">
  24. <text class="type-badge">{{ item.dataType === 'rebates' ? 'Rebates' : 'Commissions' }}</text>
  25. <text class="type-text">{{ item.type }}</text>
  26. </view>
  27. <view class="item-fields">
  28. <!-- METAL -->
  29. <view class="field-col">
  30. <text class="field-label">METAL</text>
  31. <cwg-combox
  32. v-model:value="item.energy"
  33. :options="formatOptions(item.energyOptions)"
  34. :placeholder="t('placeholder.choose')"
  35. />
  36. </view>
  37. <!-- FX -->
  38. <view class="field-col">
  39. <text class="field-label">FX</text>
  40. <cwg-combox
  41. v-model:value="item.forex"
  42. :options="formatOptions(item.forexOptions)"
  43. :placeholder="t('placeholder.choose')"
  44. />
  45. </view>
  46. <!-- ENERGY -->
  47. <view class="field-col">
  48. <text class="field-label">ENERGY</text>
  49. <cwg-combox
  50. v-model:value="item.energy2"
  51. :options="formatOptions(item.energy2Options)"
  52. :placeholder="t('placeholder.choose')"
  53. />
  54. </view>
  55. <!-- CFD -->
  56. <view class="field-col">
  57. <text class="field-label">CFD</text>
  58. <cwg-combox
  59. v-model:value="item.index"
  60. :options="formatOptions(item.indexOptions)"
  61. :placeholder="t('placeholder.choose')"
  62. />
  63. </view>
  64. <!-- INDEX -->
  65. <view class="field-col">
  66. <text class="field-label">INDEX</text>
  67. <cwg-combox
  68. v-model:value="item.metal"
  69. :options="formatOptions(item.metalOptions)"
  70. :placeholder="t('placeholder.choose')"
  71. />
  72. </view>
  73. </view>
  74. </view>
  75. </view>
  76. </view>
  77. </view>
  78. </uni-forms>
  79. </view>
  80. </cwg-popup>
  81. </template>
  82. <script setup lang="ts">
  83. import { ref, reactive, computed, onMounted, onUnmounted, watch } from 'vue'
  84. import { onLoad } from '@dcloudio/uni-app'
  85. import { useI18n } from 'vue-i18n' // uni-app 中已集成,但需配置
  86. import { customApi } from '@/service/custom'
  87. import { financialApi } from '@/service/financial'
  88. import Config from '@/config/index'
  89. import { ibApi } from '@/service/ib'
  90. import useUserStore from '@/stores/use-user-store'
  91. import { lang } from '@/composables/config'
  92. const props = defineProps({
  93. // 是否显示弹窗
  94. visible: {
  95. type: Boolean,
  96. default: false,
  97. },
  98. // 详情tableData
  99. detail: { type: Array, default: () => ([]) },
  100. isFormApplyIb: {
  101. type: Boolean,
  102. default: true,
  103. },
  104. })
  105. const { Code, Host80 } = Config
  106. const { t } = useI18n()
  107. const formRef = ref(null)
  108. const addAgentForm = ref({
  109. customerId: '',
  110. })
  111. const customerList = ref([])
  112. const commissionAccountTypeSettings = ref({
  113. ecn: { selectedIndex: null, selectedItem: null, loginType: '2' },
  114. standard: { selectedIndex: null, selectedItem: null, loginType: '7' },
  115. cent: { selectedIndex: null, selectedItem: null, loginType: '8' },
  116. })
  117. const commissionAccountTypeData = ref({
  118. ecn: [],
  119. standard: [],
  120. cent: [],
  121. })
  122. const commissionTemplateTableData = ref<any[]>([])
  123. const emit = defineEmits(['close', 'confirm'])
  124. onMounted(() => {
  125. initCommissionTemplateData(29634)
  126. })
  127. watch(() => props.detail, (val) => {
  128. if (val) {
  129. const { cId, id, comPoint1, hide1 } = val
  130. dialogForm.value = {
  131. cId, id, comPoint1, hide1,
  132. }
  133. initCommissionTemplateData(29634)
  134. // if (val.id) {
  135. // initCommissionTemplateData(val.id)
  136. // }
  137. }
  138. })
  139. const getSpreadLabelCommission = (item) => {
  140. return item.groupName || ''
  141. }
  142. const handleCommissionAccountTypeChange = (type, loginType) => {
  143. const setting = commissionAccountTypeSettings.value[type]
  144. const availableSpreads = getAvailableSpreadsCommission(loginType)
  145. if (
  146. setting.selectedIndex !== null &&
  147. setting.selectedIndex !== undefined
  148. ) {
  149. setting.selectedItem = availableSpreads[setting.selectedIndex] || null
  150. } else {
  151. setting.selectedItem = null
  152. }
  153. }
  154. const generateOptions = (currentValue) => {
  155. const options = [];
  156. for (let i = 0; i <= currentValue; i++) {
  157. options.push(i);
  158. }
  159. return options;
  160. }
  161. // 格式化 options 为 combox 期望的格式
  162. const formatOptions = (opts) => {
  163. if (!opts || !Array.isArray(opts)) return []
  164. return opts.map(val => ({ text: String(val), value: val }))
  165. }
  166. const toggleGroup = (group) => {
  167. group.isOpen = !group.isOpen
  168. }
  169. const onGroupSwitchChange = (e, group) => {
  170. group.isOpen = e.detail.value
  171. }
  172. const initCommissionTemplateData = async (customId: string | number) => {
  173. try {
  174. const res = await ibApi.getVietnamPoints({ customId })
  175. if (res.code == Code.StatusOK && res.data && Array.isArray(res.data)) {
  176. const groupedData: Record<string, any[]> = {}
  177. res.data.forEach((group: any) => {
  178. const accountGroup = group.groupCategoryName || '--'
  179. const valid = group.valid !== undefined ? group.valid : 1
  180. if (!groupedData[accountGroup]) {
  181. groupedData[accountGroup] = []
  182. }
  183. const rebates = Array.isArray(group.rebates) ? group.rebates : []
  184. const superRebates = Array.isArray(group.superRebates) ? group.superRebates : []
  185. if (superRebates.length > 0) {
  186. const rebateRow: any = {
  187. accountGroup,
  188. groupCategoryId: group.groupCategoryId,
  189. dataType: 'rebates',
  190. type: group.rebateTypeName || 'Point',
  191. valid,
  192. forex: 0,
  193. index: 0,
  194. metal: 0,
  195. energy: 0,
  196. energy2: 0,
  197. energy2Max: 0,
  198. forex1: 0,
  199. index1: 0,
  200. metal1: 0,
  201. energy1: 0,
  202. }
  203. rebates.forEach((rebate: any) => {
  204. if (rebate.symbolCategory === 1) rebateRow.forex = rebate.point || 0
  205. else if (rebate.symbolCategory === 2) rebateRow.index = rebate.point || 0
  206. else if (rebate.symbolCategory === 3) rebateRow.metal = rebate.point || 0
  207. else if (rebate.symbolCategory === 4) rebateRow.energy = rebate.point || 0
  208. else if (rebate.symbolCategory === 5) rebateRow.energy2 = rebate.point || 0
  209. })
  210. superRebates.forEach((rebate: any) => {
  211. if (rebate.symbolCategory === 1) rebateRow.forex1 = rebate.point || 0
  212. else if (rebate.symbolCategory === 2) rebateRow.index1 = rebate.point || 0
  213. else if (rebate.symbolCategory === 3) rebateRow.metal1 = rebate.point || 0
  214. else if (rebate.symbolCategory === 4) rebateRow.energy1 = rebate.point || 0
  215. else if (rebate.symbolCategory === 5) rebateRow.energy2Max = rebate.point || 0
  216. })
  217. rebateRow.forexOptions = generateOptions(rebateRow.forex1)
  218. rebateRow.indexOptions = generateOptions(rebateRow.index1)
  219. rebateRow.metalOptions = generateOptions(rebateRow.metal1)
  220. rebateRow.energyOptions = generateOptions(rebateRow.energy1)
  221. rebateRow.energy2Options = generateOptions(rebateRow.energy2Max)
  222. groupedData[accountGroup].push(rebateRow)
  223. }
  224. const commissions = Array.isArray(group.commissions) ? group.commissions : []
  225. const superCommissions = Array.isArray(group.superCommissions) ? group.superCommissions : []
  226. if (superCommissions.length > 0) {
  227. const commissionRow: any = {
  228. accountGroup,
  229. groupCategoryId: group.groupCategoryId,
  230. dataType: 'commissions',
  231. type: group.commissionTypeName || 'Commission',
  232. valid,
  233. forex: 0,
  234. index: 0,
  235. metal: 0,
  236. energy: 0,
  237. energy2: 0,
  238. energy2Max: 0,
  239. forex1: 0,
  240. index1: 0,
  241. metal1: 0,
  242. energy1: 0,
  243. }
  244. commissions.forEach((comm: any) => {
  245. if (comm.symbolCategory === 1) commissionRow.forex = comm.point || 0
  246. else if (comm.symbolCategory === 2) commissionRow.index = comm.point || 0
  247. else if (comm.symbolCategory === 3) commissionRow.metal = comm.point || 0
  248. else if (comm.symbolCategory === 4) commissionRow.energy = comm.point || 0
  249. else if (comm.symbolCategory === 5) commissionRow.energy2 = comm.point || 0
  250. })
  251. superCommissions.forEach((comm: any) => {
  252. if (comm.symbolCategory === 1) commissionRow.forex1 = comm.point || 0
  253. else if (comm.symbolCategory === 2) commissionRow.index1 = comm.point || 0
  254. else if (comm.symbolCategory === 3) commissionRow.metal1 = comm.point || 0
  255. else if (comm.symbolCategory === 4) commissionRow.energy1 = comm.point || 0
  256. else if (comm.symbolCategory === 5) commissionRow.energy2Max = comm.point || 0
  257. })
  258. commissionRow.forexOptions = generateOptions(commissionRow.forex1)
  259. commissionRow.indexOptions = generateOptions(commissionRow.index1)
  260. commissionRow.metalOptions = generateOptions(commissionRow.metal1)
  261. commissionRow.energyOptions = generateOptions(commissionRow.energy1)
  262. commissionRow.energy2Options = generateOptions(commissionRow.energy2Max)
  263. groupedData[accountGroup].push(commissionRow)
  264. }
  265. })
  266. // 将按 accountGroup 聚合后的对象转换为包含 accountGroup 和 items 数组的结构
  267. const finalData = Object.keys(groupedData).map((accountGroup) => {
  268. return {
  269. accountGroup,
  270. isOpen: false, // 默认不展开
  271. items: groupedData[accountGroup],
  272. }
  273. })
  274. console.log('tableData',finalData)
  275. commissionTemplateTableData.value = finalData
  276. return
  277. }
  278. commissionTemplateTableData.value = []
  279. uni.showToast({
  280. title: res.msg || t('Ib.Custom.GetDataFailed'),
  281. icon: 'none',
  282. })
  283. } catch (error) {
  284. commissionTemplateTableData.value = []
  285. uni.showToast({ title: t('Ib.Custom.GetDataFailed'), icon: 'none' })
  286. }
  287. }
  288. const toVerified = () => {
  289. // 确认按钮点击事件
  290. emit('confirm')
  291. }
  292. const cancel = () => {
  293. // 取消按钮点击事件
  294. emit('close')
  295. }
  296. const closeDia = () => {
  297. emit('close')
  298. }
  299. const confirmDia = async () => {
  300. // 确认按钮点击事件
  301. const loginConfig = []
  302. Object.keys(commissionAccountTypeSettings.value).forEach((key) => {
  303. const setting = commissionAccountTypeSettings.value[key]
  304. if (setting.selectedItem) {
  305. loginConfig.push(setting.selectedItem)
  306. }
  307. })
  308. let res = await ibApi.customCommissionPoint({
  309. id: dialogForm.value.id,
  310. loginConfig,
  311. })
  312. if (res.code == Code.StatusOK) {
  313. uni.showToast({
  314. title: t('Msg.ModifySuccess'),
  315. })
  316. cancel()
  317. } else {
  318. uni.showToast({
  319. title: res.msg,
  320. icon: 'none',
  321. })
  322. }
  323. emit('confirm')
  324. }
  325. </script>
  326. <style lang="scss" scoped>
  327. @import "@/uni.scss";
  328. .commission-groups {
  329. margin-top: px2rpx(10);
  330. padding-bottom: px2rpx(150); /* 预留底部空间,防止最下面的下拉框被截断或遮挡 */
  331. }
  332. .group-card {
  333. border: 1px solid #ebeef5;
  334. border-radius: px2rpx(6);
  335. margin-bottom: px2rpx(15);
  336. background-color: #fff;
  337. /* overflow: hidden; 移除此属性,防止下拉框被遮挡截断 */
  338. }
  339. .group-header {
  340. display: flex;
  341. justify-content: space-between;
  342. align-items: center;
  343. padding: px2rpx(10) px2rpx(15);
  344. background-color: #f5f7fa;
  345. border-bottom: 1px solid #ebeef5;
  346. border-top-left-radius: px2rpx(6);
  347. border-top-right-radius: px2rpx(6);
  348. }
  349. .group-title {
  350. font-size: px2rpx(14);
  351. font-weight: bold;
  352. color: #303133;
  353. }
  354. .group-body {
  355. padding: px2rpx(15);
  356. }
  357. .item-row {
  358. margin-bottom: px2rpx(15);
  359. padding-bottom: px2rpx(15);
  360. border-bottom: 1px dashed #ebeef5;
  361. &:last-child {
  362. margin-bottom: 0;
  363. padding-bottom: 0;
  364. border-bottom: none;
  365. }
  366. }
  367. .item-title {
  368. margin-bottom: px2rpx(10);
  369. display: flex;
  370. align-items: center;
  371. .type-badge {
  372. background-color: #e1f3d8;
  373. color: #67c23a;
  374. padding: px2rpx(2) px2rpx(8);
  375. border-radius: px2rpx(4);
  376. font-size: px2rpx(12);
  377. margin-right: px2rpx(8);
  378. }
  379. .type-text {
  380. font-size: px2rpx(13);
  381. color: #606266;
  382. }
  383. }
  384. .item-fields {
  385. display: flex;
  386. flex-wrap: wrap;
  387. gap: px2rpx(10);
  388. justify-content: flex-start;
  389. }
  390. .field-col {
  391. flex: 0 0 calc(20% - px2rpx(10));
  392. min-width: px2rpx(80);
  393. max-width: px2rpx(120);
  394. display: flex;
  395. flex-direction: column;
  396. .field-label {
  397. font-size: px2rpx(12);
  398. color: #909399;
  399. margin-bottom: px2rpx(5);
  400. }
  401. }
  402. .dialog-account-adjust-body {
  403. padding: 20rpx;
  404. }
  405. .account-adjust-cid-row {
  406. display: flex;
  407. align-items: center;
  408. margin-bottom: 20rpx;
  409. }
  410. .account-adjust-cid-label {
  411. color: #606266;
  412. margin-right: px2rpx(5);
  413. }
  414. .account-adjust-cid-value {
  415. font-weight: bold;
  416. color: #303133;
  417. }
  418. .form-section {
  419. margin-bottom: 20rpx;
  420. }
  421. .section-title {
  422. display: flex;
  423. align-items: center;
  424. margin-bottom: px2rpx(15);
  425. font-weight: bold;
  426. font-size: px2rpx(14);
  427. }
  428. .section-title i {
  429. margin-right: 10rpx;
  430. }
  431. .account-type-grid {
  432. }
  433. .account-type-card {
  434. display: flex;
  435. flex-direction: column;
  436. margin-bottom: px2rpx(20);
  437. }
  438. .account-type-label {
  439. margin-bottom: 10rpx;
  440. font-size: 14rpx;
  441. }
  442. .account-select {
  443. width: 100%;
  444. }
  445. .dialog-account-adjust-footer {
  446. padding: 20rpx;
  447. }
  448. .account-adjust-notes-panel {
  449. margin-bottom: 20rpx;
  450. }
  451. .account-adjust-notes-section {
  452. background-color: #f5f7fa;
  453. padding: 15rpx;
  454. border-radius: 8rpx;
  455. }
  456. .account-adjust-notes-title {
  457. display: flex;
  458. align-items: center;
  459. margin-bottom: px2rpx(10);
  460. font-weight: bold;
  461. font-size: px2rpx(13);
  462. }
  463. .account-adjust-notes-title-icon {
  464. margin-right: px2rpx(10);
  465. }
  466. .account-adjust-notes-list {
  467. margin-left: px2rpx(20);
  468. color: #606266;
  469. font-size: px2rpx(13);
  470. }
  471. .account-adjust-notes-list .list {
  472. margin-bottom: px2rpx(5);
  473. margin-left: px2rpx(10);
  474. }
  475. .account-adjust-footer-buttons {
  476. display: flex;
  477. justify-content: flex-end;
  478. gap: 15rpx;
  479. }
  480. .account-adjust-footer-buttons button {
  481. min-width: 120rpx;
  482. }
  483. </style>