diff --git a/mallplusui-uniapp-app/common/api.js b/mallplusui-uniapp-app/common/api.js index 66af339..83150a2 100644 --- a/mallplusui-uniapp-app/common/api.js +++ b/mallplusui-uniapp-app/common/api.js @@ -1,7 +1,7 @@ import store from '../store/index'; export default { // qq 237524947 wx15d4269d3210863d - BASEURI: 'http://192.168.3.9:8111/api/', + BASEURI: 'http://192.168.3.9:8083/api/', // BASEURI: 'http://mall.yyundong.com/portalapi/api/', // BASEURI: 'http://192.168.31.52:8083/api/', ADMINURI: 'http://mall.yyundong.com/adminapi/', diff --git a/mallplusui-uniapp-app/pages/category/category.vue b/mallplusui-uniapp-app/pages/category/category.vue index 885bc4a..177adaf 100644 --- a/mallplusui-uniapp-app/pages/category/category.vue +++ b/mallplusui-uniapp-app/pages/category/category.vue @@ -57,6 +57,7 @@ sizeCalcState: false, tabScrollTop: 0, currentId: 1, + list: [], flist: [], slist: [], tlist: [], @@ -75,27 +76,67 @@ async loadData() { // let list = this.$db.get('categoryList') - let list=[] - this.flist =[] - this.tlist = [] + this.flist = [] + this.slist = [] + this.tlist = [] // if (!list) { - let params = {}; - list = await Api.apiCall('get', Api.goods.typeGoodsList, params); - console.log("list>>>>>", list); - this.$db.set('categoryList', list) + let params = {}; + this.list = await Api.apiCall('get', Api.goods.typeGoodsList, params); + console.log("list>>>>>", this.list); + this.$db.set('categoryList', this.list) // } - if (list) { - list.forEach(item => { + if (this.list) { - if (item.level == 0) { - this.flist.push(item); //pid为父级id, 没有pid或者pid=0是一级分类 - } else if (item.level == 1) { - this.slist.push(item); //没有价格的是2级分类 - } else { - this.tlist.push(item); //3级分类 + // 一级分类 + this.flist = this.list.filter((item) => item.level == 0) + console.log("flist", this.flist.length) + console.log("flist", this.flist) + const pid = this.flist[0].id + this.currentId = pid + + // 二级分类 + let list2 = this.list.filter((item) => item.level == 1) + + for (var j = 0; j < list2.length; j++) { + const pid2 = list2[j].pid + if (pid2 == pid) { + this.slist.push(list2[j]) + } + } + + console.log("this.slist", this.slist) + + // 三级分类 + let list3 = this.list.filter((item) => item.level == 2) + + for (var i = 0; i < this.slist.length; i++) { + const pid2 = this.slist[i].id + for (var j = 0; j < list3.length; j++) { + const pid3 = list3[j].pid + if (pid3 == pid2) { + this.tlist.push(list3[j]) + } } - }); + + } + console.log("this.tlist", this.tlist) + + // // 三级分类 + // this.tlist = slist.filter((item) => item.level == 2) + + + + // list.forEach(item => { + + // if (item.level == 0) { + // this.flist.push(item); //pid为父级id, 没有pid或者pid=0是一级分类 + // } else if (item.level == 1) { + // this.slist.push(item); //没有价格的是2级分类 + // } else { + // this.tlist.push(item); //3级分类 + // } + // }); } }, @@ -106,7 +147,37 @@ } this.currentId = item.id; - console.log(item.id); + this.slist = [] + this.tlist = [] + + // 二级分类 + let list2 = this.list.filter((item) => item.level == 1) + + for (var j = 0; j < list2.length; j++) { + const pid2 = list2[j].pid + if (pid2 == this.currentId) { + this.slist.push(list2[j]) + } + } + + console.log("this.slist", this.slist) + + // 三级分类 + let list3 = this.list.filter((item) => item.level == 2) + + for (var i = 0; i < this.slist.length; i++) { + const pid2 = this.slist[i].id + for (var j = 0; j < list3.length; j++) { + const pid3 = list3[j].pid + if (pid3 == pid2) { + this.tlist.push(list3[j]) + } + } + + } + console.log("this.tlist", this.tlist) + + let index = this.slist.findIndex(sitem => sitem.pid === item.id); if (index >= 0) { this.tabScrollTop = this.slist[index].top;