diff --git a/common/js/request.js b/common/js/request.js index 5e7d74f..0ec28a0 100644 --- a/common/js/request.js +++ b/common/js/request.js @@ -78,6 +78,7 @@ export default { areaRes = areaRes.data; if (areaRes) { let areaArr = [areaRes.provinceArea, areaRes.cityArea, areaRes.countryArea]; + // let areaArr = [areaRes.cityArea, areaRes.countryArea]; let curLocation = { area: areaArr, updateTimes: new Date().getTime() @@ -85,6 +86,19 @@ export default { uni.setStorageSync('curLocation', curLocation); } }, + async storageLocation(res) { + let areaRes = await this.baiduGetLoacation(res.latitude, res.longitude); + areaRes = areaRes.data; + if (areaRes) { + let areaArr = [areaRes.provinceArea, areaRes.cityArea, areaRes.countryArea]; + // let areaArr = [areaRes.cityArea, areaRes.countryArea]; + let curLocation = { + area: areaArr, + updateTimes: new Date().getTime() + } + uni.setStorageSync('curLocation', curLocation); + } + }, async getCurArea() { try{ let curLocation = uni.getStorageSync('curLocation'); diff --git a/manifest.json b/manifest.json index b8061ee..cf66f7b 100644 --- a/manifest.json +++ b/manifest.json @@ -60,6 +60,7 @@ "scope.userLocation" : { "desc" : "因涉及上门家政服务,需获取地理位置" } - } + }, + "requiredPrivateInfos": ["getLocation"] } } diff --git a/pages/index/home.vue b/pages/index/home.vue index 089c57a..e2d9fe5 100644 --- a/pages/index/home.vue +++ b/pages/index/home.vue @@ -27,7 +27,7 @@ - {{searchInfo.area && searchInfo.area.length ? searchInfo.area[2].areaName : areaList[2][0].areaName}} + {{searchInfo.area && searchInfo.area.length ? searchInfo.area[1].areaName : areaList[1][0].areaName}} @@ -116,6 +116,19 @@ + + + + + + 需先授权定位功能才可正常使用功能 + + + 拒绝授权 + + + + @@ -146,13 +159,14 @@ InputBottom: 0, searchInfo: {}, areaList: [], - areaMultiIndex: [0, 0, 0], + areaMultiIndex: [0, 0], productList: [], otherCityProductList: [], pageNum: 0, pageSize: 0, otherCityProductPageNum: 0, - otherCityProductPageSize: 0 + otherCityProductPageSize: 0, + isShowPrivSetting: false } }, mounted() { @@ -162,15 +176,14 @@ this.offBindEvent(); }, async onReady() { - await this.$request.authAndGetLocation(); - await this.loadData(); + // await this.$request.authAndGetLocation(); + // 定位当前城市 + await this.getCurAreaArr(); }, methods: { async loadData() { this.initBasicData(); - // 加载区域信息 - await this.loadRegionList(); - await this.getCurAreaArr(); + // 加载区域信息 await this.loadRegionList(); // 加载服务商城热门类目 let hotServCategoryRes = await this.$request.getHotCategory({ @@ -202,15 +215,85 @@ offBindEvent() { uni.$off('clickCard'); }, - async getCurAreaArr() { - let areaArr = await this.$request.getCurArea(); - if (areaArr) { - this.searchInfo.area = areaArr; + async authLocationCallback(res) { + if (res.detail.authSetting['scope.userLocation']) { + this.isShowPrivSetting = false; + await this.getCurAreaArr(); } - // else { - // // 默认选中第一个 - // this.searchInfo.area = [this.areaList[0][0], this.areaList[1][0], this.areaList[2][0]]; - // } + }, + async wxGetLocation() { + let _this = this; + // 通过 wx.getSetting 先查询一下用户是否授权了authScope + let res1 = await wx.getSetting(); + if (res1) { + if (!res1.authSetting['scope.userLocation']) { + let res2 = await wx.getLocation({ + type: 'gcj02', + fail: async (result) => { + console.log(result) + if (result.errno === 103 || result.errMsg === 'getLocation:fail auth deny') { + this.isShowPrivSetting = true; + } else { + // 用户授权 + uni.showToast({ + title: '请确认是否开启定位', + icon: 'none', + duration: 1500 + }) + } + }, + success: async (result) => { + await _this.$request.storageLocation(result); + let areaArr = await _this.getCurAreaArr(); + if (areaArr) { + _this.searchInfo.area = areaArr; + await _this.loadData(); + } + } + }) + } else { + wx.getLocation({ + type: 'gcj02', + fail: async (result) => { + console.log(result) + if (result.errCode === 2 || result.errCode === 404) { + uni.showToast({ + title: '定位获取失败,请确认是否开启定位', + icon: 'none', + duration: 2500 + }) + } else { + uni.showToast({ + title: '定位获取失败,请稍后重试', + icon: 'none', + duration: 2500 + }) + } + }, + success: async (result) => { + await _this.$request.storageLocation(result); + let areaArr = await _this.getCurAreaArr(); + if (areaArr) { + _this.searchInfo.area = areaArr; + await _this.loadData(); + } + } + }) + } + } + }, + async getCurAreaArr() { + let curLocation = uni.getStorageSync('curLocation'); + if (curLocation && curLocation.updateTimes) { + let curTimes = new Date().getTime(); + let deltaSeconds = curTimes - curLocation.updateTimes; + if (deltaSeconds <= 15 * 60 * 1000) { + this.searchInfo.area = curLocation.area; + this.loadData(); + return; + } + } + await this.wxGetLocation(); }, async loadCategoryList() { let res = await this.$request.getProductCategories(); @@ -244,12 +327,24 @@ subSubRegionList = await this.$request.areaListByStep({ parentCode: subRegionList[0].areaCode }); - subSubRegionList = subSubRegionList.data; + subSubRegionList = subSubRegionList.data; + let allAreaIdsOfSubSubRegionList = []; + subSubRegionList.forEach(region => { + allAreaIdsOfSubSubRegionList.push(region.areaId) + }) + let subSubRegionListWithAll = [{ + areaIds: allAreaIdsOfSubSubRegionList, + areaId: subRegionList[0].areaId, + isAll: true, + areaName: subRegionList[0].areaName + }].concat(subSubRegionList); + subSubRegionList = subSubRegionListWithAll; } this.areaList = []; - this.areaList.push(regionList); + // this.areaList.push(regionList); this.areaList.push(subRegionList); - this.areaList.push(subSubRegionList); + this.areaList.push(subSubRegionList); + this.searchInfo.area = [this.areaList[0][0], this.areaList[1][0]]; }, regionChange(e) { this.areaMultiIndex = e.detail.value; @@ -261,35 +356,35 @@ this.reloadProductPage(); }, async regionColChange(e) { - let colObj = e.detail; - if (colObj.column == 0) { - // 通过一级查二级 - let subAreaList = await this.$request.areaListByStep({ - parentCode: this.areaList[0][colObj.value].areaCode - }); - subAreaList = subAreaList.data; - let subSubAreaList = []; - if (subAreaList.length) { - subSubAreaList = await this.$request.areaListByStep({ - parentCode: subAreaList[0].areaCode - }); - subSubAreaList = subSubAreaList.data; - } - this.areaList.pop(); - this.areaList.pop(); - this.areaList.push(subAreaList); - this.areaList.push(subSubAreaList); - this.areaMultiIndex = [colObj.value, 0, 0]; - } else if (colObj.column == 1) { - // 通过二级查三级 - let subAreaList = await this.$request.areaListByStep({ - parentCode: this.areaList[1][colObj.value].areaCode - }); - subAreaList = subAreaList.data; - this.areaList.pop(); - this.areaList.push(subAreaList); - this.areaMultiIndex = [this.areaMultiIndex[0], colObj.value, 0]; - } + // let colObj = e.detail; + // if (colObj.column == 0) { + // // 通过一级查二级 + // let subAreaList = await this.$request.areaListByStep({ + // parentCode: this.areaList[0][colObj.value].areaCode + // }); + // subAreaList = subAreaList.data; + // let subSubAreaList = []; + // if (subAreaList.length) { + // subSubAreaList = await this.$request.areaListByStep({ + // parentCode: subAreaList[0].areaCode + // }); + // subSubAreaList = subSubAreaList.data; + // } + // this.areaList.pop(); + // this.areaList.pop(); + // this.areaList.push(subAreaList); + // this.areaList.push(subSubAreaList); + // this.areaMultiIndex = [colObj.value, 0, 0]; + // } else if (colObj.column == 1) { + // // 通过二级查三级 + // let subAreaList = await this.$request.areaListByStep({ + // parentCode: this.areaList[1][colObj.value].areaCode + // }); + // subAreaList = subAreaList.data; + // this.areaList.pop(); + // this.areaList.push(subAreaList); + // this.areaMultiIndex = [this.areaMultiIndex[0], colObj.value, 0]; + // } }, async tabSelect(e, item) { this.tabCur = e == null ? 0 : e.currentTarget.dataset.index; @@ -339,8 +434,7 @@ url: '/pages/product/filtered-products?params=' + encodeURIComponent(JSON.stringify(params)) }) }, - clickHotCategory(item) { - console.log(item) + clickHotCategory(item) { let params = { category: item }; @@ -378,6 +472,11 @@ async loadProductPage(params = { areaId: this.searchInfo.area && this.searchInfo.area.length ? this.searchInfo.area[this.searchInfo.area.length - 1].areaId : null }, loadStatusBarRefName = "loadStatusBar1", resContainer = "productList", pageNumName = "pageNum", pageSizeName = "pageSize") { + if (!params.exceptParentAreaId && this.searchInfo.area + && this.searchInfo.area.length && this.searchInfo.area[this.searchInfo.area.length - 1].isAll) { + params.areaIds = this.searchInfo.area[this.searchInfo.area.length - 1].areaIds; + params.areaId = null; + } params.pageNum = this[pageNumName]; params.pageSize = this[pageSizeName]; params.status = 0; diff --git a/pages/index/worker-home.vue b/pages/index/worker-home.vue index 3e7e461..c464365 100644 --- a/pages/index/worker-home.vue +++ b/pages/index/worker-home.vue @@ -11,7 +11,7 @@ - {{searchInfo.area && searchInfo.area.length ? searchInfo.area[2].areaName : areaList[2][0].areaName}} + {{searchInfo.area && searchInfo.area.length ? searchInfo.area[1].areaName : areaList[1][0].areaName}} @@ -208,7 +208,7 @@ stickyTop: this.CustomBar, searchInfo: {}, areaList: [], - areaMultiIndex: [0, 0, 0], + areaMultiIndex: [0, 0], categoryList: [], categoryMultiIndex: [0, 0, 0] } @@ -220,7 +220,6 @@ async loadData() { this.pageNum = this.$globalData.initPageNum; this.pageSize = this.$globalData.initPageSize; - await this.loadRegionList(); // 获取当前定位 await this.getCurAreaArr(); await this.loadRegionList(); @@ -230,9 +229,7 @@ async getCurAreaArr() { let areaArr = await this.$request.getCurArea(); if (areaArr) { - this.searchInfo.area = areaArr; - } else { - this.searchInfo.area = [this.areaList[0][0], this.areaList[1][0], this.areaList[2][0]] + this.searchInfo.area = [areaArr[1], areaArr[2]]; } }, async reloadData(params = {}) { @@ -244,6 +241,10 @@ this.loadOtherCityWorkerPage(); }, async loadWorkerPage(params = {}) { + if (this.searchInfo.area && this.searchInfo.area.length && this.searchInfo.area[this.searchInfo.area.length - 1].isAll) { + params.areaIds = this.searchInfo.area[this.searchInfo.area.length - 1].areaIds; + params.areaId = null; + } params.pageNum = this.pageNum; params.pageSize = this.pageSize; this.$refs.loadStatusBar1.showLoading(); @@ -315,38 +316,50 @@ this.categoryList.push(subSubTypeList); }, async loadRegionList() { - let area = this.searchInfo.area && this.searchInfo.area.length ? this.searchInfo.area : null - let regionList = await this.$request.areaListByStep({ - areaId: area == null ? null : area[0].areaId - }); - regionList = regionList.data; - let subRegionList = []; + // let area = this.searchInfo.area && this.searchInfo.area.length ? this.searchInfo.area : null + // let regionList = await this.$request.areaListByStep({ + // areaId: area == null ? null : area[0].areaId + // }); + // regionList = regionList.data; + let subRegionList = [this.searchInfo.area[0]]; let subSubRegionList = []; - if (regionList && regionList.length > 0) { - let params = {}; - if (area != null) { - params = { - areaId: area[1].areaId, - parentCode: area[0].areaId - } - } else { - params = { - parentCode: regionList[0].areaCode - } - } - subRegionList = await this.$request.areaListByStep(params); - subRegionList = subRegionList.data; - } + // if (regionList && regionList.length > 0) { + // let params = {}; + // if (area != null) { + // params = { + // areaId: area[1].areaId, + // parentCode: area[0].areaId + // } + // } else { + // params = { + // parentCode: regionList[0].areaCode + // } + // } + // subRegionList = await this.$request.areaListByStep(params); + // subRegionList = subRegionList.data; + // } if (subRegionList && subRegionList.length > 0) { subSubRegionList = await this.$request.areaListByStep({ parentCode: subRegionList[0].areaCode }); subSubRegionList = subSubRegionList.data; + let allAreaIdsOfSubSubRegionList = []; + subSubRegionList.forEach(region => { + allAreaIdsOfSubSubRegionList.push(region.areaId) + }) + let subSubRegionListWithAll = [{ + areaIds: allAreaIdsOfSubSubRegionList, + areaId: subRegionList[0].areaId, + isAll: true, + areaName: subRegionList[0].areaName + }].concat(subSubRegionList); + subSubRegionList = subSubRegionListWithAll; } this.areaList = []; - this.areaList.push(regionList); + // this.areaList.push(regionList); this.areaList.push(subRegionList); this.areaList.push(subSubRegionList); + this.searchInfo.area = [this.areaList[0][0], this.areaList[1][0]]; }, regionChange(e) { this.areaMultiIndex = e.detail.value; @@ -358,35 +371,35 @@ this.searchGoods(); }, async regionColChange(e) { - let colObj = e.detail; - if (colObj.column == 0) { - // 通过一级查二级 - let subAreaList = await this.$request.areaListByStep({ - parentCode: this.areaList[0][colObj.value].areaCode - }); - subAreaList = subAreaList.data; - let subSubAreaList = []; - if (subAreaList.length) { - subSubAreaList = await this.$request.areaListByStep({ - parentCode: subAreaList[0].areaCode - }); - subSubAreaList = subSubAreaList.data; - } - this.areaList.pop(); - this.areaList.pop(); - this.areaList.push(subAreaList); - this.areaList.push(subSubAreaList); - this.areaMultiIndex = [colObj.value, 0, 0]; - } else if (colObj.column == 1) { - // 通过二级查三级 - let subAreaList = await this.$request.areaListByStep({ - parentCode: this.areaList[1][colObj.value].areaCode - }); - subAreaList = subAreaList.data; - this.areaList.pop(); - this.areaList.push(subAreaList); - this.areaMultiIndex = [this.areaMultiIndex[0], colObj.value, 0]; - } + // let colObj = e.detail; + // if (colObj.column == 0) { + // // 通过一级查二级 + // let subAreaList = await this.$request.areaListByStep({ + // parentCode: this.areaList[0][colObj.value].areaCode + // }); + // subAreaList = subAreaList.data; + // let subSubAreaList = []; + // if (subAreaList.length) { + // subSubAreaList = await this.$request.areaListByStep({ + // parentCode: subAreaList[0].areaCode + // }); + // subSubAreaList = subSubAreaList.data; + // } + // this.areaList.pop(); + // this.areaList.pop(); + // this.areaList.push(subAreaList); + // this.areaList.push(subSubAreaList); + // this.areaMultiIndex = [colObj.value, 0, 0]; + // } else if (colObj.column == 1) { + // // 通过二级查三级 + // let subAreaList = await this.$request.areaListByStep({ + // parentCode: this.areaList[1][colObj.value].areaCode + // }); + // subAreaList = subAreaList.data; + // this.areaList.pop(); + // this.areaList.push(subAreaList); + // this.areaMultiIndex = [this.areaMultiIndex[0], colObj.value, 0]; + // } }, async categoryChange(e) { this.categoryMultiIndex = e.detail.value; @@ -450,9 +463,11 @@ searchGoods() { let params = { goodsCategoryId: this.searchInfo.category && this.searchInfo.category.length > 1 ? this.searchInfo.category[2].goodsCategoryId : null, - areaId: this.searchInfo.area[2].areaId, workerName: this.searchInfo.inputWorkerName }; + if (this.searchInfo.area && this.searchInfo.area.length) { + params.areaId = this.searchInfo.area[this.searchInfo.area.length - 1].areaId; + } this.reloadData(params); }, showShopDetail(shopInfo) { diff --git a/pages/product/filtered-products.vue b/pages/product/filtered-products.vue index 6fc3c97..6230a7c 100644 --- a/pages/product/filtered-products.vue +++ b/pages/product/filtered-products.vue @@ -23,7 +23,7 @@ :value="areaMultiIndex" :range-key="'areaName'" :range="areaList"> - {{chosenArea && chosenArea.length ? chosenArea[2].areaName : item.title}} + {{chosenArea && chosenArea.length ? chosenArea[chosenArea.length - 1].areaName : item.title}} @@ -140,7 +140,7 @@ }], inputGoodsName: null, areaList: [], - areaMultiIndex: [0, 0, 0], + areaMultiIndex: [0, 0], chosenArea: [], categoryList: [], categoryMultiIndex: [0, 0, 0], @@ -159,7 +159,7 @@ } if (params.area) { this.chosenArea = params.area; - this.taskConditions[0].value = this.chosenArea[2].areaId; + this.taskConditions[0].value = this.chosenArea[this.chosenArea.length - 1].areaId; } if (params.inputGoodsName) { this.inputGoodsName = params.inputGoodsName; @@ -170,17 +170,17 @@ async loadData() { this.pageNum = this.$globalData.initPageNum; this.pageSize = this.$globalData.initPageSize; - this.loadCategoryList(); - this.loadRegionList(); + this.loadCategoryList(); // 获取当前定位 - await this.getCurAreaArr(); + await this.getCurAreaArr(); + await this.loadRegionList(); this.loadProductData(); }, async getCurAreaArr() { let areaArr = await this.$request.getCurArea(); if (areaArr) { - this.chosenArea = areaArr; - this.taskConditions[0].value = this.chosenArea[2].areaId; + this.chosenArea = [areaArr[1], areaArr[2]]; + this.taskConditions[0].value = this.chosenArea[this.chosenArea.length - 1].areaId; } }, async loadProductData(params = {}) { @@ -195,7 +195,11 @@ params.params = params.params ? params.params : {}; params.params[condition.code] = condition.value === 1 ? 'desc' : 'asc'; } - }) + }) + if (this.chosenArea[this.chosenArea.length - 1].isAll) { + params.areaId = null; + params.areaIds = this.chosenArea[this.chosenArea.length - 1].areaIds; + } this.loadMoreStatus = 'loading bg-main-color light'; this.hasMoreData = false; try { @@ -256,25 +260,38 @@ this.categoryList.push(subSubTypeList); }, async loadRegionList() { - let regionList = await this.$request.areaListByStep(); - regionList = regionList.data; - let subRegionList = []; + // let regionList = await this.$request.areaListByStep(); + // regionList = regionList.data; + let subRegionList = [this.chosenArea[0]]; let subSubRegionList = []; - if (regionList && regionList.length > 0) { - subRegionList = await this.$request.areaListByStep({ - parentCode: regionList[0].areaCode - }); - subRegionList = subRegionList.data; - } + // if (regionList && regionList.length > 0) { + // subRegionList = await this.$request.areaListByStep({ + // parentCode: regionList[0].areaCode + // }); + // subRegionList = subRegionList.data; + // } if (subRegionList && subRegionList.length > 0) { - subSubRegionList = await this.$request.areaListByStep({ - parentCode: subRegionList[0].areaCode - }); - subSubRegionList = subSubRegionList.data; + subSubRegionList = await this.$request.areaListByStep({ + parentCode: subRegionList[0].areaCode + }); + subSubRegionList = subSubRegionList.data; + let allAreaIdsOfSubSubRegionList = []; + subSubRegionList.forEach(region => { + allAreaIdsOfSubSubRegionList.push(region.areaId) + }) + let subSubRegionListWithAll = [{ + areaIds: allAreaIdsOfSubSubRegionList, + areaId: subRegionList[0].areaId, + isAll: true, + areaName: subRegionList[0].areaName + }].concat(subSubRegionList); + subSubRegionList = subSubRegionListWithAll; } - this.areaList.push(regionList); + // this.areaList.push(regionList); this.areaList.push(subRegionList); - this.areaList.push(subSubRegionList); + this.areaList.push(subSubRegionList); + this.chosenArea = [this.areaList[0][0], this.areaList[1][0]]; + this.taskConditions[0].value = this.chosenArea[this.chosenArea.length - 1].areaId; }, searchGoods() { this.reloadProductPage(); @@ -323,29 +340,29 @@ this.searchGoods(); }, async regionColChange(e) { - let colObj = e.detail; - if (colObj.column == 0) { - // 通过一级查二级 - let subAreaList = await this.$request.areaListByStep({parentCode: this.areaList[0][colObj.value].areaCode}); - subAreaList = subAreaList.data; - let subSubAreaList = []; - if (subAreaList.length) { - subSubAreaList = await this.$request.areaListByStep({parentCode: subAreaList[0].areaCode}); - subSubAreaList = subSubAreaList.data; - } - this.areaList.pop(); - this.areaList.pop(); - this.areaList.push(subAreaList); - this.areaList.push(subSubAreaList); - this.areaMultiIndex = [colObj.value, 0, 0]; - } else if (colObj.column == 1) { - // 通过二级查三级 - let subAreaList = await this.$request.areaListByStep({parentCode: this.areaList[1][colObj.value].areaCode}); - subAreaList = subAreaList.data; - this.areaList.pop(); - this.areaList.push(subAreaList); - this.areaMultiIndex = [this.areaMultiIndex[0], colObj.value, 0]; - } + // let colObj = e.detail; + // if (colObj.column == 0) { + // // 通过一级查二级 + // let subAreaList = await this.$request.areaListByStep({parentCode: this.areaList[0][colObj.value].areaCode}); + // subAreaList = subAreaList.data; + // let subSubAreaList = []; + // if (subAreaList.length) { + // subSubAreaList = await this.$request.areaListByStep({parentCode: subAreaList[0].areaCode}); + // subSubAreaList = subSubAreaList.data; + // } + // this.areaList.pop(); + // this.areaList.pop(); + // this.areaList.push(subAreaList); + // this.areaList.push(subSubAreaList); + // this.areaMultiIndex = [colObj.value, 0, 0]; + // } else if (colObj.column == 1) { + // // 通过二级查三级 + // let subAreaList = await this.$request.areaListByStep({parentCode: this.areaList[1][colObj.value].areaCode}); + // subAreaList = subAreaList.data; + // this.areaList.pop(); + // this.areaList.push(subAreaList); + // this.areaMultiIndex = [this.areaMultiIndex[0], colObj.value, 0]; + // } }, async categoryChange(e) { this.categoryMultiIndex = e.detail.value; diff --git a/pages/product/shop-detail.vue b/pages/product/shop-detail.vue index d0d8492..6a565fd 100644 --- a/pages/product/shop-detail.vue +++ b/pages/product/shop-detail.vue @@ -11,7 +11,7 @@ - + {{shopInfo.name}} @@ -77,7 +77,7 @@ - {{searchInfo.area && searchInfo.area.length ? searchInfo.area[2].areaName : areaList[2][0].areaName}} + {{searchInfo.area && searchInfo.area.length ? searchInfo.area[1].areaName : areaList[1][0].areaName}} @@ -127,7 +127,7 @@ }], searchInfo: {}, areaList: [], - areaMultiIndex: [0, 0, 0], + areaMultiIndex: [0, 0], categoryList: [], stickyTop: this.CustomBar } @@ -144,17 +144,15 @@ }) this.shopInfo = res.data; this.loadCategoryList(); - await this.loadRegionList(); // 获取当前定位 await this.getCurAreaArr(); + await this.loadRegionList(); this.searchGoods(); }, async getCurAreaArr() { let areaArr = await this.$request.getCurArea(); if (areaArr) { - this.searchInfo.area = areaArr; - } else { - this.searchInfo.area = [this.areaList[0][0], this.areaList[1][0], this.areaList[2][0]]; + this.searchInfo.area = [areaArr[1], areaArr[2]]; } }, async loadProductData(params = {}) { @@ -162,6 +160,10 @@ status: 0, ...params } + if (this.searchInfo.area[this.searchInfo.area.length - 1].isAll) { + params.areaId = null; + params.areaIds = this.searchInfo.area[this.searchInfo.area.length - 1].areaIds; + } let res = await this.$request.qryProductPage(params); this.productList = res[1].data.rows; }, @@ -183,25 +185,37 @@ this.categoryList.push(subSubTypeList); }, async loadRegionList() { - let regionList = await this.$request.areaListByStep(); - regionList = regionList.data; - let subRegionList = []; + // let regionList = await this.$request.areaListByStep(); + // regionList = regionList.data; + let subRegionList = [this.searchInfo.area[0]]; let subSubRegionList = []; - if (regionList && regionList.length > 0) { - subRegionList = await this.$request.areaListByStep({ - parentCode: regionList[0].areaCode - }); - subRegionList = subRegionList.data; - } + // if (regionList && regionList.length > 0) { + // subRegionList = await this.$request.areaListByStep({ + // parentCode: regionList[0].areaCode + // }); + // subRegionList = subRegionList.data; + // } if (subRegionList && subRegionList.length > 0) { subSubRegionList = await this.$request.areaListByStep({ parentCode: subRegionList[0].areaCode }); subSubRegionList = subSubRegionList.data; + let allAreaIdsOfSubSubRegionList = []; + subSubRegionList.forEach(region => { + allAreaIdsOfSubSubRegionList.push(region.areaId) + }) + let subSubRegionListWithAll = [{ + areaIds: allAreaIdsOfSubSubRegionList, + areaId: subRegionList[0].areaId, + isAll: true, + areaName: subRegionList[0].areaName + }].concat(subSubRegionList); + subSubRegionList = subSubRegionListWithAll; } - this.areaList.push(regionList); + // this.areaList.push(regionList); this.areaList.push(subRegionList); this.areaList.push(subSubRegionList); + this.searchInfo.area = [this.areaList[0][0], this.areaList[1][0]]; }, regionChange(e) { this.areaMultiIndex = e.detail.value; @@ -213,39 +227,39 @@ this.searchGoods(); }, async regionColChange(e) { - let colObj = e.detail; - if (colObj.column == 0) { - // 通过一级查二级 - let subAreaList = await this.$request.areaListByStep({ - parentCode: this.areaList[0][colObj.value].areaCode - }); - subAreaList = subAreaList.data; - let subSubAreaList = []; - if (subAreaList.length) { - subSubAreaList = await this.$request.areaListByStep({ - parentCode: subAreaList[0].areaCode - }); - subSubAreaList = subSubAreaList.data; - } - this.areaList.pop(); - this.areaList.pop(); - this.areaList.push(subAreaList); - this.areaList.push(subSubAreaList); - this.areaMultiIndex = [colObj.value, 0, 0]; - } else if (colObj.column == 1) { - // 通过二级查三级 - let subAreaList = await this.$request.areaListByStep({ - parentCode: this.areaList[1][colObj.value].areaCode - }); - subAreaList = subAreaList.data; - this.areaList.pop(); - this.areaList.push(subAreaList); - this.areaMultiIndex = [this.areaMultiIndex[0], colObj.value, 0]; - } + // let colObj = e.detail; + // if (colObj.column == 0) { + // // 通过一级查二级 + // let subAreaList = await this.$request.areaListByStep({ + // parentCode: this.areaList[0][colObj.value].areaCode + // }); + // subAreaList = subAreaList.data; + // let subSubAreaList = []; + // if (subAreaList.length) { + // subSubAreaList = await this.$request.areaListByStep({ + // parentCode: subAreaList[0].areaCode + // }); + // subSubAreaList = subSubAreaList.data; + // } + // this.areaList.pop(); + // this.areaList.pop(); + // this.areaList.push(subAreaList); + // this.areaList.push(subSubAreaList); + // this.areaMultiIndex = [colObj.value, 0, 0]; + // } else if (colObj.column == 1) { + // // 通过二级查三级 + // let subAreaList = await this.$request.areaListByStep({ + // parentCode: this.areaList[1][colObj.value].areaCode + // }); + // subAreaList = subAreaList.data; + // this.areaList.pop(); + // this.areaList.push(subAreaList); + // this.areaMultiIndex = [this.areaMultiIndex[0], colObj.value, 0]; + // } }, searchGoods() { let params = { - areaId: this.searchInfo.area[2].areaId, + areaId: this.searchInfo.area[this.searchInfo.area.length - 1].areaId, goodsName: this.searchInfo.goodsName, workerId: this.shopInfo.workerId }; @@ -267,6 +281,8 @@ } -