pointDialog.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363
  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 class="account-adjust-cid-row">
  5. <text class="account-adjust-cid-label">{{ t('Label.CidAccount') }}:</text>
  6. <text class="account-adjust-cid-value">{{ dialogForm.cId || '--' }}</text>
  7. </view>
  8. <uni-forms :model="dialogForm" ref="formRef" label-width="0" class="dialogCheck_form dialog-account-adjust-form">
  9. <view class="form-section form-section-commission">
  10. <view class="section-title">
  11. <cwg-icon name="crm-option" :size="22" color="#000"></cwg-icon>
  12. {{ t('Ib.Index.Spread5') }}
  13. </view>
  14. <view class="account-type-grid">
  15. <view class="account-type-card">
  16. <view class="account-type-label">
  17. {{ t('AccountType.StandardAccount') }}
  18. </view>
  19. <cwg-combox v-model:value="commissionAccountTypeSettings.standard.selectedIndex" :options="getAvailableSpreadsCommission('7').map((item, index) => ({
  20. text: getSpreadLabelCommission(item),
  21. value: index
  22. }))" :placeholder="t('placeholder.choose')" class="account-select"
  23. @change="(value) => handleCommissionAccountTypeChange('standard', '7', value)" />
  24. </view>
  25. <view class="account-type-card">
  26. <view class="account-type-label">
  27. {{ t('AccountType.SeniorAccount') }}
  28. </view>
  29. <cwg-combox v-model:value="commissionAccountTypeSettings.ecn.selectedIndex" :options="getAvailableSpreadsCommission('2').map((item, index) => ({
  30. text: getSpreadLabelCommission(item),
  31. value: index
  32. }))" :placeholder="t('placeholder.choose')" class="account-select"
  33. @change="(value) => handleCommissionAccountTypeChange('ecn', '2', value)" />
  34. </view>
  35. <view class="account-type-card">
  36. <view class="account-type-label">
  37. {{ t('AccountType.CentAccount') }}
  38. </view>
  39. <cwg-combox v-model:value="commissionAccountTypeSettings.cent.selectedIndex" :options="getAvailableSpreadsCommission('8').map((item, index) => ({
  40. text: getSpreadLabelCommission(item),
  41. value: index
  42. }))" :placeholder="t('placeholder.choose')" class="account-select"
  43. @change="(value) => handleCommissionAccountTypeChange('cent', '8', value)" />
  44. </view>
  45. </view>
  46. </view>
  47. </uni-forms>
  48. </view>
  49. <view class="dialog-footer dialog-account-adjust-footer">
  50. <view class="account-adjust-notes-panel">
  51. <view class="account-adjust-notes-section">
  52. <view class="account-adjust-notes-title">
  53. <cwg-icon name="gy" :size="20" class="account-adjust-notes-title-icon"></cwg-icon>
  54. <span class="account-adjust-notes-title-text">{{ t('Ib.Custom.AccountAdjustNotesSection2Title') }}</span>
  55. </view>
  56. <view class="account-adjust-notes-list">
  57. <view class="list">{{ t('Ib.Custom.AccountAdjustNotesSection2Item1') }}</view>
  58. <view class="list">{{ t('Ib.Custom.AccountAdjustNotesSection2Item2') }}</view>
  59. </view>
  60. </view>
  61. </view>
  62. </view>
  63. </cwg-popup>
  64. </template>
  65. <script setup lang="ts">
  66. import { ref, reactive, computed, onMounted, onUnmounted, watch } from 'vue'
  67. import { onLoad } from '@dcloudio/uni-app'
  68. import { useI18n } from 'vue-i18n' // uni-app 中已集成,但需配置
  69. import { customApi } from '@/service/custom'
  70. import { financialApi } from '@/service/financial'
  71. import Config from '@/config/index'
  72. import PaymentMethodsList from './components/PaymentMethodsList.vue'
  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. // 是否显示弹窗
  78. visible: {
  79. type: Boolean,
  80. default: false,
  81. },
  82. // 详情formData
  83. detail: { type: Object, default: () => ({}) },
  84. })
  85. const { Code, Host80 } = Config
  86. const { t } = useI18n()
  87. const formRef = ref(null)
  88. const dialogForm = ref({
  89. cId: '',
  90. })
  91. const commissionAccountTypeSettings = ref({
  92. ecn: { selectedIndex: null, selectedItem: null, loginType: '2' },
  93. standard: { selectedIndex: null, selectedItem: null, loginType: '7' },
  94. cent: { selectedIndex: null, selectedItem: null, loginType: '8' },
  95. })
  96. const commissionAccountTypeData = ref({
  97. ecn: [],
  98. standard: [],
  99. cent: [],
  100. })
  101. const emit = defineEmits(['close', 'confirm'])
  102. onMounted(() => {
  103. console.log(props.visible)
  104. })
  105. // 佣金调整弹框:拉取点差/价格数据(与 ConsumerShareLink getCustomLinkTypes 一致)
  106. const loadCommissionAccountTypes = async (ibId) => {
  107. const params = ibId ? { ibId } : {}
  108. let res = await ibApi.customLinkTypes(params)
  109. if (res.code == Code.StatusOK) {
  110. const data = res.data || []
  111. commissionAccountTypeData.value = {
  112. ecn: data.filter(
  113. (item) => item.loginType === 2 || item.loginType === '2',
  114. ),
  115. standard: data.filter(
  116. (item) => item.loginType === 7 || item.loginType === '7',
  117. ),
  118. cent: data.filter(
  119. (item) => item.loginType === 8 || item.loginType === '8',
  120. ),
  121. }
  122. } else {
  123. uni.showToast({
  124. title: res.msg,
  125. icon: 'none',
  126. })
  127. commissionAccountTypeData.value = { ecn: [], standard: [], cent: [] }
  128. }
  129. }
  130. const getAvailableSpreadsCommission = (loginType) => {
  131. if (loginType === '2') return commissionAccountTypeData.value.ecn || []
  132. if (loginType === '7')
  133. return commissionAccountTypeData.value.standard || []
  134. if (loginType === '8') return commissionAccountTypeData.value.cent || []
  135. return []
  136. }
  137. // 佣金调整弹框:根据佣金查看(getLoginPoint)的当前值设置账户类型下拉默认选中
  138. const setCommissionDefaultsFromLoginPoint = async (customerId) => {
  139. if (!customerId) return
  140. try {
  141. const res = await ibApi.getLoginPoint({ id: customerId })
  142. if (res.code !== Code.StatusOK || !Array.isArray(res.data)) return
  143. const list = res.data || []
  144. const norm = (v) =>
  145. v === 2 || v === '2'
  146. ? '2'
  147. : v === 7 || v === '7'
  148. ? '7'
  149. : v === 8 || v === '8'
  150. ? '8'
  151. : null
  152. const byType = { 2: [], 7: [], 8: [] }
  153. list.forEach((d) => {
  154. const t = norm(d.loginType)
  155. if (t && d.groupName) byType[t].push(d.groupName)
  156. });
  157. ['2', '7', '8'].forEach((loginType) => {
  158. const key =
  159. loginType === '2' ? 'ecn' : loginType === '7' ? 'standard' : 'cent'
  160. const currentGroupName = byType[loginType][0]
  161. const options = getAvailableSpreadsCommission(loginType)
  162. const idx =
  163. currentGroupName == null
  164. ? -1
  165. : options.findIndex(
  166. (item) => (item.groupName || '') === currentGroupName,
  167. )
  168. const setting = commissionAccountTypeSettings.value[key]
  169. if (idx >= 0) {
  170. setting.selectedIndex = idx
  171. setting.selectedItem = options[idx]
  172. } else {
  173. setting.selectedIndex = null
  174. setting.selectedItem = null
  175. }
  176. })
  177. } catch (e) {
  178. console.error('设置佣金调整默认值失败:', e)
  179. }
  180. }
  181. watch(() => props.detail, (val) => {
  182. if (val.cId) {
  183. const { cId, id, comPoint1, hide1 } = val
  184. dialogForm.value = {
  185. cId, id, comPoint1, hide1,
  186. }
  187. loadCommissionAccountTypes(val.ibId).then(
  188. () => {
  189. return setCommissionDefaultsFromLoginPoint(val.id)
  190. },
  191. )
  192. }
  193. })
  194. const getSpreadLabelCommission = (item) => {
  195. return item.groupName || ''
  196. }
  197. const handleCommissionAccountTypeChange = (type, loginType) => {
  198. const setting = commissionAccountTypeSettings.value[type]
  199. const availableSpreads = getAvailableSpreadsCommission(loginType)
  200. if (
  201. setting.selectedIndex !== null &&
  202. setting.selectedIndex !== undefined
  203. ) {
  204. setting.selectedItem = availableSpreads[setting.selectedIndex] || null
  205. } else {
  206. setting.selectedItem = null
  207. }
  208. }
  209. const toVerified = () => {
  210. // 确认按钮点击事件
  211. emit('confirm')
  212. }
  213. const closeDia = () => {
  214. dialogForm.value = {
  215. cId: '',
  216. }
  217. commissionAccountTypeSettings.value = {
  218. ecn: { selectedIndex: null, selectedItem: null, loginType: '2' },
  219. standard: { selectedIndex: null, selectedItem: null, loginType: '7' },
  220. cent: { selectedIndex: null, selectedItem: null, loginType: '8' },
  221. }
  222. emit('close')
  223. }
  224. const confirmDia = async () => {
  225. // 确认按钮点击事件
  226. const loginConfig = []
  227. Object.keys(commissionAccountTypeSettings.value).forEach((key) => {
  228. const setting = commissionAccountTypeSettings.value[key]
  229. if (setting.selectedItem) {
  230. loginConfig.push(setting.selectedItem)
  231. }
  232. })
  233. let res = await ibApi.customCommissionPoint({
  234. id: dialogForm.value.id,
  235. loginConfig,
  236. })
  237. if (res.code == Code.StatusOK) {
  238. uni.showToast({
  239. title: t('Msg.ModifySuccess'),
  240. })
  241. closeDia()
  242. } else {
  243. uni.showToast({
  244. title: res.msg,
  245. icon: 'none',
  246. })
  247. }
  248. emit('confirm')
  249. }
  250. </script>
  251. <style lang="scss" scoped>
  252. @import "@/uni.scss";
  253. .dialog-account-adjust-body {
  254. padding: 20rpx;
  255. }
  256. .account-adjust-cid-row {
  257. display: flex;
  258. align-items: center;
  259. margin-bottom: 20rpx;
  260. font-size: px2rpx(20);
  261. }
  262. .account-adjust-cid-label {
  263. color: #606266;
  264. margin-right: px2rpx(5);
  265. }
  266. .account-adjust-cid-value {
  267. font-weight: bold;
  268. color: #303133;
  269. }
  270. .form-section {
  271. margin-bottom: 20rpx;
  272. }
  273. .section-title {
  274. display: flex;
  275. align-items: center;
  276. margin-bottom: px2rpx(15);
  277. font-weight: bold;
  278. font-size: px2rpx(18);
  279. }
  280. .section-title i {
  281. margin-right: 10rpx;
  282. }
  283. .account-type-grid {}
  284. .account-type-card {
  285. display: flex;
  286. flex-direction: column;
  287. margin-bottom: px2rpx(20);
  288. }
  289. .account-type-label {
  290. margin-bottom: 10rpx;
  291. font-size: 14rpx;
  292. }
  293. .account-select {
  294. width: 100%;
  295. }
  296. .dialog-account-adjust-footer {
  297. padding: 20rpx;
  298. }
  299. .account-adjust-notes-panel {
  300. margin-bottom: 20rpx;
  301. }
  302. .account-adjust-notes-section {
  303. background-color: rgba(var(--bs-body-bg-rgb), var(--bs-bg-opacity)) !important;
  304. padding: 15rpx;
  305. border-radius: 8rpx;
  306. }
  307. .account-adjust-notes-title {
  308. display: flex;
  309. align-items: center;
  310. margin-bottom: px2rpx(10);
  311. font-weight: bold;
  312. font-size: px2rpx(13);
  313. }
  314. .account-adjust-notes-title-icon {
  315. margin-right: px2rpx(10);
  316. }
  317. .account-adjust-notes-list {
  318. margin-left: px2rpx(20);
  319. color: #606266;
  320. font-size: px2rpx(13);
  321. }
  322. .account-adjust-notes-list .list {
  323. margin-bottom: px2rpx(5);
  324. margin-left: px2rpx(10);
  325. }
  326. .account-adjust-footer-buttons {
  327. display: flex;
  328. justify-content: flex-end;
  329. gap: 15rpx;
  330. }
  331. .account-adjust-footer-buttons button {
  332. min-width: 120rpx;
  333. }
  334. </style>