applyIbDialog.vue 20 KB

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