applyIbDialog.vue 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666
  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 @change="changeCustomer" />
  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"
  18. style="transform:scale(0.8)" />
  19. </view>
  20. </view>
  21. <!-- 展开的内容区 -->
  22. <view v-show="group.isOpen" class="group-body">
  23. <view v-for="(item, iIndex) in group.items" :key="iIndex" class="item-row">
  24. <view class="item-title">
  25. <!-- <text class="type-badge">{{ item.dataType === 'rebates' ? 'Rebates' : 'Commissions' }}</text>-->
  26. <text class="type-text">{{ item.type }}</text>
  27. </view>
  28. <view class="item-fields">
  29. <!-- METAL -->
  30. <view class="field-col">
  31. <text class="field-label">METAL</text>
  32. <cwg-combox
  33. v-model:value="item.energy"
  34. :options="formatOptions(item.energyOptions)"
  35. :placeholder="t('placeholder.choose')"
  36. />
  37. </view>
  38. <!-- FX -->
  39. <view class="field-col">
  40. <text class="field-label">FX</text>
  41. <cwg-combox
  42. v-model:value="item.forex"
  43. :options="formatOptions(item.forexOptions)"
  44. :placeholder="t('placeholder.choose')"
  45. />
  46. </view>
  47. <!-- ENERGY -->
  48. <view class="field-col">
  49. <text class="field-label">ENERGY</text>
  50. <cwg-combox
  51. v-model:value="item.energy2"
  52. :options="formatOptions(item.energy2Options)"
  53. :placeholder="t('placeholder.choose')"
  54. />
  55. </view>
  56. <!-- CFD -->
  57. <view class="field-col">
  58. <text class="field-label">CFD</text>
  59. <cwg-combox
  60. v-model:value="item.index"
  61. :options="formatOptions(item.indexOptions)"
  62. :placeholder="t('placeholder.choose')"
  63. />
  64. </view>
  65. <!-- INDEX -->
  66. <view class="field-col">
  67. <text class="field-label">INDEX</text>
  68. <cwg-combox
  69. v-model:value="item.metal"
  70. :options="formatOptions(item.metalOptions)"
  71. :placeholder="t('placeholder.choose')"
  72. />
  73. </view>
  74. </view>
  75. </view>
  76. </view>
  77. </view>
  78. </view>
  79. </uni-forms>
  80. </view>
  81. </cwg-popup>
  82. </template>
  83. <script setup lang="ts">
  84. import { ref, reactive, computed, onMounted, onUnmounted, watch } from 'vue'
  85. import { onLoad } from '@dcloudio/uni-app'
  86. import { useI18n } from 'vue-i18n' // uni-app 中已集成,但需配置
  87. import { customApi } from '@/service/custom'
  88. import { financialApi } from '@/service/financial'
  89. import Config from '@/config/index'
  90. import { ibApi } from '@/service/ib'
  91. import useUserStore from '@/stores/use-user-store'
  92. import { lang } from '@/composables/config'
  93. const props = defineProps({
  94. // 是否显示弹窗
  95. visible: {
  96. type: Boolean,
  97. default: false,
  98. },
  99. // 详情tableData
  100. detail: { type: Array, default: () => ({}) },
  101. isFormApplyIb: {
  102. type: Boolean,
  103. default: true,
  104. },
  105. })
  106. const { Code, Host80 } = Config
  107. const { t } = useI18n()
  108. const formRef = ref(null)
  109. const addAgentForm = ref({
  110. customerId: '',
  111. })
  112. const customerList = ref([])
  113. const commissionAccountTypeSettings = ref({
  114. ecn: { selectedIndex: null, selectedItem: null, loginType: '2' },
  115. standard: { selectedIndex: null, selectedItem: null, loginType: '7' },
  116. cent: { selectedIndex: null, selectedItem: null, loginType: '8' },
  117. })
  118. const commissionAccountTypeData = ref({
  119. ecn: [],
  120. standard: [],
  121. cent: [],
  122. })
  123. const commissionTemplateTableData = ref<any[]>([])
  124. const emit = defineEmits(['close', 'confirm'])
  125. onMounted(() => {
  126. initCommissionTemplateData(29634)
  127. })
  128. watch(() => props.visible, (val) => {
  129. if (val) {
  130. loadCustomerList()
  131. // initCommissionTemplateData(29634)
  132. if (props.detail.id) {
  133. initCommissionTemplateData(val.id)
  134. }
  135. }
  136. })
  137. const getSpreadLabelCommission = (item) => {
  138. return item.groupName || ''
  139. }
  140. const handleCommissionAccountTypeChange = (type, loginType) => {
  141. const setting = commissionAccountTypeSettings.value[type]
  142. const availableSpreads = getAvailableSpreadsCommission(loginType)
  143. if (
  144. setting.selectedIndex !== null &&
  145. setting.selectedIndex !== undefined
  146. ) {
  147. setting.selectedItem = availableSpreads[setting.selectedIndex] || null
  148. } else {
  149. setting.selectedItem = null
  150. }
  151. }
  152. const generateOptions = (currentValue) => {
  153. const options = []
  154. for (let i = 0; i <= currentValue; i++) {
  155. options.push(i)
  156. }
  157. return options
  158. }
  159. // 格式化 options 为 combox 期望的格式
  160. const formatOptions = (opts) => {
  161. if (!opts || !Array.isArray(opts)) return []
  162. return opts.map(val => ({ text: String(val), value: val }))
  163. }
  164. const toggleGroup = (group) => {
  165. group.isOpen = !group.isOpen
  166. }
  167. const onGroupSwitchChange = (e, group) => {
  168. group.isOpen = e.detail.value
  169. }
  170. const initCommissionTemplateData = async (customId: string | number) => {
  171. try {
  172. const res = await ibApi.getVietnamPoints({ customId })
  173. if (res.code == Code.StatusOK && res.data && Array.isArray(res.data)) {
  174. const groupedData: Record<string, any[]> = {}
  175. res.data.forEach((group: any) => {
  176. const accountGroup = group.groupCategoryName || '--'
  177. const valid = group.valid !== undefined ? group.valid : 1
  178. if (!groupedData[accountGroup]) {
  179. groupedData[accountGroup] = []
  180. }
  181. const rebates = Array.isArray(group.rebates) ? group.rebates : []
  182. const superRebates = Array.isArray(group.superRebates) ? group.superRebates : []
  183. if (superRebates.length > 0) {
  184. const rebateRow: any = {
  185. accountGroup,
  186. groupCategoryId: group.groupCategoryId,
  187. dataType: 'rebates',
  188. type: group.rebateTypeName || 'Point',
  189. valid,
  190. forex: 0,
  191. index: 0,
  192. metal: 0,
  193. energy: 0,
  194. energy2: 0,
  195. energy2Max: 0,
  196. forex1: 0,
  197. index1: 0,
  198. metal1: 0,
  199. energy1: 0,
  200. }
  201. rebates.forEach((rebate: any) => {
  202. if (rebate.symbolCategory === 1) rebateRow.forex = rebate.point || 0
  203. else if (rebate.symbolCategory === 2) rebateRow.index = rebate.point || 0
  204. else if (rebate.symbolCategory === 3) rebateRow.metal = rebate.point || 0
  205. else if (rebate.symbolCategory === 4) rebateRow.energy = rebate.point || 0
  206. else if (rebate.symbolCategory === 5) rebateRow.energy2 = rebate.point || 0
  207. })
  208. superRebates.forEach((rebate: any) => {
  209. if (rebate.symbolCategory === 1) rebateRow.forex1 = rebate.point || 0
  210. else if (rebate.symbolCategory === 2) rebateRow.index1 = rebate.point || 0
  211. else if (rebate.symbolCategory === 3) rebateRow.metal1 = rebate.point || 0
  212. else if (rebate.symbolCategory === 4) rebateRow.energy1 = rebate.point || 0
  213. else if (rebate.symbolCategory === 5) rebateRow.energy2Max = rebate.point || 0
  214. })
  215. rebateRow.forexOptions = generateOptions(rebateRow.forex1)
  216. rebateRow.indexOptions = generateOptions(rebateRow.index1)
  217. rebateRow.metalOptions = generateOptions(rebateRow.metal1)
  218. rebateRow.energyOptions = generateOptions(rebateRow.energy1)
  219. rebateRow.energy2Options = generateOptions(rebateRow.energy2Max)
  220. groupedData[accountGroup].push(rebateRow)
  221. }
  222. const commissions = Array.isArray(group.commissions) ? group.commissions : []
  223. const superCommissions = Array.isArray(group.superCommissions) ? group.superCommissions : []
  224. if (superCommissions.length > 0) {
  225. const commissionRow: any = {
  226. accountGroup,
  227. groupCategoryId: group.groupCategoryId,
  228. dataType: 'commissions',
  229. type: group.commissionTypeName || 'Commission',
  230. valid,
  231. forex: 0,
  232. index: 0,
  233. metal: 0,
  234. energy: 0,
  235. energy2: 0,
  236. energy2Max: 0,
  237. forex1: 0,
  238. index1: 0,
  239. metal1: 0,
  240. energy1: 0,
  241. }
  242. commissions.forEach((comm: any) => {
  243. if (comm.symbolCategory === 1) commissionRow.forex = comm.point || 0
  244. else if (comm.symbolCategory === 2) commissionRow.index = comm.point || 0
  245. else if (comm.symbolCategory === 3) commissionRow.metal = comm.point || 0
  246. else if (comm.symbolCategory === 4) commissionRow.energy = comm.point || 0
  247. else if (comm.symbolCategory === 5) commissionRow.energy2 = comm.point || 0
  248. })
  249. superCommissions.forEach((comm: any) => {
  250. if (comm.symbolCategory === 1) commissionRow.forex1 = comm.point || 0
  251. else if (comm.symbolCategory === 2) commissionRow.index1 = comm.point || 0
  252. else if (comm.symbolCategory === 3) commissionRow.metal1 = comm.point || 0
  253. else if (comm.symbolCategory === 4) commissionRow.energy1 = comm.point || 0
  254. else if (comm.symbolCategory === 5) commissionRow.energy2Max = comm.point || 0
  255. })
  256. commissionRow.forexOptions = generateOptions(commissionRow.forex1)
  257. commissionRow.indexOptions = generateOptions(commissionRow.index1)
  258. commissionRow.metalOptions = generateOptions(commissionRow.metal1)
  259. commissionRow.energyOptions = generateOptions(commissionRow.energy1)
  260. commissionRow.energy2Options = generateOptions(commissionRow.energy2Max)
  261. groupedData[accountGroup].push(commissionRow)
  262. }
  263. })
  264. // 将按 accountGroup 聚合后的对象转换为包含 accountGroup 和 items 数组的结构
  265. const finalData = Object.keys(groupedData).map((accountGroup) => {
  266. return {
  267. accountGroup,
  268. isOpen: false, // 默认不展开
  269. items: groupedData[accountGroup],
  270. }
  271. })
  272. console.log('tableData', finalData)
  273. commissionTemplateTableData.value = finalData
  274. return
  275. }
  276. commissionTemplateTableData.value = []
  277. uni.showToast({
  278. title: res.msg || t('Ib.Custom.GetDataFailed'),
  279. icon: 'none',
  280. })
  281. } catch (error) {
  282. commissionTemplateTableData.value = []
  283. uni.showToast({ title: t('Ib.Custom.GetDataFailed'), icon: 'none' })
  284. }
  285. }
  286. // 加载客户列表
  287. const loadCustomerList = async () => {
  288. try {
  289. let res = await ibApi.customerSubsList({
  290. ibStatus: 1,
  291. })
  292. if (res.code == Code.StatusOK) {
  293. customerList.value = res.data.map(item => ({
  294. label: `${item.name || ''}-${item.cId}`,
  295. value: item.id || '',
  296. cId: item.cId // 保存 cId 供后续提交使用
  297. })) || []
  298. } else {
  299. uni.showToast({ title: res.msg, icon: 'none' })
  300. customerList.value = []
  301. }
  302. } catch (error) {
  303. console.error('加载客户列表失败:', error)
  304. customerList.value = []
  305. } finally {
  306. }
  307. }
  308. // 客户选择改变时触发
  309. const changeCustomer = (val) => {
  310. if (val) {
  311. initCommissionTemplateData(val)
  312. }else {
  313. commissionTemplateTableData.value = []
  314. }
  315. }
  316. // 构建佣金模板points数据
  317. const buildCommissionTemplatePoints = () => {
  318. const points: any[] = []
  319. const groupedData: Record<string, any> = {}
  320. // 由于现在的 commissionTemplateTableData 是 { accountGroup, isOpen, items } 嵌套结构,需要双层遍历提取
  321. commissionTemplateTableData.value.forEach((groupObj) => {
  322. groupObj.items.forEach((row: any) => {
  323. const groupId = row.groupCategoryId
  324. if (!groupedData[groupId]) {
  325. groupedData[groupId] = {
  326. groupCategoryId: groupId,
  327. commissions: [],
  328. rebates: [],
  329. valid: groupObj.isOpen ? 1 : 0,
  330. }
  331. }
  332. // 根据dataType添加到对应的数组
  333. const pointList = row.dataType === 'commissions'
  334. ? groupedData[groupId].commissions
  335. : groupedData[groupId].rebates
  336. // 添加各个symbolCategory的数据
  337. if (row.forex !== undefined && row.forex !== null) {
  338. pointList.push({ symbolCategory: 1, point: row.forex }) // FX
  339. }
  340. if (row.index !== undefined && row.index !== null) {
  341. pointList.push({ symbolCategory: 2, point: row.index }) // CFD
  342. }
  343. if (row.metal !== undefined && row.metal !== null) {
  344. pointList.push({ symbolCategory: 3, point: row.metal }) // INDEX
  345. }
  346. if (row.energy !== undefined && row.energy !== null) {
  347. pointList.push({ symbolCategory: 4, point: row.energy }) // METAL
  348. }
  349. if (row.energy2 !== undefined && row.energy2 !== null) {
  350. pointList.push({ symbolCategory: 5, point: row.energy2 }) // Energy
  351. }
  352. })
  353. })
  354. // 转换为数组格式
  355. Object.keys(groupedData).forEach((groupId) => {
  356. const group = groupedData[groupId]
  357. if (group.commissions.length > 0 || group.rebates.length > 0) {
  358. points.push({
  359. groupCategoryId: group.groupCategoryId,
  360. commissions: group.commissions.length > 0 ? group.commissions : undefined,
  361. rebates: group.rebates.length > 0 ? group.rebates : undefined,
  362. valid: group.valid,
  363. })
  364. }
  365. })
  366. return points
  367. }
  368. const toVerified = () => {
  369. // 确认按钮点击事件
  370. emit('confirm')
  371. }
  372. const closeDia = () => {
  373. commissionTemplateTableData.value = []
  374. emit('close')
  375. }
  376. const confirmDia = async () => {
  377. let customId, cId
  378. if (!props.isFormApplyIb) {
  379. if (!props.detail.id) {
  380. uni.showToast({ title: t('Ib.Custom.CustomerNotExist'), icon: 'none' })
  381. return
  382. }
  383. const applyIbRowData: any = props.detail || {}
  384. customId = applyIbRowData.id
  385. cId = applyIbRowData.cId
  386. } else {
  387. // 从其他地方打开,需要选择客户
  388. if (!addAgentForm.value.customerId) {
  389. uni.showToast({ title: t('placeholder.choose'), icon: 'none' })
  390. return
  391. }
  392. // 从客户列表中找到选中的客户对象
  393. const selectedCustomer: any = customerList.value.find(
  394. (item: any) => item.value === addAgentForm.value.customerId
  395. )
  396. if (!selectedCustomer) {
  397. uni.showToast({ title: t('Ib.Custom.CustomerNotFound'), icon: 'none' })
  398. return
  399. }
  400. customId = selectedCustomer.value
  401. cId = selectedCustomer.cId
  402. }
  403. try {
  404. // 构建points数据
  405. const points = buildCommissionTemplatePoints()
  406. console.log(points)
  407. // 调用新增代理申请接口
  408. const res = await ibApi.agentApplyAddPoint({
  409. customId: customId,
  410. cId: cId,
  411. points: points,
  412. })
  413. if (res.code == Code.StatusOK) {
  414. uni.showToast({ title: res.msg || t('Ib.Custom.SubmitSuccess'), icon: 'success' })
  415. closeDia()
  416. emit('confirm') // 刷新列表
  417. } else {
  418. uni.showToast({ title: res.msg || t('Ib.Custom.SubmitFailed'), icon: 'none' })
  419. }
  420. } catch (error) {
  421. console.error('新增代理失败:', error)
  422. uni.showToast({ title: t('Ib.Custom.SubmitFailed'), icon: 'none' })
  423. }
  424. }
  425. </script>
  426. <style lang="scss" scoped>
  427. @import "@/uni.scss";
  428. .commission-groups {
  429. margin-top: px2rpx(10);
  430. padding-bottom: px2rpx(150); /* 预留底部空间,防止最下面的下拉框被截断或遮挡 */
  431. }
  432. .group-card {
  433. border: 1px solid #ebeef5;
  434. border-radius: px2rpx(6);
  435. margin-bottom: px2rpx(15);
  436. background-color: #fff;
  437. /* overflow: hidden; 移除此属性,防止下拉框被遮挡截断 */
  438. }
  439. .group-header {
  440. display: flex;
  441. justify-content: space-between;
  442. align-items: center;
  443. padding: px2rpx(10) px2rpx(15);
  444. background-color: #f5f7fa;
  445. border-bottom: 1px solid #ebeef5;
  446. border-top-left-radius: px2rpx(6);
  447. border-top-right-radius: px2rpx(6);
  448. }
  449. .group-title {
  450. font-size: px2rpx(14);
  451. font-weight: bold;
  452. color: #303133;
  453. }
  454. .group-body {
  455. padding: px2rpx(15);
  456. }
  457. .item-row {
  458. margin-bottom: px2rpx(15);
  459. padding-bottom: px2rpx(15);
  460. border-bottom: 1px dashed #ebeef5;
  461. &:last-child {
  462. margin-bottom: 0;
  463. padding-bottom: 0;
  464. border-bottom: none;
  465. }
  466. }
  467. .item-title {
  468. margin-bottom: px2rpx(10);
  469. display: flex;
  470. align-items: center;
  471. .type-badge {
  472. background-color: #e1f3d8;
  473. color: #67c23a;
  474. padding: px2rpx(2) px2rpx(8);
  475. border-radius: px2rpx(4);
  476. font-size: px2rpx(12);
  477. margin-right: px2rpx(8);
  478. }
  479. .type-text {
  480. font-size: px2rpx(13);
  481. color: #606266;
  482. }
  483. }
  484. .item-fields {
  485. display: flex;
  486. flex-wrap: wrap;
  487. gap: px2rpx(10);
  488. justify-content: flex-start;
  489. }
  490. .field-col {
  491. flex: 0 0 calc(20% - px2rpx(10));
  492. min-width: px2rpx(80);
  493. max-width: px2rpx(120);
  494. display: flex;
  495. flex-direction: column;
  496. .field-label {
  497. font-size: px2rpx(12);
  498. color: #909399;
  499. margin-bottom: px2rpx(5);
  500. }
  501. }
  502. .dialog-account-adjust-body {
  503. padding: 20rpx;
  504. }
  505. .account-adjust-cid-row {
  506. display: flex;
  507. align-items: center;
  508. margin-bottom: 20rpx;
  509. }
  510. .account-adjust-cid-label {
  511. color: #606266;
  512. margin-right: px2rpx(5);
  513. }
  514. .account-adjust-cid-value {
  515. font-weight: bold;
  516. color: #303133;
  517. }
  518. .form-section {
  519. margin-bottom: 20rpx;
  520. }
  521. .section-title {
  522. display: flex;
  523. align-items: center;
  524. margin-bottom: px2rpx(15);
  525. font-weight: bold;
  526. font-size: px2rpx(14);
  527. }
  528. .section-title i {
  529. margin-right: 10rpx;
  530. }
  531. .account-type-grid {
  532. }
  533. .account-type-card {
  534. display: flex;
  535. flex-direction: column;
  536. margin-bottom: px2rpx(20);
  537. }
  538. .account-type-label {
  539. margin-bottom: 10rpx;
  540. font-size: 14rpx;
  541. }
  542. .account-select {
  543. width: 100%;
  544. }
  545. .dialog-account-adjust-footer {
  546. padding: 20rpx;
  547. }
  548. .account-adjust-notes-panel {
  549. margin-bottom: 20rpx;
  550. }
  551. .account-adjust-notes-section {
  552. background-color: #f5f7fa;
  553. padding: 15rpx;
  554. border-radius: 8rpx;
  555. }
  556. .account-adjust-notes-title {
  557. display: flex;
  558. align-items: center;
  559. margin-bottom: px2rpx(10);
  560. font-weight: bold;
  561. font-size: px2rpx(13);
  562. }
  563. .account-adjust-notes-title-icon {
  564. margin-right: px2rpx(10);
  565. }
  566. .account-adjust-notes-list {
  567. margin-left: px2rpx(20);
  568. color: #606266;
  569. font-size: px2rpx(13);
  570. }
  571. .account-adjust-notes-list .list {
  572. margin-bottom: px2rpx(5);
  573. margin-left: px2rpx(10);
  574. }
  575. .account-adjust-footer-buttons {
  576. display: flex;
  577. justify-content: flex-end;
  578. gap: 15rpx;
  579. }
  580. .account-adjust-footer-buttons button {
  581. min-width: 120rpx;
  582. }
  583. </style>