Kaynağa Gözat

增项物资类的增项分类级联选择器修改

ljm 6 yıl önce
ebeveyn
işleme
ca1315e738

+ 26 - 2
src/dashoo.cn/backend/api/controllers/oilsupplier/goodsaptitudeclass.go

@@ -289,13 +289,37 @@ func (this *OilGoodsAptitudeClassController) DeleteEntity() {
 // @Title get 获取物资类资质分类层级表
 // @Description get SampleType by token
 // @Success 200 {object} sampletype.SampleType
-// @router /getgoodsclasslist [get]
+// @router /getgoodsclasslist/:id [get]
 func (this *OilGoodsAptitudeClassController) GetGoodsClassList() {
+	ParentId := this.Ctx.Input.Param(":id")
+
+	where := " 1 = 1 "
+	if ParentId != "" {
+		where = where + " and ParentId = " + ParentId
+	}
+	where = where + " and DeletionStateCode = 0 "
 
-	where := " DeletionStateCode = 0 "
 	var list []goodsaptitudeclass.GoodsAptitudeClassList
 	svc := goodsaptitudeclass.GetOilGoodsAptitudeClassService(utils.DBE)
 	svc.GetEntitysByWhere(OilGoodsAptitudeClassName, where, &list)
+	var datainfo DataInfo
+	datainfo.Items = list
+
+	this.Data["json"] = &datainfo
+	this.ServeJSON()
+}
+
+// @Title get 获取子类
+// @Description get SampleType by token
+// @Success 200 {object} sampletype.SampleType
+// @router /getchildlist/:id [get]
+func (this *OilGoodsAptitudeClassController) GetChildList() {
+	ParentId := this.Ctx.Input.Param(":id")
+	sqlStr := "SELECT Id, `Code`, `Name`, ParentId FROM OilGoodsAptitudeClass WHERE FIND_IN_SET(ParentId, fun_getOilGoodsAptitudeClasschildlist(" + ParentId + ")) AND DeletionStateCode = 0"
+
+	svc := goodsaptitudeclass.GetOilGoodsAptitudeClassService(utils.DBE)
+	list, _ := svc.DBE.QueryString(sqlStr)
+
 	var datainfo DataInfo
 	datainfo.Items = list
 	this.Data["json"] = &datainfo

+ 72 - 5
src/dashoo.cn/frontend_web/src/pages/oilsupplier/supplierappend/_opera/goodsdataopera.vue

@@ -86,8 +86,8 @@
         <el-row>
           <el-col :span="12">
             <el-form-item label="分类名称" prop="checkSelectedOptList">
-              <el-cascader ref="cascader" :options="optionsList" style="width:100%" :props="goodsProps" change-on-select :show-all-levels="false" 
-                v-model="selectedOptList" @change="getCode" placeholder="请选择分类">
+              <el-cascader ref="cascader" :options="optionsList" style="width:100%" :props="goodsProps" :show-all-levels="false" 
+                v-model="selectedOptList" @active-item-change="getChildrens" @change="getCode" placeholder="请选择分类">
               </el-cascader>
             </el-form-item>
           </el-col>
@@ -160,6 +160,8 @@
           label: 'Name',
           children: 'children'
         },
+        ParentId: 0, //物资类初始父类Id值:0
+        flagId: 0, //标记是否第一次点击
         organizeTreeList: [], //推荐单位层级列表
         selectedOrgList: [], //已选择的单位列表
         organizeTreeProps: {
@@ -244,7 +246,7 @@
         this.getSortList()
       }
       this.getOrgTreeList() //获取推荐单位层级列表
-      this.getGoodsTreeList() //获取物资类层级列表
+      this.getGoodsTreeList(this.ParentId) //获取物资类层级列表
       this.getSupplierList() //获取供应方公司列表
     },
     methods: {
@@ -279,17 +281,56 @@
       },
 
       //获取物资类层级列表
-      getGoodsTreeList() {
+      getGoodsTreeList(Id) {
         let _this = this
-        this.$axios.get('goodsaptitudeclass/getgoodsclasslist', {})
+        this.$axios.get('goodsaptitudeclass/getgoodsclasslist/' + Id, {})
           .then(res => {
             _this.optionsList = window.toolfun_gettreejson(res.data.items, 'Id', 'ParentId', 'Id,Name')
+            _this.optionsList.forEach((item,index)=>{
+              _this.$set(this.optionsList[index], 'children', [])
+            })
           })
           .catch(err => {
             console.error(err)
           })
       },
 
+      //获取下一级分类
+      getChildrens(val) {
+        let _this = this
+        let Id = val[0]
+        if (Id != _this.flagId) { //判断是否是第一次,若不相等则为第一次
+          this.$axios.get('goodsaptitudeclass/getchildlist/' + Id, {})
+          .then(res => {
+            //获取下一级所有级联数据
+            if (res.data.items) {//判断是否有数据
+              let tempList = []
+              tempList = window.toolfun_gettreejson(res.data.items, 'Id', 'ParentId', 'Id,Name')
+              //添加到上一级对应的选项中
+              for (let i = 0; i < _this.optionsList.length; i++) {
+                if (_this.optionsList[i].id === Id) {
+                  _this.$set(_this.optionsList[i], 'children', tempList)
+                  break
+                }
+              }
+            } else {
+              //修改上一级的children属性
+              for (let i = 0; i < _this.optionsList.length; i++) {
+                if (_this.optionsList[i].id === Id) {
+                  _this.$set(_this.optionsList[i], 'children', '')
+                  break
+                }
+              }
+            }
+            //做标记
+            _this.flagId = Id
+          })
+          .catch(err => {
+            console.error(err)
+          })
+        }
+      },
+
       //获取分类级联Id
       getCode(item) {
         let sortFlagStr = item.toString()
@@ -457,6 +498,32 @@
           }
           _this.selectedOptList = arr2
         }
+        let Id = _this.selectedOptList[0]
+        this.$axios.get('goodsaptitudeclass/getchildlist/' + Id, {})
+          .then(res => {
+            if (res.data.items) {//判断是否有数据
+              let tempList = []
+              tempList = window.toolfun_gettreejson(res.data.items, 'Id', 'ParentId', 'Id,Name')
+              //添加到上一级对应的选项中
+              for (let i = 0; i < _this.optionsList.length; i++) {
+                if (_this.optionsList[i].id === Id) {
+                  _this.$set(_this.optionsList[i], 'children', tempList)
+                  break
+                }
+              }
+            } else {
+              //修改上一级的children属性
+              for (let i = 0; i < _this.optionsList.length; i++) {
+                if (_this.optionsList[i].id === Id) {
+                  _this.$set(_this.optionsList[i], 'children', '')
+                  break
+                }
+              }
+            }
+          })
+          .catch(err => {
+            console.error(err)
+          })
       },
 
       //取消