点击按钮选中,再点击其他按钮也都选中的业务需求
<p class="one-button" @click="commentFetch2(2,'pr2','productStatus','pr1','pr2','pr3','pr4','ProductStatus2')"></p>
首先注意的是这个数组只能接受四个数字,1,2,3,4. 所以我们首先对数据去重,然后取消点击的时候删除此时的数据,
let commentFetch2 = (key, value, type, val1, val2, val3, val4, istype) => {
state.params[type].push(key);
state.params[type] = [...new Set(state.params[type])];
if (value == val1) {
state[istype] = !state[istype];
if (state[istype] === true) {
state.assetLists = [];
fetchData();
} else {
state.params[type].splice(state.params[type].findIndex(item => item === key), 1);
fetchData();
}
}
if (value == val2) {
state[istype] = !state[istype];
if (state[istype] === true) {
state.assetLists = [];
fetchData();
} else {
state.params[type].splice(state.params[type].findIndex(item => item === key), 1);
fetchData();
}
}
if (value == val3) {
state[istype] = !state[istype];
if (state[istype] === true) {
state.assetLists = [];
fetchData();
} else {
state.params[type].splice(state.params[type].findIndex(item => item === key), 1);
fetchData();
}
}
if (value == val4) {
state[istype] = !state[istype];
if (state[istype] === true) {
state.assetLists = [];
fetchData();
} else {
state.params[type].splice(state.params[type].findIndex(item => item === key), 1);
fetchData();
}
}
};