...
|
...
|
@@ -39,11 +39,18 @@ export default { |
|
|
return {
|
|
|
chosenVal: '',
|
|
|
show: false,
|
|
|
chosen: {},
|
|
|
chosen: [],
|
|
|
choiceName: '品牌',
|
|
|
showMore: false,
|
|
|
allChoices: [],
|
|
|
initialChoices: []
|
|
|
initialChoices: [],
|
|
|
gsFilter: null,
|
|
|
secondSort: []
|
|
|
}
|
|
|
},
|
|
|
computed: {
|
|
|
isGs() {
|
|
|
return typeMap[this.name] === 'group_sort';
|
|
|
}
|
|
|
},
|
|
|
methods: {
|
...
|
...
|
@@ -56,15 +63,54 @@ export default { |
|
|
bus.$emit('expand.choice.only', this.name);
|
|
|
},
|
|
|
toggleChoice(index, choice) {
|
|
|
choice.isChosen = !choice.isChosen;
|
|
|
let change;
|
|
|
|
|
|
this.isGs && this.delSecondSort();
|
|
|
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.splice(index, 1, change);
|
|
|
|
|
|
if (!change.isChosen) {
|
|
|
let id1, id2;
|
|
|
|
|
|
!choice.isChosen && (delete this.chosen[index]);
|
|
|
choice.isChosen && (this.chosen[index] = choice);
|
|
|
_.each(this.chosen, (ch, idx) => {
|
|
|
id1 = this.isGs ? ch.relation_parameter.sort : ch.id;
|
|
|
id2 = this.isGs ? choice.relation_parameter.sort : choice.id;
|
|
|
|
|
|
this.calcChosenVal();
|
|
|
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);
|
|
|
},
|
|
|
calcChosenVal() {
|
|
|
delSecondSort(){
|
|
|
if (this.chosen.length && this.secondSort.length) { // 选择三级分类时排除所有二级分类
|
|
|
_.each(this.chosen, (item, index) => {
|
|
|
if (this.secondSort.indexOf(item.relation_parameter.sort.replace(/,$/, '')) > -1) {
|
|
|
this.chosen.splice(index, 1);
|
|
|
}
|
|
|
});
|
|
|
this.calcChosenStr();
|
|
|
}
|
|
|
},
|
|
|
calcChosenStr(){
|
|
|
let name;
|
|
|
let names = [];
|
|
|
let keys = Object.keys(this.chosen);
|
...
|
...
|
@@ -96,10 +142,10 @@ export default { |
|
|
},
|
|
|
clearChosenVal(){
|
|
|
this.show = false;
|
|
|
this.chosen = {};
|
|
|
this.chosen = [];
|
|
|
this.chosenVal = '';
|
|
|
this.allChoices = this.initialChoices.slice();
|
|
|
bus.$emit('subChosen.change', this.name, this.chosen);
|
|
|
bus.$emit('subChosen.change', typeMap[this.name], this.chosen);
|
|
|
},
|
|
|
searchChosenVal() {
|
|
|
this.show = false;
|
...
|
...
|
@@ -107,29 +153,78 @@ export default { |
|
|
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;
|
|
|
|
|
|
if (sub.value && sub.value.length) {
|
|
|
this.allChoices = this.initialChoices.slice();
|
|
|
if (!len) {
|
|
|
this.chosen = [];
|
|
|
this.chosenVal = '';
|
|
|
} else {
|
|
|
const gs = sub.subType === 'group_sort';
|
|
|
|
|
|
_.each(sub.value, item => {
|
|
|
// 所有品类信息
|
|
|
// 用于选择三级分类的时候清除非三级分类
|
|
|
if (gs && !this.gsFilter) {
|
|
|
this.calcSecondSort(filter);
|
|
|
}
|
|
|
|
|
|
this.chosen = [];
|
|
|
this.allChoices = this.initialChoices.slice();
|
|
|
_.each(sub.value, (item, index) => {
|
|
|
names.push(item.name);
|
|
|
|
|
|
_.each(this.allChoices, (choice, index) => {
|
|
|
const isSort = this.name === '品类';
|
|
|
const id = isSort ? choice.category_id : choice.id;
|
|
|
const id = gs ?
|
|
|
choice.relation_parameter.sort :
|
|
|
choice.id;
|
|
|
|
|
|
if (item.id === id) {
|
|
|
choice.isChosen = !choice.isChosen;
|
|
|
this.chosen[index] = choice;
|
|
|
let chosen = {};
|
|
|
|
|
|
if (gs) {
|
|
|
chosen = {
|
|
|
isChosen: true,
|
|
|
category_name: item.name,
|
|
|
relation_parameter: choice.relation_parameter
|
|
|
};
|
|
|
} else {
|
|
|
chosen = {
|
|
|
id: choice.id,
|
|
|
name: choice.name,
|
|
|
isChosen: true
|
|
|
};
|
|
|
}
|
|
|
|
|
|
this.allChoices.splice(index, 1, chosen);
|
|
|
}
|
|
|
});
|
|
|
|
|
|
if (gs) {
|
|
|
item.relation_parameter = {
|
|
|
sort: item.id
|
|
|
};
|
|
|
item.category_name = item.name;
|
|
|
}
|
|
|
|
|
|
this.chosen.push(item);
|
|
|
});
|
|
|
this.show = false;
|
|
|
this.chosenVal = names.join(',');
|
|
|
}
|
|
|
|
|
|
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(){
|
...
|
...
|
|