Jelajahi Sumber

Merge branch 'need-pool#863'

cxmo 1 tahun lalu
induk
melakukan
230e4c6294
1 mengubah file dengan 37 tambahan dan 2 penghapusan
  1. 37 2
      src/views/business_ETA_manage/businessAuth.vue

+ 37 - 2
src/views/business_ETA_manage/businessAuth.vue

@@ -8,6 +8,7 @@
             </div>
         </div>
         <div class="auth-wrap">
+            <el-checkbox v-model="checkAll" :indeterminate="isIndeterminate" style="margin-bottom: 20px;">全选</el-checkbox>
             <el-tree 
                 v-loading="treeLoading"
                 ref="checkboxTree"
@@ -16,7 +17,8 @@
                 :default-expand-all="false"
                 show-checkbox 
                 node-key="MenuId"
-                :default-checked-keys="defaultCheckedKeys">
+                :default-checked-keys="defaultCheckedKeys"
+                @check-change="()=>{handleCheckChange()}">
             </el-tree>
         </div>
     </div>
@@ -29,9 +31,23 @@ export default {
         return {
             authList:[],
             defaultCheckedKeys:[],
-            treeLoading:false
+            treeLoading:false,
+            checkAll:false,
+            isIndeterminate:false
         };
     },
+    watch:{
+        checkAll(newVal){
+            if(newVal){
+                const topLevelNodes = this.authList.map(i=>i.MenuId)
+                this.$refs.checkboxTree.setCheckedKeys(topLevelNodes)
+            }else{
+                if(!this.isIndeterminate){
+                    this.$refs.checkboxTree.setCheckedKeys([])
+                }
+            }
+        }
+    },
     methods: {
         getBusinessAuthList(){
             const EtaBusinessId = this.$route.query.id
@@ -46,6 +62,7 @@ export default {
                 const {List,ChoiceList=[],HalfChoiceList=[]} = res.Data
                 this.authList = List||[]
                 this.defaultCheckedKeys = ChoiceList.filter((item)=>!HalfChoiceList.some((halfItem)=>item===halfItem))
+                this.handleCheckChange(ChoiceList,HalfChoiceList)
             })
         },
         async handleBtnClik(type){
@@ -69,6 +86,24 @@ export default {
                 this.$message.success('权限设置成功')
             }
             this.$router.push('/businessETAList')
+        },
+        handleCheckChange(choiceList,HalfChoiceList){
+            const keys = choiceList||this.$refs.checkboxTree.getCheckedKeys()
+            const halfKeys = HalfChoiceList||this.$refs.checkboxTree.getHalfCheckedKeys()
+            const ChoiceList = Array.from(new Set([...keys,...halfKeys]))
+            const topLevelNodes = this.authList.map(i=>i.MenuId)
+            let nodeLength = 0
+            topLevelNodes.forEach(i=>{
+                if(ChoiceList.includes(i)){nodeLength++}
+                if(!ChoiceList.includes(i)){nodeLength--}
+            })
+            if(nodeLength===topLevelNodes.length){
+                this.checkAll = true
+                this.isIndeterminate = false
+            }else{
+                this.checkAll = false
+                this.isIndeterminate = Boolean(ChoiceList.length)
+            }
         }
     },
     mounted(){