diff --git a/pages/news3/components/category.vue b/pages/news3/components/category.vue index 07d9945..8a542bf 100644 --- a/pages/news3/components/category.vue +++ b/pages/news3/components/category.vue @@ -19,7 +19,7 @@ - {{ item.name }}2 + {{ item.name }} @@ -28,9 +28,9 @@ - + 确定 @@ -59,15 +59,8 @@ this.activeIndex = [] }, getShop(item, category_id) { - console.log(category_id,this.activeIndex) - if (uni.getStorageSync('list').indexOf(category_id) > -1) { - - if(this.activeIndex.indexOf(category_id)!==-1){ - console.log(this.activeIndex.indexOf(category_id)!==-1) - let index=this.activeIndex.indexOf(category_id); - this.activeIndex.splice(index, 1); // 通过索引位置删除元素 - } - // return this.$toast('此分类已被设置规则') + if (uni.getStorageSync('beyondList').indexOf(category_id) > -1) { + return this.$toast('此分类已被其他分类模板设置规则') } let arrIndex = this.activeIndex.indexOf(category_id) if (arrIndex > -1) { @@ -75,7 +68,6 @@ } else { this.activeIndex.push(category_id) } - console.log(this.activeIndex) }, findElementsById(arr, ids) { console.log(ids) @@ -95,13 +87,14 @@ submit() { let idList = [] idList = this.findElementsById(this.tabList, this.activeIndex); - let storage = uni.getStorageSync('list') || [] + let storage = uni.getStorageSync('beyondList') || [] + console.log(idList, storage) if (storage.length > 0 && idList.length > 0) { idList = this.getArrDifference(idList, storage) } console.log(idList) this.$emit('getChoseCategory', { - category_id: idList||[], + category_id: idList || [], }) }, getArrDifference(arr1, arr2) { @@ -140,7 +133,7 @@ } .submit { - width: 216upx; + width: 416upx; height: 70upx; background: linear-gradient(180deg, #FD5D06 0%, #F3211A 100%); border-radius: 50px 50px 50px 50px; diff --git a/pages/news3/vipPrice.vue b/pages/news3/vipPrice.vue index 9279fb8..01da63b 100644 --- a/pages/news3/vipPrice.vue +++ b/pages/news3/vipPrice.vue @@ -109,8 +109,12 @@ if (status == 200) { if (data.list.length > 0) { data.list.forEach((item_1, index_1) => { - let name = this.findElementsById(this.categoryList, item_1.category.split(",").map( - item => Number(item))) + if (typeof item_1.category == 'string') { + item_1.category = item_1.category.split(",").map(item => Number(item)) + } else { + item_1.category = [item_1.category] + } + let name = this.findElementsById(this.categoryList,item_1.category) item_1.category_name = name.join(',') + (name.length > 0 ? '等' : ''); item_1.price_list.forEach((item_2, index_2) => { item_2.startProfit = Number((Number(item_2.min) * (Number(item_2 @@ -284,6 +288,28 @@ } item.price_list.pop() }, + // 对比数组中取不同的 + mergeArrays(arr1, arr2) { + // 创建一个空数组存放结果 + let mergedArr = []; + // 遍历第一个数组 + for (let i = 0; i < arr1.length; i++) { + if (!arr2.includes(arr1[i])) { + // 如果第二个数组没有包含当前元素,则将其添加到结果数组中 + mergedArr.push(arr1[i]); + } + } + + // 再次遍历第二个数组 + for (let j = 0; j < arr2.length; j++) { + if (!arr1.includes(arr2[j]) && !mergedArr.includes(arr2[j])) { + // 如果第一个数组也没有包含该元素且结果数组中还未包含该元素,则将其添加到结果数组中 + mergedArr.push(arr2[j]); + } + } + + return mergedArr; + }, // 选择分类 onCategory(categoryId, index) { let newId = [] @@ -291,12 +317,19 @@ this.activeIndex = []; this.list.forEach((item, index) => { if (item.category) { - newId = newId.concat((item.category.split(",").map(item => Number(item)))) + newId = newId.concat(item.category) } }) - let list = Array.from(new Set(newId)); + let list = Array.from(new Set(newId)); //所有以选中的 + // 找到除了当前分类的id集合 + let currentList = []; + if (this.list[index].category) { + currentList = this.list[index].category + } + if (currentList.length > 0 && list.length > 0) { + uni.setStorageSync('beyondList', this.mergeArrays(list, currentList)) + } this.activeIndex = list - uni.setStorageSync('list', list) this.$refs.category.afterSale = true; }, findElementsById(arr, ids) { @@ -316,14 +349,9 @@ // 获取分类 getChoseCategory(res) { let nameList = []; - let list = []; - if (this.list[this.categoryIndex].category) { - list = this.list[this.categoryIndex].category.split(",").map(item => Number(item)) - } - let newList = list.concat(res.category_id); - nameList = this.findElementsById(this.categoryList, newList); + nameList = this.findElementsById(this.categoryList, res.category_id); this.list[this.categoryIndex].category_name = nameList.join(',') + (nameList.length > 0 ? '等' : ''); - this.list[this.categoryIndex].category = newList.join(',') + this.list[this.categoryIndex].category = res.category_id.join(',') this.$refs.category.afterSale = false; }, // 新增分类