Просмотр исходного кода

feat:ib-代理管理,佣金分配,加点分配弹窗

ljc 2 месяцев назад
Родитель
Сommit
f3a25e631b
2 измененных файлов с 164 добавлено и 50 удалено
  1. 72 41
      pages/ib/components/applyIbDialog.vue
  2. 92 9
      pages/ib/subsList.vue

+ 72 - 41
pages/ib/components/applyIbDialog.vue

@@ -1,5 +1,5 @@
 <template>
-  <cwg-popup :title="t('Ib.Report.Title5')" :visible="visible" @close="closeDia" @confirm="confirmDia">
+  <cwg-popup :title="t(title)" :visible="visible" @close="closeDia" @confirm="confirmDia">
     <view class="dia-content">
       <uni-forms ref="formRef" labelWidth="200">
         <uni-forms-item v-if="isFormApplyIb" :label="t('Ib.Custom.Manage3')+':'" prop="customerId">
@@ -99,6 +99,14 @@
   import { lang } from '@/composables/config'
 
   const props = defineProps({
+    paramsType: {
+      type: String,
+      default: 'vietnam'
+    },
+    title: {
+      type: String,
+      default: 'Ib.Report.Title5',
+    },
     // 是否显示弹窗
     visible: {
       type: Boolean,
@@ -106,9 +114,10 @@
     },
     // 详情tableData
     detail: { type: Array, default: () => ({}) },
+    // 是否需要选择客户
     isFormApplyIb: {
       type: Boolean,
-      default: true,
+      default: false,
     },
   })
   const { Code, Host80 } = Config
@@ -132,7 +141,7 @@
   const emit = defineEmits(['close', 'confirm'])
 
   onMounted(() => {
-    initCommissionTemplateData(29634)
+    // initCommissionTemplateData(29634)
   })
 
   watch(() => props.visible, (val) => {
@@ -141,7 +150,15 @@
 
       // initCommissionTemplateData(29634)
       if (props.detail.id) {
-        initCommissionTemplateData(val.id)
+        let params = {
+          customerId: props.detail.id,
+        }
+        if (props.paramsType == 'vietnam') {
+          params = {
+            agentId: 91886//props.params.id,
+          }
+        }
+        initCommissionTemplateData(params)
       }
     }
   })
@@ -185,9 +202,9 @@
     group.isOpen = e.detail.value
   }
 
-  const initCommissionTemplateData = async (customId: string | number) => {
+  const initCommissionTemplateData = async (params) => {
     try {
-      const res = await ibApi.getVietnamPoints({ customId })
+      const res = await ibApi.getVietnamPoints(params)
 
       if (res.code == Code.StatusOK && res.data && Array.isArray(res.data)) {
         const groupedData: Record<string, any[]> = {}
@@ -329,7 +346,7 @@
         customerList.value = res.data.map(item => ({
           label: `${item.name || ''}-${item.cId}`,
           value: item.id || '',
-          cId: item.cId // 保存 cId 供后续提交使用
+          cId: item.cId, // 保存 cId 供后续提交使用
         })) || []
       } else {
         uni.showToast({ title: res.msg, icon: 'none' })
@@ -345,8 +362,8 @@
   // 客户选择改变时触发
   const changeCustomer = (val) => {
     if (val) {
-      initCommissionTemplateData(val)
-    }else {
+      initCommissionTemplateData({ customId: val })
+    } else {
       commissionTemplateTableData.value = []
     }
   }
@@ -365,7 +382,7 @@
             groupCategoryId: groupId,
             commissions: [],
             rebates: [],
-            valid: groupObj.isOpen  ? 1 : 0,
+            valid: groupObj.isOpen ? 1 : 0,
           }
         }
 
@@ -420,56 +437,70 @@
   }
 
   const confirmDia = async () => {
+    //  越南分配也用,看怎么调整提交接口
     let customId, cId
 
-    if (!props.isFormApplyIb) {
-      if (!props.detail.id) {
-        uni.showToast({ title: t('Ib.Custom.CustomerNotExist'), icon: 'none' })
-        return
-      }
-      const applyIbRowData: any = props.detail || {}
-      customId = applyIbRowData.id
-      cId = applyIbRowData.cId
-    } else {
-      // 从其他地方打开,需要选择客户
-      if (!addAgentForm.value.customerId) {
-        uni.showToast({ title: t('placeholder.choose'), icon: 'none' })
-        return
-      }
+    // 越南佣金分配不用判断customId
+    if (props.paramsType !== 'vietnam') {
+      if (!props.isFormApplyIb) {
+        if (!props.detail.id) {
+          uni.showToast({ title: t('Ib.Custom.CustomerNotExist'), icon: 'none' })
+          return
+        }
+        const applyIbRowData: any = props.detail || {}
+        customId = applyIbRowData.id
+        cId = applyIbRowData.cId
+      } else {
+        // 从其他地方打开,需要选择客户
+        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
+        // 从客户列表中找到选中的客户对象
+        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
       }
-      customId = selectedCustomer.value
-      cId = selectedCustomer.cId
     }
 
     try {
       // 构建points数据
       const points = buildCommissionTemplatePoints()
-      console.log(points)
+      // console.log(points)
       // 调用新增代理申请接口
-      const res = await ibApi.agentApplyAddPoint({
+      let params = {
         customId: customId,
         cId: cId,
         points: points,
-      })
+      }
+      if (props.paramsType === 'vietnam') {
+        params = {
+          agentId: props.detail.id,
+          points: points,
+        }
+      }
+
+      // 越南分配和新增代理
+      const res = props.paramsType === 'vietnam' ?await ibApi.saveVietnamPoints(params):await ibApi.agentApplyAddPoint(params)
 
       if (res.code == Code.StatusOK) {
-        uni.showToast({ title: res.msg || t('Ib.Custom.SubmitSuccess'), icon: 'success' })
+        uni.showToast({ title: res.msg || props.paramsType?t("Ib.Custom.SaveSuccess"):t('Ib.Custom.SubmitSuccess'), icon: 'success' })
         closeDia()
-        emit('confirm') // 刷新列表
+        emit('confirm')
+
       } else {
-        uni.showToast({ title: res.msg || t('Ib.Custom.SubmitFailed'), icon: 'none' })
+        uni.showToast({ title: res.msg || props.paramsType?t("Ib.Custom.SaveFailed"):t('Ib.Custom.SubmitFailed'), icon: 'none' })
       }
     } catch (error) {
-      console.error('新增代理失败:', error)
-      uni.showToast({ title: t('Ib.Custom.SubmitFailed'), icon: 'none' })
+      console.error('新增代理失败或保存越南分配数据失败:', error)
+      uni.showToast({ title: props.paramsType?t("Ib.Custom.SaveFailed"):t('Ib.Custom.SubmitFailed'), icon: 'none' })
     }
   }
 </script>

+ 92 - 9
pages/ib/subsList.vue

@@ -36,6 +36,27 @@
         </template>
       </cwg-tabel>
     </view>
+    <ApplyIbDialog ref="applyIbDialogRef" :visible="applyVisible" @close="closeApplyIb" @confirm="confirmApply" :title="formDia?'Ib.Custom.Commit3':'Ib.Report.Title5'" :isFormApplyIb="formDia" :paramsType="applyType" :detail="applyDetail"/>
+    <cwg-popup
+      :visible="exclusiveVisible"
+      :title="t('Ib.Custom.Commit5')"
+      :cancelText="t('Btn.Cancel')"
+      :confirmText="t('Btn.Confirm')"
+      @close="cancelExclusiveCommission"
+      @confirm="confirmExclusiveCommission"
+    >
+      <view class="dia-content">
+        <uni-forms ref="exclusiveCommissionFormRef" labelWidth="240">
+          <uni-forms-item :label="t('Ib.Custom.Commit5')" prop="selectedPoint">
+            <cwg-combox
+              v-model:value="exclusiveCommissionForm.selectedPoint"
+              :options="exclusiveCommissionForm.pointOptions"
+              :placeholder="t('placeholder.choose')"
+            />
+          </uni-forms-item>
+        </uni-forms>
+      </view>
+    </cwg-popup>
   </cwg-page-wrapper>
 </template>
 
@@ -50,6 +71,7 @@
   import { lang } from '@/composables/config'
   import { ibApi } from '@/service/ib'
   import { useFilters } from '@/composables/useFilters'
+  import ApplyIbDialog from '@/pages/ib/components/applyIbDialog.vue'
 
   const { numberFormat, numberDecimal } = useFilters()
 
@@ -61,7 +83,22 @@
     startDate: '',
     endDate: '',
   })
+  const tableRef = ref(null)
+  const applyIbDialogRef = ref(null)
+  const applyVisible = ref(false)
+  const applyType = ref('')
+  const applyDetail = ref()
+  const formDia = ref(false)
+  const exclusiveVisible = ref(false)
+  const exclusiveCommissionFormRef = ref(null)
+  const exclusiveCommissionForm = ref({
+    agentId: "",
+    selectedPoint: '',
+    pointOptions: [],
+  })
+  const exclusiveRow = ref<any>(null)
   const { t, locale } = useI18n()
+  const { Code } = Config
   // 表格列配置
   const columns = ref([
     {
@@ -138,6 +175,9 @@
     search.value.endDate = val[1]
   }
 
+  onMounted(()=>{
+    applyVisible.value = true
+  })
   // 下拉菜单配置
   const menuList = (row) => {
     return [
@@ -157,17 +197,60 @@
   }
   const handleMenuClick = (item) => {
     if (item.type == 'vietnamDistribution') {
-      const { cId, id, permissionDisplay } = item.row
-      formInfoRow.value = {
-        cId, id, permissionDisplay,
+      const { agentId, id } = item.row
+      applyDetail.value = {
+        id: id|| agentId
       }
-      docVisible.value = true
+      formDia.value = true
+      applyType.value = 'vietnam'
+      applyVisible.value = true
     } else if (item.type == 'exclusiveCommission') {
-      const { cId, id, comPoint1, hide1 } = item.row
-      pointForm.value = {
-        cId, id, comPoint1, hide1,
+      openExclusiveCommission(item.row)
+    }
+  }
+  const addSub = () => {
+    formDia.value = false
+    applyVisible.value = true
+  }
+  const closeApplyIb = () => {
+    applyVisible.value = false
+  }
+  const confirmApply = (data) => {
+    tableRef.value.refreshTable()
+  }
+
+  const normalizePointOptions = (options: any[]) => {
+    if (!Array.isArray(options)) return []
+    return options.map((o: any) => ({
+      text: o.label ?? o.text ?? o.name ?? String(o.value ?? ''),
+      value: o.value,
+    }))
+  }
+
+  const openExclusiveCommission = async (row: any) => {
+    exclusiveCommissionForm.value.agentId = row.id
+    exclusiveCommissionForm.value.selectedPoint = ''
+    exclusiveCommissionForm.value.pointOptions = normalizePointOptions(row?.exclusiveCommissionOptions || [])
+    exclusiveVisible.value = true
+  }
+
+  const cancelExclusiveCommission = () => {
+    exclusiveVisible.value = false
+    exclusiveCommissionForm.value.selectedPoint = ''
+    exclusiveCommissionForm.value.pointOptions = []
+  }
+
+  const confirmExclusiveCommission = async () => {
+    try {
+      const res = await ibApi.agentHiddenPointAdd({
+        agentId: exclusiveCommissionForm.value.agentId,
+        point: [{ value: exclusiveCommissionForm.value.selectedPoint }],
+      })
+      if (res.code == Code.StatusOK) {
+        cancelExclusiveCommission()
+        tableRef.value?.refreshTable?.()
       }
-      pointVisible.value = true
+    } catch (e) {
     }
   }
 </script>
@@ -184,4 +267,4 @@
     line-height: px2rpx(36);
     min-width: px2rpx(120);
   }
-</style>
+</style>