Authored by 李奇

筛选修改

... ... @@ -38,11 +38,19 @@ module.exports = {
return {
chosenVal: '',
show: false,
chosen: {},
chosen: [],
choiceName: '品牌',
showMore: false,
allChoices: [],
initialChoices: []
initialChoices: [],
isGs: '',
gsFilter: null,
secondSort: []
}
},
computed: {
isGs() {
return typeMap[this.name] === 'group_sort';
}
},
methods: {
... ... @@ -55,21 +63,53 @@ module.exports = {
bus.$emit('expand.choice.only', this.name);
},
toggleChoice(index, choice) {
const newChoice = {
id: choice.id,
name: choice.name,
isChosen: !choice.isChosen,
category_name: choice.category_name,
relation_parameter: choice.relation_parameter
};
this.allChoices.$set(index, newChoice);
!newChoice.isChosen && (delete this.chosen[index]);
newChoice.isChosen && (this.chosen[index] = newChoice);
let change;
this.isGs && this.delSecondSort(choice);
if (this.isGs) {
change = {
isChosen: !choice.isChosen,
category_name: choice.category_name,
relation_parameter: choice.relation_parameter
};
} else {
change = {
id: choice.id,
name: choice.name,
isChosen: !choice.isChosen
};
}
this.allChoices.$set(index, change);
if (!change.isChosen) {
let id1, id2;
_.each(this.chosen, (ch, idx) => {
id1 = this.isGs ? ch.relation_parameter.sort : ch.id;
id2 = this.isGs ? choice.relation_parameter.sort : choice.id;
if (id1 === id2) {
this.chosen.splice(idx, 1);
return false;
}
});
} else {
this.chosen.push(change);
}
this.calcChosenStr();
bus.$emit('subChosen.change', typeMap[this.name], this.chosen);
},
delSecondSort(){
if (this.chosen.length && this.secondSort.length) { // 选择三级分类时排除所有二级分类
_.each(this.chosen, (item, index) => {
if (this.secondSort.indexOf(item.relation_parameter.sort) > -1) {
this.chosen = this.chosen.splice(index, 1);
}
});
}
},
calcChosenStr(){
let name;
let names = [];
... ... @@ -113,7 +153,7 @@ module.exports = {
foldExcept(name) {
this.show = this.name === name;
},
subFilterChange(sub){
subFilterChange(sub, filter){
if (typeMap[this.name] === sub.subType) {
let names = [];
const len = sub.value.length;
... ... @@ -124,6 +164,12 @@ module.exports = {
} else {
const gs = sub.subType === 'group_sort';
// 所有品类信息
// 用于选择三级分类的时候清除非三级分类
if (gs && !this.gsFilter) {
this.calcSecondSort(filter);
}
this.chosen = [];
this.allChoices = this.initialChoices.slice();
_.each(sub.value, (item, index) => {
... ... @@ -162,7 +208,7 @@ module.exports = {
item.category_name = item.name;
}
this.chosen[index] = item;
this.chosen.push(item);
});
this.chosenVal = names.join(',');
}
... ... @@ -170,6 +216,15 @@ module.exports = {
this.show = false;
bus.$emit('subChosen.change', typeMap[this.name], this.chosen);
}
},
calcSecondSort(filter){
_.each(filter, item => {
let idArr = [];
_.each(item.sub, subItm => {
idArr.push(subItm.relation_parameter.sort);
});
this.secondSort.push(idArr.join(','));
});
}
},
created(){
... ...
... ... @@ -230,9 +230,16 @@ module.exports = {
this.$refs.filterSub.isVisible = true;
},
subFilterChange(sub){
bus.$emit('subFilter.change', sub);
let filter = {};
if (sub.subType === 'group_sort') {
filter = this.filter['group_sort'];
}
bus.$emit('subFilter.change', sub, filter);
},
subChosenChange(name, chosen) {
let keyArr = Object.keys(chosen);
if (keyArr.length) {
... ...