Browse Source

销售排名统计修改

hbchen 11 months ago
parent
commit
ba91fba107
1 changed files with 60 additions and 20 deletions
  1. 60 20
      src/views/financialStatistics/salesStatistics.vue

+ 60 - 20
src/views/financialStatistics/salesStatistics.vue

@@ -1,6 +1,6 @@
 <script setup>
   import {getSellerGroupStatisticsList,getSellerStatisticsList} from '@/api/financialStatistics'
-  import {getSellerGroupList,getSellerTeamList} from '@/api/crm'
+  import {getSellerGroupList,getSellerTeamList,getSellerList} from '@/api/crm'
   import {downloadByFlow} from '@/utils/common-methods'
   const moment = inject('$moment')
 
@@ -10,7 +10,10 @@
   {text:'近2月',tabId:3,type:'month',diff:2},{text:'近3月',tabId:4,type:'month',diff:3},{text:'今年以来',tabId:5,type:'year',diff:1}]
 
   // let groupList=ref([])
-  let sellerSellerTeamList=ref([])
+  const sellerTeamList=ref([])
+  const sellerCascaderRef=ref(null)
+  const sellerArr=ref([])
+
   const tabType=ref(1)
   const statisticsData=reactive({
     tableData:[],
@@ -41,6 +44,8 @@
   // 日期按钮选项
   const currentTabId=ref(0)
 
+  const tableLoading=ref(false)
+
   watch(createtime,(newVal)=>{
     if(newVal){
       searchParams.start_date=newVal[0]
@@ -52,16 +57,10 @@
     searchStatistics()
     
   })
-  // 销售类型缓存 为了减少请求次数
-  // let sellerTypeCache=0
 
   const changeTab=(tab)=>{
     if(tabType.value==tab) return 
     tabType.value=tab
-    // if(tab==2 && sellerTypeCache!=searchParams.seller_type){
-      // getSellerGroup()
-    getSellerListFun()
-    // }
     searchParams.current=1
     searchParams.page_size=10
     // searchParams.group_id=''
@@ -71,8 +70,16 @@
     searchParams.company_type=0
     searchParams.show_resign=false
     currentTabId.value=0
+    sellerArr.value=[]
+    if(tab==2){
+      // getSellerGroup()
+      getSellerListFun()
+      searchParams.seller_type=0
+    }else{
+      searchParams.seller_type=1
+    }
     if(createtime.value===null){
-      statisticsList()
+      tab==1 && statisticsList()
     }else{
       // 监听了createtime,createtime变化就会发起请求,避免发起两次请求
       createtime.value=null
@@ -80,24 +87,46 @@
   }
 
   const sellerChange=(value)=>{
-    console.log(value);
-    searchParams.seller_ids=(value&&value.length)?value.join(','):''
+    if(value && value.length){
+      let node = sellerCascaderRef.value.getCheckedNodes()[0]
+      searchParams.seller_type=node.data.product_id || 0
+      setDisabled(sellerTeamList.value,node.data.product_id)
+      searchParams.seller_ids=value.join(',')
+    }else{
+      searchParams.seller_type=0
+      searchParams.seller_ids=''
+      setDisabled(sellerTeamList.value,0)
+    }
     statisticsList()
   }
 
+  const setDisabled=(list,product_id)=>{
+    list.forEach(element => {
+      element.selected=(product_id==0 || element.product_id == product_id)?false:true
+      if(element.child?.length){
+        setDisabled(element.child,product_id)
+      }
+    });
+  }
+
   // 获取列表
   const statisticsList=()=>{
+    tableLoading.value=true
     if(tabType.value==1){
       // 销售组排名 - 无分页
       getSellerGroupStatisticsList(searchParams).then(res=>{
         statisticsData.tableData = res.data || []
         statisticsData.total = 0
+      }).finally(()=>{
+        tableLoading.value=false
       })
     }else if(tabType.value==2){
       // 销售排名
       getSellerStatisticsList(searchParams).then(res=>{
         statisticsData.tableData = res.data.list || []
         statisticsData.total = res.data.page.total || 0
+      }).finally(()=>{
+        tableLoading.value=false
       })
     }
 
@@ -105,7 +134,6 @@
 
   // 获取销售组别
   // const getSellerGroup=()=>{
-  //   sellerTypeCache=searchParams.seller_type
   //   getSellerGroupList({seller_type:searchParams.seller_type}).then(res=>{
   //     groupList.value=res.data || []
   //   })
@@ -113,14 +141,26 @@
 
   //获取销售列表
   const getSellerListFun=()=>{
-    getSellerTeamList().then(res=>{
-      sellerSellerTeamList.value = res.data.all_list || []
+    tableLoading.value=true
+    getSellerList().then(res=>{
+      sellerTeamList.value = res.data.all_list || []
+      getFiccSellerIds(sellerTeamList.value.filter(it => it.product_id==1))
+    }).finally(()=>{
+      sellerChange(sellerArr.value)
+    })
+  }
+  const getFiccSellerIds=(list)=>{
+    list.forEach(it =>{
+      if(it.child?.length){
+        getFiccSellerIds(it.child)
+      }else{
+        sellerArr.value.push(it.seller_id) 
+      }
     })
   }
-  
   // 切换销售类型
   // const changeSellerType=()=>{
-    // if(tabType.value==2&&sellerTypeCache!=searchParams.seller_type){
+    // if(tabType.value==2){
     //   searchParams.group_id=''
     //   getSellerGroup()
     // }
@@ -196,9 +236,9 @@
           @change="searchStatistics" v-show="tabType==2" clearable >
             <el-option :label="item.group_name" :value="item.group_id" v-for="item in groupList"></el-option>
           </el-select> -->
-          <el-cascader :options="sellerSellerTeamList" style="width: 240px;margin:0 30px 8px 0;" filterable collapse-tags-tooltip
-            @change="sellerChange" placeholder="请选择销售" clearable collapse-tags :show-all-levels="false"
-            :props="{multiple:true,label:'seller_name',value:'seller_id',children:'child',emitPath:false}" key="seller" 
+          <el-cascader :options="sellerTeamList" v-model="sellerArr" style="width: 240px;margin:0 30px 8px 0;z-index: 10;" filterable collapse-tags-tooltip
+            @change="sellerChange" placeholder="请选择销售" clearable collapse-tags :show-all-levels="false" ref="sellerCascaderRef"
+            :props="{multiple:true,label:'seller_name',value:'seller_id',children:'child',emitPath:false,disabled:'selected'}" key="seller" 
             v-if="tabType==2">
           </el-cascader>
           <el-checkbox v-model="searchParams.show_resign" style="margin: 0 30px 8px 0;"
@@ -223,7 +263,7 @@
         </div>
       </div>
       <div class="statistics-table-zone" >
-        <el-table :data="statisticsData.tableData" border
+        <el-table :data="statisticsData.tableData" border v-loading="tableLoading" element-loading-text="数据加载中"
         max-height="600" @sort-change="sortChange" size='large'>
           <el-table-column label="排名" align="center">
             <template #default="{$index}">