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

机构管理页面新增编辑逻辑修改

haizhouwang 2 лет назад
Родитель
Сommit
e167254a7c
2 измененных файлов с 132 добавлено и 125 удалено
  1. 8 0
      src/http/moudules/dept.js
  2. 124 125
      src/views/Sys/Deptall.vue

+ 8 - 0
src/http/moudules/dept.js

@@ -135,3 +135,11 @@ export const queryTree = (data) => {
         data
     })
 }
+
+// 删除机构
+export const deleteDept = (id) => {
+    return axios({
+        url: '/dept/'+id,
+        method: 'delete'
+    })
+}

+ 124 - 125
src/views/Sys/Deptall.vue

@@ -34,6 +34,7 @@
             <template slot-scope="scope">
               <el-button type="text" size="medium " icon="el-icon-edit" @click.native.stop="handleEdit(scope.row)"
                 @findPage="findSubDeptPage">编辑</el-button>
+              <el-button type="text" style="color:#f56c6c" :round="false" size="medium " icon="el-icon-delete" @click.native.stop="deleteMechanism(scope.row)">删除</el-button>
             </template>
           </el-table-column>
         </el-table>
@@ -394,15 +395,18 @@ export default {
             trigger: "blur",
           },
         ],
-        // province: [
-        //   { required: true, message: '请选择省', trigger: 'change' }
-        // ],
-        // city: [
-        //   { required: true, message: '请选择市', trigger: 'change' }
-        // ],
-        // area: [
-        //   { required: true, message: '请选择区', trigger: 'change' }
-        // ]
+      },
+      ///省市区表单校验规则
+      roleProCity:{
+        province: [
+          { required: true, message: '请选择省', trigger: 'change' }
+        ],
+        city: [
+          { required: true, message: '请选择市', trigger: 'change' }
+        ],
+        area: [
+          { required: true, message: '请选择区', trigger: 'change' }
+        ]
       },
       //-- address begin ---
       selectAddress: {
@@ -444,6 +448,7 @@ export default {
   methods: {
     //点击每一行的事件
     rowClick(row, treeNode) {
+      console.log(row)
       //点每行展开折叠
       row.expanded = !row.expanded;
       this.$refs.expandTable.toggleRowExpansion(row, row.expanded);
@@ -526,59 +531,34 @@ export default {
         this.dataForm.area = "";
       } else {
         if (!!this.currentTreeNode.province) {
-          this.selectAddress.province = {areaCname:this.currentTreeNode.province};
+          this.transitionFun('province',this.currentTreeNode.province)
           this.dataForm.province = this.currentTreeNode.province;
           this.dataForm.id = "";
         }
         if (!!this.currentTreeNode.city) {
-          this.selectAddress.city = {areaCname:this.currentTreeNode.city};
+          this.transitionFun('city',this.currentTreeNode.city)
           this.dataForm.city = this.currentTreeNode.city;
           this.dataForm.id = "";
         }
         if (!!this.currentTreeNode.area) {
-          this.selectAddress.area = {areaCname:this.currentTreeNode.area};
+          this.transitionFun('area',this.currentTreeNode.area)
           this.dataForm.area = this.currentTreeNode.area;
           this.dataForm.id = "";
         }
-        /****
-         * 获取市、区下拉框对应数据 ...start
-         */
-          let cityArr = this.provinces.filter(item=>{
-            return this.dataForm.province == item.areaCname
-          })
-          if(cityArr.length>0){
-            this.cities=cityArr[0].child
-            let areaArr = this.cities.filter(item=>{
-              return this.dataForm.city == item.areaCname
-            })
-            if(areaArr.length>0){
-              this.areas=areaArr[0].child
-            }
-          }
-        /****
-         * 获取市、区下拉框对应数据 ...end
-         */
+        that.getProvinceData();//获取市、区下拉框对应数据
       }
-
+      //设置省市区是否可操作以及必填逻辑
       if (this.currentTreeNode.comlevel == 1) {
-        this.disabledAddress.province = true;
-        this.disabledAddress.city = false;
-        this.disabledAddress.area = false;
+        this.resetFunction('province')
       }
       if (this.currentTreeNode.comlevel == 2) {
-        this.disabledAddress.province = false;
-        this.disabledAddress.city = true;
-        this.disabledAddress.area = false;
+        this.resetFunction('city')
       }
       if (this.currentTreeNode.comlevel == 3) {
-        this.disabledAddress.province = false;
-        this.disabledAddress.city = false;
-        this.disabledAddress.area = true;
+        this.resetFunction('area')
       }
       if (this.currentTreeNode.comlevel > 3) {
-        this.disabledAddress.province = false;
-        this.disabledAddress.city = false;
-        this.disabledAddress.area = false;
+        this.resetFunction()
       }
       if (this.currentTreeNode.comlevel >= 5) {
         return this.$message({
@@ -612,6 +592,7 @@ export default {
       if (this.dataForm.comlevel === "5") {
        //第5级是门店,去服务器获取最大编号
        this.$api.dept.findMaxHouseId(this.currentTreeNode.id).then((res) => {
+        console.log(res)
          let newId = parseInt(res.data) + 1;
          if (newId < 10) {
            newId = "0" + newId;
@@ -631,6 +612,7 @@ export default {
           type: "info",
         });
       }
+      console.log(this.currentTreeNode.id)
       if (this.currentTreeNode.id.indexOf("D") >= 0) {
         return this.$message({
           message: "部门下无法增设部门",
@@ -642,6 +624,7 @@ export default {
       this.deptDataForm.deptType = "D"; //类型是机构(C是机构,D是部门)
       this.deptDataForm.parentId = this.currentTreeNode.id;
       this.$api.dept.findMaxDeptId(this.currentTreeNode.id).then((res) => {
+        console.log(res)
         let newId = parseInt(res.data) + 1;
         if (newId < 10) {
           newId = "0" + newId;
@@ -710,61 +693,31 @@ export default {
       if (data.deptType == "C") {
         //编辑机构
         this.dialogTitle = "修改机构信息";
-        switch(data.comlevel){
-          case '1':
-              break;
-          case '2':
-            this.disabledAddress = {
-              province: true,
+        this.disabledAddress = {
+              province: false,
               city: false,
               area: false,
             }
-            break;
-          case '3':
-            this.disabledAddress = {
-              province: true,
-              city: true,
-              area: false,
-            }
-            break;
-          case '4':
-            this.disabledAddress = {
-              province: true,
-              city: true,
-              area: true,
-            }
-            break;
-          default:
-            this.disabledAddress = {
-              province: true,
-              city: true,
-              area: true,
-            }
-        }
           this.$api.dept.getDeptById(data.id).then((res) => {
             that.dataForm = res.data;
             Object.assign(that.dataForm, res.data);
-            that.selectAddress.province = {areaCname:that.dataForm.province};
-            that.selectAddress.city = {areaCname:that.dataForm.city};
-            that.selectAddress.area = {areaCname:that.dataForm.area};
-            /****
-             * 获取市、区下拉框对应数据 ...start
-             */
+            this.transitionFun('province',that.dataForm.province)
+            this.transitionFun('city',that.dataForm.city)
+            this.transitionFun('area',that.dataForm.area)
+           
             let cityArr = that.provinces.filter(item=>{
-              return that.dataForm.province == item.areaCname
+              return that.dataForm.province == item.areaCode
             })
             if(cityArr.length>0){
               that.cities=cityArr[0].child
                 let areaArr = that.cities.filter(item=>{
-                  return that.dataForm.city == item.areaCname
+                  return that.dataForm.city == item.areaCode
                 })
                 if(areaArr.length>0){
                   that.areas=areaArr[0].child
                 }
             }
-            /****
-             * 获取市、区下拉框对应数据 ...end
-             */
+            that.getProvinceData();//获取市、区下拉框对应数据
             this.$api.dept.getDeptById(res.data.parentId).then((res) => {
               this.currentTreeNode = res.data;
             });
@@ -780,6 +733,38 @@ export default {
         });
       }
     },
+    //删除机构或部门
+    deleteMechanism(data){
+      let that = this
+      that.$confirm('此操作将删除该数据, 是否继续?', '提示', {
+          confirmButtonText: '确定',
+          cancelButtonText: '取消',
+          type: 'warning'
+        }).then(() => {
+          that.$api.dept.deleteDept(data.id).then((res)=>{
+            if(res.code==200){
+              this.findSubDeptPage();
+              this.findTreeData();
+              this.currentTreeNode = null;
+              that.$message({
+                type: 'success',
+                message: '删除成功!'
+              });
+            }else{
+              that.$message({
+                type: 'warning',
+                message: res.msg
+              });
+            }
+          })
+        }).catch(() => {
+          that.$message({
+            type: 'info',
+            message: '已取消删除'
+          });          
+        });
+    
+    },
     handleDeleteFlag(data) {
       let that = this;
       this.$api.dept.batchDelete(data.params).then((data) => {
@@ -818,24 +803,6 @@ export default {
     },
     // 提交表单
     submitForm() {
-      // if (!this.dataForm.id || this.dataForm.id == this.dataForm.parentId) {
-      //   return this.$message({
-      //     message: "请选择完整地区生成编码",
-      //     type: "error",
-      //   });
-      // }
-      if (this.operType == "ADDC") {
-        if (!!this.dataForm.id) {
-          this.dataForm.id = this.dataForm.id.replace(/(^\s*)|(\s*$)/g, "");
-        }
-        let a = this.dataForm.id.substring(0, this.dataForm.parentId.length);
-        if (a !== this.dataForm.parentId) {
-          return this.$message({
-            message: "新增机构编码必须已[" + this.dataForm.parentId + "]开头",
-            type: "error",
-          });
-        }
-      }
       let that = this;
       this.$refs["dataForm"].validate((valid) => {
         if (valid) {
@@ -843,7 +810,6 @@ export default {
           let params = Object.assign({}, this.dataForm);
           if (that.operType === "ADD" || that.operType === "ADDC") {
             let paramData = {
-              id: params.id,
               name: params.name,
               parentId: params.parentId,
               comlevel: params.comlevel, //机构级别
@@ -946,15 +912,8 @@ export default {
     // 选择省
     selectProvince(value) {
       this.selectAddress.province = {areaCname:value.areaCname};
-      this.dataForm.province = value.areaCname;
+      this.dataForm.province = value.areaCode;
       this.cities = value.child;
-      if (this.dataForm.comlevel == 5) {
-      } else if (value.areaCode) {
-        this.dataForm.id = this.dataForm.parentId + value.areaCode.substr(0, 2);
-        // this.dataForm.id = ("99" + value.code).substr(0, 4);
-      } else {
-        this.dataForm.id = "";
-      }
       this.selectAddress.city = '';
       this.dataForm.city = '';
       this.selectAddress.area = '';
@@ -963,29 +922,15 @@ export default {
      // 选择市
     selectCity(value) {
       this.selectAddress.city = {areaCname:value.areaCname};
-      this.dataForm.city = value.areaCname;
+      this.dataForm.city = value.areaCode;
       this.areas = value.child;
-      if (this.dataForm.comlevel == 5) {
-      } else if (value.areaCode) {
-        this.dataForm.id = this.dataForm.parentId + value.areaCode.substr(2, 2);
-        // this.dataForm.id = ("99" + value.areaCode).substr(0, 6);
-      } else {
-        this.dataForm.id = "";
-      }
       this.selectAddress.area = '';
       this.dataForm.area = '';
     },
      // 选择区
     selectArea(value) {
       this.selectAddress.area = {areaCname:value.areaCname};
-      this.dataForm.area = value.areaCname;
-      if (this.dataForm.comlevel == 5) {
-      } else if (value.areaCode) {
-        this.dataForm.id = this.dataForm.parentId + value.areaCode.substr(4, 2);
-        // this.dataForm.id = ("99" + value.areaCode).substr(0, 8);
-      } else {
-        this.dataForm.id = "";
-      }
+      this.dataForm.area = value.areaCode;
     },
 
     //关闭机构弹框
@@ -1011,6 +956,60 @@ export default {
       // this.$refs.deptDataForm.resetFields();
       this.deptDialogVisible = false;
     },
+    /****
+     * 设置省市区校验规则
+     * objName为省市区名称
+     */
+    resetFunction(objName){
+      for (const key in this.roleProCity) {
+        if(!objName){ //当级别大于3时需先赋值在清空对应校验规则
+          this.dataRule[key] = []
+        }
+        if(objName!=key){ 
+          delete this.dataRule[key] //删除其他两个校验规则
+          this.disabledAddress[key] = false; //设置其他选择框不可点击
+        }else{
+          this.disabledAddress[key] = true;
+          this.$set( this.dataRule,key,this.roleProCity.area)
+        }
+      }
+    },
+    /****
+     * 省市县code转换为文字
+     *  闭包搜寻多维数组数据进行转换
+     *  objName为省市县赋值名称
+     *  codeParams为需要进行判断的省市县code
+     *  data为进行查找的数据
+     */
+    transitionFun(objName,codeParams,data){
+      data = data || this.provinces
+      for (var i = 0;i<data.length;i++){
+        if(codeParams == data[i].areaCode){
+          this.selectAddress[objName] = {areaCname:data[i].areaCname }
+        }else{
+          if(data[i].child.length){
+            this.transitionFun(objName,codeParams,data[i].child)
+          }
+        }
+      }
+    },
+    /****
+     * 获取市、区下拉框对应数据
+     */
+    getProvinceData(){
+      let cityArr = this.provinces.filter(item=>{
+        return this.dataForm.province == item.areaCode
+      })
+      if(cityArr.length>0){
+        this.cities=cityArr[0].child
+        let areaArr = this.cities.filter(item=>{
+          return this.dataForm.city == item.areaCode
+        })
+        if(areaArr.length>0){
+          this.areas=areaArr[0].child
+        }
+      }
+    },
   },
 };
 </script>