Преглед на файлове

feat:ib-申请代理,combox加入selected插槽

ljc преди 2 месеца
родител
ревизия
ae61d2aa22
променени са 3 файла, в които са добавени 189 реда и са изтрити 71 реда
  1. 6 2
      components/cwg-combox.vue
  2. 180 67
      pages/ib/components/applyIbDialog.vue
  3. 3 2
      pages/ib/customer.vue

+ 6 - 2
components/cwg-combox.vue

@@ -12,7 +12,11 @@
 
             <!-- 普通下拉模式 -->
             <uni-data-select v-else v-model="innerValue" :localdata="options" :clear="clearable"
-                :placeholder="placeholder" :multiple="multiple" :disabled="disabled" @change="handleSelectChange" />
+                :placeholder="placeholder" :multiple="multiple" :disabled="disabled" @change="handleSelectChange">
+                <template #selected v-if="$slots.selected">
+                    <slot name="selected"></slot>
+                </template>
+            </uni-data-select>
         </template>
 
     </view>
@@ -109,7 +113,7 @@ watch(
  * 普通 select 改变
  */
 const handleSelectChange = (val) => {
-    console.log(val, props.options, 1111)
+    // console.log(val, props.options, 1111)
     innerValue.value = val
     updateTextByValue(val)
     emit('update:value', val)

+ 180 - 67
pages/ib/components/applyIbDialog.vue

@@ -4,7 +4,7 @@
       <uni-forms ref="formRef" labelWidth="200">
         <uni-forms-item v-if="isFormApplyIb" :label="t('Ib.Custom.Manage3')+':'" prop="customerId">
           <cwg-combox v-model:value="addAgentForm.customerId" :options="customerList"
-                      :placeholder="t('placeholder.choose')" filterable/>
+                      :placeholder="t('placeholder.choose')" filterable @change="changeCustomer" />
         </uni-forms-item>
         <view class="commission-groups">
           <view v-for="(group, gIndex) in commissionTemplateTableData" :key="gIndex" class="group-card">
@@ -14,7 +14,8 @@
                 <text class="title-text">{{ group.accountGroup }}</text>
               </view>
               <view class="group-switch" @click.stop>
-                <switch :checked="group.isOpen" @change="(e) => onGroupSwitchChange(e, group)" color="#2b5aed" style="transform:scale(0.8)"/>
+                <switch :checked="group.isOpen" @change="(e) => onGroupSwitchChange(e, group)" color="#2b5aed"
+                        style="transform:scale(0.8)" />
               </view>
             </view>
 
@@ -22,58 +23,58 @@
             <view v-show="group.isOpen" class="group-body">
               <view v-for="(item, iIndex) in group.items" :key="iIndex" class="item-row">
                 <view class="item-title">
-                  <text class="type-badge">{{ item.dataType === 'rebates' ? 'Rebates' : 'Commissions' }}</text>
+                  <!--                  <text class="type-badge">{{ item.dataType === 'rebates' ? 'Rebates' : 'Commissions' }}</text>-->
                   <text class="type-text">{{ item.type }}</text>
                 </view>
-                
+
                 <view class="item-fields">
                   <!-- METAL -->
                   <view class="field-col">
                     <text class="field-label">METAL</text>
-                    <cwg-combox 
-                      v-model:value="item.energy" 
-                      :options="formatOptions(item.energyOptions)" 
-                      :placeholder="t('placeholder.choose')" 
+                    <cwg-combox
+                      v-model:value="item.energy"
+                      :options="formatOptions(item.energyOptions)"
+                      :placeholder="t('placeholder.choose')"
                     />
                   </view>
-                  
+
                   <!-- FX -->
                   <view class="field-col">
                     <text class="field-label">FX</text>
-                    <cwg-combox 
-                      v-model:value="item.forex" 
-                      :options="formatOptions(item.forexOptions)" 
-                      :placeholder="t('placeholder.choose')" 
+                    <cwg-combox
+                      v-model:value="item.forex"
+                      :options="formatOptions(item.forexOptions)"
+                      :placeholder="t('placeholder.choose')"
                     />
                   </view>
-                  
+
                   <!-- ENERGY -->
                   <view class="field-col">
                     <text class="field-label">ENERGY</text>
-                    <cwg-combox 
-                      v-model:value="item.energy2" 
-                      :options="formatOptions(item.energy2Options)" 
-                      :placeholder="t('placeholder.choose')" 
+                    <cwg-combox
+                      v-model:value="item.energy2"
+                      :options="formatOptions(item.energy2Options)"
+                      :placeholder="t('placeholder.choose')"
                     />
                   </view>
-                  
+
                   <!-- CFD -->
                   <view class="field-col">
                     <text class="field-label">CFD</text>
-                    <cwg-combox 
-                      v-model:value="item.index" 
-                      :options="formatOptions(item.indexOptions)" 
-                      :placeholder="t('placeholder.choose')" 
+                    <cwg-combox
+                      v-model:value="item.index"
+                      :options="formatOptions(item.indexOptions)"
+                      :placeholder="t('placeholder.choose')"
                     />
                   </view>
-                  
+
                   <!-- INDEX -->
                   <view class="field-col">
                     <text class="field-label">INDEX</text>
-                    <cwg-combox 
-                      v-model:value="item.metal" 
-                      :options="formatOptions(item.metalOptions)" 
-                      :placeholder="t('placeholder.choose')" 
+                    <cwg-combox
+                      v-model:value="item.metal"
+                      :options="formatOptions(item.metalOptions)"
+                      :placeholder="t('placeholder.choose')"
                     />
                   </view>
                 </view>
@@ -104,7 +105,7 @@
       default: false,
     },
     // 详情tableData
-    detail: { type: Array, default: () => ([]) },
+    detail: { type: Array, default: () => ({}) },
     isFormApplyIb: {
       type: Boolean,
       default: true,
@@ -134,16 +135,14 @@
     initCommissionTemplateData(29634)
   })
 
-  watch(() => props.detail, (val) => {
+  watch(() => props.visible, (val) => {
     if (val) {
-      const { cId, id, comPoint1, hide1 } = val
-      dialogForm.value = {
-        cId, id, comPoint1, hide1,
+      loadCustomerList()
+
+      // initCommissionTemplateData(29634)
+      if (props.detail.id) {
+        initCommissionTemplateData(val.id)
       }
-      initCommissionTemplateData(29634)
-      // if (val.id) {
-      //   initCommissionTemplateData(val.id)
-      // }
     }
   })
 
@@ -165,11 +164,11 @@
   }
 
   const generateOptions = (currentValue) => {
-    const options = [];
+    const options = []
     for (let i = 0; i <= currentValue; i++) {
-      options.push(i);
+      options.push(i)
     }
-    return options;
+    return options
   }
 
   // 格式化 options 为 combox 期望的格式
@@ -196,7 +195,7 @@
         res.data.forEach((group: any) => {
           const accountGroup = group.groupCategoryName || '--'
           const valid = group.valid !== undefined ? group.valid : 1
-          
+
           if (!groupedData[accountGroup]) {
             groupedData[accountGroup] = []
           }
@@ -303,7 +302,7 @@
           }
         })
 
-        console.log('tableData',finalData)
+        console.log('tableData', finalData)
         commissionTemplateTableData.value = finalData
         return
       }
@@ -319,45 +318,159 @@
     }
   }
 
+
+  // 加载客户列表
+  const loadCustomerList = async () => {
+    try {
+      let res = await ibApi.customerSubsList({
+        ibStatus: 1,
+      })
+      if (res.code == Code.StatusOK) {
+        customerList.value = res.data.map(item => ({
+          label: `${item.name || ''}-${item.cId}`,
+          value: item.id || '',
+          cId: item.cId // 保存 cId 供后续提交使用
+        })) || []
+      } else {
+        uni.showToast({ title: res.msg, icon: 'none' })
+        customerList.value = []
+      }
+    } catch (error) {
+      console.error('加载客户列表失败:', error)
+      customerList.value = []
+    } finally {
+    }
+  }
+
+  // 客户选择改变时触发
+  const changeCustomer = (val) => {
+    if (val) {
+      initCommissionTemplateData(val)
+    }else {
+      commissionTemplateTableData.value = []
+    }
+  }
+
+  // 构建佣金模板points数据
+  const buildCommissionTemplatePoints = () => {
+    const points: any[] = []
+    const groupedData: Record<string, any> = {}
+
+    // 由于现在的 commissionTemplateTableData 是 { accountGroup, isOpen, items } 嵌套结构,需要双层遍历提取
+    commissionTemplateTableData.value.forEach((groupObj) => {
+      groupObj.items.forEach((row: any) => {
+        const groupId = row.groupCategoryId
+        if (!groupedData[groupId]) {
+          groupedData[groupId] = {
+            groupCategoryId: groupId,
+            commissions: [],
+            rebates: [],
+            valid: groupObj.isOpen  ? 1 : 0,
+          }
+        }
+
+        // 根据dataType添加到对应的数组
+        const pointList = row.dataType === 'commissions'
+          ? groupedData[groupId].commissions
+          : groupedData[groupId].rebates
+
+        // 添加各个symbolCategory的数据
+        if (row.forex !== undefined && row.forex !== null) {
+          pointList.push({ symbolCategory: 1, point: row.forex }) // FX
+        }
+        if (row.index !== undefined && row.index !== null) {
+          pointList.push({ symbolCategory: 2, point: row.index }) // CFD
+        }
+        if (row.metal !== undefined && row.metal !== null) {
+          pointList.push({ symbolCategory: 3, point: row.metal }) // INDEX
+        }
+        if (row.energy !== undefined && row.energy !== null) {
+          pointList.push({ symbolCategory: 4, point: row.energy }) // METAL
+        }
+        if (row.energy2 !== undefined && row.energy2 !== null) {
+          pointList.push({ symbolCategory: 5, point: row.energy2 }) // Energy
+        }
+      })
+    })
+
+    // 转换为数组格式
+    Object.keys(groupedData).forEach((groupId) => {
+      const group = groupedData[groupId]
+      if (group.commissions.length > 0 || group.rebates.length > 0) {
+        points.push({
+          groupCategoryId: group.groupCategoryId,
+          commissions: group.commissions.length > 0 ? group.commissions : undefined,
+          rebates: group.rebates.length > 0 ? group.rebates : undefined,
+          valid: group.valid,
+        })
+      }
+    })
+
+    return points
+  }
+
   const toVerified = () => {
     // 确认按钮点击事件
     emit('confirm')
   }
 
-  const cancel = () => {
-    // 取消按钮点击事件
-    emit('close')
-  }
-
   const closeDia = () => {
+    commissionTemplateTableData.value = []
     emit('close')
   }
 
   const confirmDia = async () => {
-    // 确认按钮点击事件
-    const loginConfig = []
-    Object.keys(commissionAccountTypeSettings.value).forEach((key) => {
-      const setting = commissionAccountTypeSettings.value[key]
-      if (setting.selectedItem) {
-        loginConfig.push(setting.selectedItem)
+    let customId, cId
+
+    if (!props.isFormApplyIb) {
+      if (!props.detail.id) {
+        uni.showToast({ title: t('Ib.Custom.CustomerNotExist'), icon: 'none' })
+        return
       }
-    })
-    let res = await ibApi.customCommissionPoint({
-      id: dialogForm.value.id,
-      loginConfig,
-    })
-    if (res.code == Code.StatusOK) {
-      uni.showToast({
-        title: t('Msg.ModifySuccess'),
-      })
-      cancel()
+      const applyIbRowData: any = props.detail || {}
+      customId = applyIbRowData.id
+      cId = applyIbRowData.cId
     } else {
-      uni.showToast({
-        title: res.msg,
-        icon: 'none',
+      // 从其他地方打开,需要选择客户
+      if (!addAgentForm.value.customerId) {
+        uni.showToast({ title: t('placeholder.choose'), icon: 'none' })
+        return
+      }
+
+      // 从客户列表中找到选中的客户对象
+      const selectedCustomer: any = customerList.value.find(
+        (item: any) => item.value === addAgentForm.value.customerId
+      )
+      if (!selectedCustomer) {
+        uni.showToast({ title: t('Ib.Custom.CustomerNotFound'), icon: 'none' })
+        return
+      }
+      customId = selectedCustomer.value
+      cId = selectedCustomer.cId
+    }
+
+    try {
+      // 构建points数据
+      const points = buildCommissionTemplatePoints()
+      console.log(points)
+      // 调用新增代理申请接口
+      const res = await ibApi.agentApplyAddPoint({
+        customId: customId,
+        cId: cId,
+        points: points,
       })
+
+      if (res.code == Code.StatusOK) {
+        uni.showToast({ title: res.msg || t('Ib.Custom.SubmitSuccess'), icon: 'success' })
+        closeDia()
+        emit('confirm') // 刷新列表
+      } else {
+        uni.showToast({ title: res.msg || t('Ib.Custom.SubmitFailed'), icon: 'none' })
+      }
+    } catch (error) {
+      console.error('新增代理失败:', error)
+      uni.showToast({ title: t('Ib.Custom.SubmitFailed'), icon: 'none' })
     }
-    emit('confirm')
   }
 </script>
 <style lang="scss" scoped>

+ 3 - 2
pages/ib/customer.vue

@@ -67,7 +67,7 @@
       <DocumentaryDialog :visible="docVisible" :detail="formInfoRow" @close="closeDoc" @confirm="confirmDoc" />
       <!-- 开户调整     -->
       <PointDialog :visible="pointVisible" :detail="pointForm" @close="closePoint" @confirm="confirmPoint" />
-      <ApplyIbDialog :visible="applyVisible" :tableData="pointForm" @close="closePoint" @confirm="confirmPoint" />
+      <ApplyIbDialog :visible="applyVisible" :tableData="applyForm" @close="closeApply" @confirm="confirmApply" />
     </view>
   </cwg-page-wrapper>
 </template>
@@ -102,6 +102,7 @@
 
   const formInfoRow = ref({})
   const pointForm = ref({})
+  const applyForm = ref({})
   const applyTable = ref([])
   const docVisible = ref(false)
   const pointVisible = ref(false)
@@ -226,7 +227,7 @@
       }
       docVisible.value = true
     } else if (item.type == 'applyIb') {
-
+      applyForm.value = row
       applyVisible.value = true
     } else if (item.type == 'Point') {
       const { cId, id, comPoint1, hide1 } = item.row