applyIbDialog.vue 21 KB

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