applyIbDialog.vue 20 KB

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