applyIbDialog.vue 19 KB

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