applyIbDialog.vue 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304
  1. <template>
  2. <cwg-popup :title="t('Ib.Custom.AccountAdjust')" :visible="visible" @close="closeDia" @confirm="confirmDia">
  3. <view class="dia-content dialog-account-adjust-body">
  4. </view>
  5. </cwg-popup>
  6. </template>
  7. <script setup lang="ts">
  8. import { ref, reactive, computed, onMounted, onUnmounted, watch } from 'vue'
  9. import { onLoad } from '@dcloudio/uni-app'
  10. import { useI18n } from 'vue-i18n' // uni-app 中已集成,但需配置
  11. import { customApi } from '@/service/custom'
  12. import { financialApi } from '@/service/financial'
  13. import Config from '@/config/index'
  14. import { ibApi } from '@/service/ib'
  15. import useUserStore from '@/stores/use-user-store'
  16. import { lang } from '@/composables/config'
  17. const props = defineProps({
  18. // 是否显示弹窗
  19. visible: {
  20. type: Boolean,
  21. default: false,
  22. },
  23. // 详情tableData
  24. tableData: { type: Array, default: () => ([]) },
  25. })
  26. const { Code, Host80 } = Config
  27. const { t } = useI18n()
  28. const formRef = ref(null)
  29. const dialogForm = ref({
  30. cId: '123',
  31. })
  32. const commissionAccountTypeSettings = ref({
  33. ecn: { selectedIndex: null, selectedItem: null, loginType: '2' },
  34. standard: { selectedIndex: null, selectedItem: null, loginType: '7' },
  35. cent: { selectedIndex: null, selectedItem: null, loginType: '8' },
  36. })
  37. const commissionAccountTypeData = ref({
  38. ecn: [],
  39. standard: [],
  40. cent: [],
  41. })
  42. const emit = defineEmits(['close', 'confirm'])
  43. onMounted(() => {
  44. console.log(props.visible)
  45. })
  46. // 佣金调整弹框:拉取点差/价格数据(与 ConsumerShareLink getCustomLinkTypes 一致)
  47. const loadCommissionAccountTypes = async (ibId) => {
  48. const params = ibId ? { ibId } : {}
  49. let res = await ibApi.customLinkTypes(params)
  50. if (res.code == Code.StatusOK) {
  51. const data = res.data || []
  52. commissionAccountTypeData.value = {
  53. ecn: data.filter(
  54. (item) => item.loginType === 2 || item.loginType === '2',
  55. ),
  56. standard: data.filter(
  57. (item) => item.loginType === 7 || item.loginType === '7',
  58. ),
  59. cent: data.filter(
  60. (item) => item.loginType === 8 || item.loginType === '8',
  61. ),
  62. }
  63. } else {
  64. uni.showToast({
  65. title: res.msg,
  66. icon: 'none',
  67. })
  68. commissionAccountTypeData.value = { ecn: [], standard: [], cent: [] }
  69. }
  70. }
  71. const getAvailableSpreadsCommission = (loginType) => {
  72. if (loginType === '2') return commissionAccountTypeData.value.ecn || []
  73. if (loginType === '7')
  74. return commissionAccountTypeData.value.standard || []
  75. if (loginType === '8') return commissionAccountTypeData.value.cent || []
  76. return []
  77. }
  78. // 佣金调整弹框:根据佣金查看(getLoginPoint)的当前值设置账户类型下拉默认选中
  79. const setCommissionDefaultsFromLoginPoint = async (customerId) => {
  80. if (!customerId) return
  81. try {
  82. const res = await ibApi.getLoginPoint({ id: customerId })
  83. if (res.code !== Code.StatusOK || !Array.isArray(res.data)) return
  84. const list = res.data || []
  85. const norm = (v) =>
  86. v === 2 || v === '2'
  87. ? '2'
  88. : v === 7 || v === '7'
  89. ? '7'
  90. : v === 8 || v === '8'
  91. ? '8'
  92. : null
  93. const byType = { 2: [], 7: [], 8: [] }
  94. list.forEach((d) => {
  95. const t = norm(d.loginType)
  96. if (t && d.groupName) byType[t].push(d.groupName)
  97. });
  98. ['2', '7', '8'].forEach((loginType) => {
  99. const key =
  100. loginType === '2' ? 'ecn' : loginType === '7' ? 'standard' : 'cent'
  101. const currentGroupName = byType[loginType][0]
  102. const options = getAvailableSpreadsCommission(loginType)
  103. const idx =
  104. currentGroupName == null
  105. ? -1
  106. : options.findIndex(
  107. (item) => (item.groupName || '') === currentGroupName,
  108. )
  109. const setting = commissionAccountTypeSettings.value[key]
  110. if (idx >= 0) {
  111. setting.selectedIndex = idx
  112. setting.selectedItem = options[idx]
  113. } else {
  114. setting.selectedIndex = null
  115. setting.selectedItem = null
  116. }
  117. })
  118. } catch (e) {
  119. console.error('设置佣金调整默认值失败:', e)
  120. }
  121. }
  122. watch(() => props.detail, (val) => {
  123. if (val) {
  124. const { cId, id, comPoint1, hide1 } = val
  125. dialogForm.value = {
  126. cId, id, comPoint1, hide1,
  127. }
  128. if (val.ibId) {
  129. loadCommissionAccountTypes(val.ibId).then(
  130. () => {
  131. return setCommissionDefaultsFromLoginPoint(val.id)
  132. },
  133. )
  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 toVerified = () => {
  153. // 确认按钮点击事件
  154. emit('confirm')
  155. }
  156. const cancel = () => {
  157. // 取消按钮点击事件
  158. emit('close')
  159. }
  160. const closeDia = () => {
  161. emit('close')
  162. }
  163. const confirmDia = async () => {
  164. // 确认按钮点击事件
  165. const loginConfig = []
  166. Object.keys(commissionAccountTypeSettings.value).forEach((key) => {
  167. const setting = commissionAccountTypeSettings.value[key]
  168. if (setting.selectedItem) {
  169. loginConfig.push(setting.selectedItem)
  170. }
  171. })
  172. let res = await ibApi.customCommissionPoint({
  173. id: dialogForm.value.id,
  174. loginConfig,
  175. })
  176. if (res.code == Code.StatusOK) {
  177. uni.showToast({
  178. title: t('Msg.ModifySuccess'),
  179. })
  180. this.cancel()
  181. } else {
  182. uni.showToast({
  183. title: res.msg,
  184. icon: 'none',
  185. })
  186. }
  187. emit('confirm')
  188. }
  189. </script>
  190. <style lang="scss" scoped>
  191. @import "@/uni.scss";
  192. .dialog-account-adjust-body {
  193. padding: 20rpx;
  194. }
  195. .account-adjust-cid-row {
  196. display: flex;
  197. align-items: center;
  198. margin-bottom: 20rpx;
  199. }
  200. .account-adjust-cid-label {
  201. color: #606266;
  202. margin-right: px2rpx(5);
  203. }
  204. .account-adjust-cid-value {
  205. font-weight: bold;
  206. color: #303133;
  207. }
  208. .form-section {
  209. margin-bottom: 20rpx;
  210. }
  211. .section-title {
  212. display: flex;
  213. align-items: center;
  214. margin-bottom: px2rpx(15);
  215. font-weight: bold;
  216. font-size: px2rpx(14);
  217. }
  218. .section-title i {
  219. margin-right: 10rpx;
  220. }
  221. .account-type-grid {
  222. }
  223. .account-type-card {
  224. display: flex;
  225. flex-direction: column;
  226. margin-bottom: px2rpx(20);
  227. }
  228. .account-type-label {
  229. margin-bottom: 10rpx;
  230. font-size: 14rpx;
  231. }
  232. .account-select {
  233. width: 100%;
  234. }
  235. .dialog-account-adjust-footer {
  236. padding: 20rpx;
  237. }
  238. .account-adjust-notes-panel {
  239. margin-bottom: 20rpx;
  240. }
  241. .account-adjust-notes-section {
  242. background-color: #f5f7fa;
  243. padding: 15rpx;
  244. border-radius: 8rpx;
  245. }
  246. .account-adjust-notes-title {
  247. display: flex;
  248. align-items: center;
  249. margin-bottom: px2rpx(10);
  250. font-weight: bold;
  251. font-size: px2rpx(13);
  252. }
  253. .account-adjust-notes-title-icon {
  254. margin-right: px2rpx(10);
  255. }
  256. .account-adjust-notes-list {
  257. margin-left: px2rpx(20);
  258. color: #606266;
  259. font-size: px2rpx(13);
  260. }
  261. .account-adjust-notes-list .list {
  262. margin-bottom: px2rpx(5);
  263. margin-left: px2rpx(10);
  264. }
  265. .account-adjust-footer-buttons {
  266. display: flex;
  267. justify-content: flex-end;
  268. gap: 15rpx;
  269. }
  270. .account-adjust-footer-buttons button {
  271. min-width: 120rpx;
  272. }
  273. </style>