From 12fd8f6b04b26ef02bccdf5fd0bcefb59541c7f6 Mon Sep 17 00:00:00 2001
From: “dzb” <2632970487@qq.com>
Date: 星期三, 02 十一月 2022 17:04:23 +0800
Subject: [PATCH] :预警研判

---
 src/views/operate/baseSetting/violation/createUser/index.vue |  246 +++++++++++++++++++++++++++++++------------------
 1 files changed, 156 insertions(+), 90 deletions(-)

diff --git a/src/views/operate/baseSetting/violation/createUser/index.vue b/src/views/operate/baseSetting/violation/createUser/index.vue
index fa9d67c..b55af77 100644
--- a/src/views/operate/baseSetting/violation/createUser/index.vue
+++ b/src/views/operate/baseSetting/violation/createUser/index.vue
@@ -2,11 +2,8 @@
     <div class="createUser">
         <main>
             <div class="mainContent">
-                <el-form ref="user" :rules="createThings" label-width="140px" autoComplete="on" :model="things" label-position="right">
-                    <!-- 杩濊浜嬮」缂栧彿 -->
-                    <!-- <el-form-item class="optionItem" label="杩濊浜嬮」缂栧彿:" prop="number">
-                        <el-input v-model="things.number" placeholder="璇峰~鍐欒繚瑙勪簨椤圭紪鍙�"></el-input>
-                    </el-form-item>  -->
+                <el-form ref="user" :rules="createThings" label-width="140px" autoComplete="on" :model="things"
+                    label-position="right">
                     <!-- 鏂板鐨勭被鍨嬫垨澶х被鎴栧皬绫� -->
                     <el-form-item class="optionItem" label="鏂板鍚嶇О:" prop="name">
                         <el-input v-model="things.name" placeholder="璇疯緭鍏ユ柊澧炲悕绉�"></el-input>
@@ -21,15 +18,18 @@
                     </el-form-item>
                     <!-- 鐖剁骇id -->
                     <el-form-item class="optionItem" label="鐖剁骇:" prop="parentId">
-                        <el-select v-model="things.parentId" placeholder="璇烽�夋嫨鎵�灞炵被鍨�" >
-                            <el-option v-for="item in parentList" :key="item.id" :label="item.name"
-                                :value="item.id">
+                        <el-select v-model="things.parentId" placeholder="璇烽�夋嫨鎵�灞炵被鍨�" :disabled="things.level===1">
+                            <el-option :value="mylabel">
+                                <el-tree ref="tree" :check-strictly="true"  :data="parentList" :props="defaultProps" show-checkbox
+                                    @check-change="handleCheck" default-expand-all node-key="id">
+                                </el-tree>
                             </el-option>
                         </el-select>
                     </el-form-item>
                     <!-- 妗堢敱 -->
                     <el-form-item class="optionItem" label="妗堢敱:" prop="type">
-                        <el-input type="textarea" autosize v-model="things.type" placeholder="璇疯緭鍏ユ鐢辨弿杩板唴瀹�"></el-input>
+                        <el-input type="textarea" :rows="2" v-model="things.type" placeholder="璇疯緭鍏ユ鐢辨弿杩板唴瀹�"
+                            :disabled="things.level!==4"></el-input>
                     </el-form-item>
                     <el-form-item>
                         <div class="optionBtn">
@@ -45,42 +45,35 @@
 <script>
 export default {
     data() {
-        const checkName = (rule,value,callback)=>{
-            if(value){
+        const checkName = (rule, value, callback) => {
+            if (value) {
                 callback();
-            }else{
+            } else {
                 callback(new Error('鏂板杩濊绫诲瀷涓嶈兘涓虹┖'));
             }
         }
-        const checkLevel = (rule,value,callback)=>{
-            if(value){
+        const checkLevel = (rule, value, callback) => {
+            if (value) {
                 callback();
-            }else{
+            } else {
                 callback(new Error('鏂板杩濊绛夌骇涓嶈兘涓虹┖'));
             }
         }
-        // const checkId = (rule,value,callback)=>{
-        //     if(value){
-        //         callback();
-        //     }else{
-        //         callback(new Error('鏂板杩濊绛夌骇涓嶈兘涓虹┖'));
-        //     }
-        // }
         return {
             things: {
-                name:'',
-                parentId:'',
-                level:'',
+                name: '',
+                parentId: '',
+                level: '',
             },
-            createThings:{
-                name:[
+            createThings: {
+                name: [
                     {
-                        required:true,trigger:'blur',validator:checkName
+                        required: true, trigger: 'blur', validator: checkName
                     }
                 ],
-                level:[
+                level: [
                     {
-                        required:true,trigger:'change',validator:checkLevel
+                        required: true, trigger: 'change', validator: checkLevel
                     }
                 ],
                 // parentId:[
@@ -89,59 +82,81 @@
                 //     }
                 // ]
             },
-            levelList:[
+            levelList: [
                 {
-                    label:"杩濊涓被鍨�",
-                    value:1,
+                    label: "杩濊涓被鍨�",
+                    value: 1,
                 },
                 {
-                    label:"澶х被",
-                    value:2,
+                    label: "澶х被",
+                    value: 2,
                 },
                 {
-                    label:"灏忕被",
-                    value:3,
+                    label: "灏忕被",
+                    value: 3,
                 },
                 {
-                    label:"妗堢敱",
-                    value:4,
+                    label: "妗堢敱",
+                    value: 4,
                 },
             ],
-            parentList:[],
+            parentList: [],
+            selectOrg: {
+                orgsid: []
+            },
+            defaultProps: {
+                children: 'children',
+                label: 'name',
+                disabled:(data,node)=>{
+                    if (data.level<this.things.level-1) {
+                        return !data.leaf
+                    }
+                }
+            },
+            mylabel:''
         }
     },
     created() {
     },
     methods: {
         // 鏌ヨ鎵�灞炵被鍨�
-        getTypeThird() {
-            this.$axios({
+        async getTypeThird() {
+            let arr = [];
+            await this.$axios({
                 method: 'get',
                 url: "sccg/violations/query/type_first",
             })
                 .then(res => {
-                    this.parentList = res.data;
+                    arr = res.data;
+                    // this.parentList = res.data;
                 })
+            return arr
         },
         // 鏌ヨ鎵�灞炲ぇ绫�
-        getTypeSecond(){
-            this.$axios({
+        async getTypeSecond() {
+            let arr = [];
+            await this.$axios({
                 method: 'get',
                 url: "sccg/violations/query/type_second",
             })
                 .then(res => {
-                    this.parentList = res.data;
+                    arr = res.data;
+                    // this.parentList = res.data;
                 })
+            return arr
         },
         // 鏌ヨ鎵�灞炲皬绫�
-        getTypeFirst(){
-            this.$axios({
+        async getTypeFirst() {
+            let arr = [];
+            await this.$axios({
                 method: 'get',
                 url: "sccg/violations/query/type_third",
             })
                 .then(res => {
-                    this.parentList = res.data;
+                    arr = res.data;
+                    // this.parentList = res.data;
                 })
+            return arr
         },
         // 鏌ヨ鎵�灞炴鐢�
         getEventLevel() {
@@ -152,60 +167,111 @@
                 .then(res => {
                     console.log(res);
                     this.parentList = res.data;
-                }) 
+                })
         },
         // 鎻愪氦鏂板杩濊绫诲瀷
-        handleSubmit(){
+        handleSubmit() {
             console.log(this.things);
-            this.$refs.user.validate((valid)=>{
+            this.$refs.user.validate((valid) => {
                 console.log(valid);
-                if(valid){
-                    const {things} = this;
+                if (valid) {
+                    const { things, selectOrg} = this;
+                    console.log(things,selectOrg.orgsid[0]);
                     this.$axios({
-                        method:'post',
-                        url:'sccg/violations/addition/type',
-                        data:{
-                            code:'1111',
-                            level:things.parentId === '' ? things.level : things.level+1,
-                            name:things.name,
-                            parentId:things.parentId=== '' ? 0 : things.parentId,
-                            typeCode:'01',
-                            typeName:'闂绫诲瀷',
-                            remark:things.type,
+                        method: 'post',
+                        url: 'sccg/violations/addition/type',
+                        data: {
+                            code: '1111',
+                            level: things.level,
+                            name: things.name,
+                            parentId: things.parentId === '' ? 0 : selectOrg.orgsid[0],
+                            typeCode: '01',
+                            typeName: '闂绫诲瀷',
+                            remark: things.type,
                         }
                     })
-                    .then(res=>{
-                        console.log(res);
-                        if(res.code === 200){
-                            this.$message({
-                                type:'success',
-                                message:'娣诲姞鎴愬姛'
-                            })
-                            this.$emit('changeDialog',{flag:false});
-                        }else{
-                            this.$message({
-                                type:'error',
-                                message:"娣诲姞澶辫触"
-                            })
-                        }
-                    })
-                }else{
+                        .then(res => {
+                            console.log(res);
+                            if (res.code === 200) {
+                                this.$message({
+                                    type: 'success',
+                                    message: '娣诲姞鎴愬姛'
+                                })
+                                this.$emit('changeDialog', { flag: false });
+                            } else {
+                                this.$message({
+                                    type: 'error',
+                                    message: "娣诲姞澶辫触"
+                                })
+                            }
+                        })
+                } else {
                     return false;
                 }
             })
         },
         // 妗堜欢绾у埆鍙樺寲
-        resetParentList(index){
-            if(index === 1){
-                this.getTypeThird();
-            }else if(index === 2){
-                this.getTypeSecond();
-            }else if(index === 3){
-                this.getTypeFirst();
-            }else{
-                this.getEventLevel();
+        async resetParentList(index) {
+            this.things.parentId=''
+            this.selectOrg.orgsid = [];
+            if (index === 1) {
+                // this.getTypeThird();
+            } else if (index === 2) {
+                // console.log(this.getTypeThird());
+                this.parentList = await this.getTypeThird();
+                this.parentList.forEach(item=>{
+                    item.children = [];
+                })
+            } else if (index === 3) {
+            
+                this.parentList = this.addChildren(await this.getTypeThird(), await this.getTypeSecond());
+                console.log(this.parentList);
+            } else {
+                let arr1 =  this.addChildren(await this.getTypeSecond(), await this.getTypeFirst());
+                this.parentList =  this.addChildren(await this.getTypeThird(), arr1);
             }
-        }
+        },
+        addChildren(parentArr, childArr) {
+            // console.log(parentArr.length,childArr);
+            parentArr.forEach(item => {
+                item.children = [];
+                childArr.forEach(child => {
+                    if (item.id === child.parentId) {
+                        item.children.push(child);
+                    }
+                })
+            })
+            console.log(parentArr);
+            return parentArr;
+        },
+        handleCheck(data, checked) {
+            this.things.parentId = data.name;
+            console.log(this.selectOrg.orgsid);
+            // 鑾峰彇褰撳墠閫夋嫨鐨刬d鍦ㄦ暟缁勪腑鐨勭储寮�
+            const indexs = this.selectOrg.orgsid.indexOf(data.id)
+            // 濡傛灉涓嶅瓨鍦ㄦ暟缁勪腑锛屽苟涓旀暟缁勪腑宸茬粡鏈変竴涓猧d骞朵笖checked涓簍rue鐨勬椂鍊欙紝浠h〃涓嶈兘鍐嶆閫夋嫨銆�
+            if (indexs < 0 && this.selectOrg.orgsid.length === 1 && checked) {
+                this.$message({
+                    message: '鍙兘閫夋嫨涓�涓尯鍩燂紒',
+                    type: 'error',
+                    showClose: true
+                })
+                // 璁剧疆宸查�夋嫨鐨勮妭鐐逛负false 寰堥噸瑕�
+                this.$refs.tree.setChecked(data, false)
+            } else if (this.selectOrg.orgsid.length === 0 && checked) {
+                // 鍙戠幇鏁扮粍涓虹┖ 骞朵笖鏄凡閫夋嫨
+                // 闃叉鏁扮粍鏈夊�硷紝棣栧厛娓呯┖锛屽啀push
+                this.selectOrg.orgsid = []
+                this.selectOrg.orgsid.push(data.id)
+            } else if (
+                indexs >= 0 &&
+                this.selectOrg.orgsid.length === 1 &&
+                !checked
+            ) {
+                // 鍐嶆鐩存帴杩涜璧嬪�间负绌烘搷浣�
+                this.selectOrg.orgsid = []
+            }
+        },
     },
     props: ['changeDialog']
 }

--
Gitblit v1.8.0