//对比数据
let list = [{
type: "default",
spec_array: null,
pths_supply_price: '11.8',
ptbhs_supply_price: '11.8',
pt_fee: "0.00",
ylhs_supply_price: "14.50",
ylbhs_supply_price: "13.50",
yl_fee: "0.00",
elhs_supply_price: "15.30",
elbhs_supply_price: "14.50",
el_fee: "0.00",
pchs_price: "0.00",
pcbhs_price: "0.00",
ylpchs_price: "0.00",
ylpcbhs_price: "0.00",
elpchs_price: "0.00",
elpcbhs_price: "0.00",
tmall_price: "0.00",
jd_price: "0.00",
lowest_price: "0",
hasoption: "0",
create_time: "2020-09-07 10:10:45",
carName: "居家日用 家庭清洁 ",
seller_name: "福建省洁柔日化用品商贸有限公司",
commend: [{
id: "15",
name: "茶叶",
type: "3",
icon: "upload/20200911/20200911105820445.jpg"
},
{
id: "12",
name: "网红直播",
type: "0",
icon: "upload/20200911/20200911105820445.jpg"
}
]
},
{
ylhs_supply_price: "14.50",
ylbhs_supply_price: "13.50",
yl_fee: "0.00",
elhs_supply_price: "15.30",
elbhs_supply_price: "14.50",
el_fee: "0.00",
pchs_price: "0.00",
pcbhs_price: "0.00",
ylpchs_price: "0.00",
ylpcbhs_price: "0.00",
elpchs_price: "0.00",
elpcbhs_price: "0.00",
tmall_price: "0.00",
jd_price: "0.00",
lowest_price: "0",
hasoption: "0",
create_time: "2020-09-07 10:10:45",
carName: "居家日用 家庭清洁 ",
seller_name: "福建省洁柔日化用品商贸有限公司",
commend: [{
id: "12",
name: "网红直播",
type: "0",
icon: "upload/20200911/20200911105820445.jpg"
}]
}
]
//对比数据
let tableList = [
{
id: "10",
name: "新品推荐",
status: "1",
default: "0",
type: "1",
icon: "upload/20201029/20201029092322290.jpg"
},
{
id: "12",
name: "网红直播",
status: "1",
default: "0",
type: "0",
icon: "upload/20200911/20200911105820445.jpg"
},
{
id: "14",
name: "9.9",
status: "0",
default: "0",
type: "3",
icon: "upload/20201029/20201029092322290.jpg"
},
{
id: "15",
name: "茶叶",
status: "1",
default: "0",
type: "3",
icon: "upload/20200911/20200911105820445.jpg"
},
{
id: "16",
name: "电脑",
status: "1",
default: "1",
type: "2",
icon: "upload/20201029/20201029092322290.jpg"
}
]
methods: {
getlist(){
let timeStamp = new Date().getTime();
this.list.forEach((i, index) => {
i.oneArr = [];
i.twoArr = [];
if (i.commend) { //这里做commend 非空判断,commend 不为空才执行下面的代码。
let setArr = i.commend.map(item => item.name);
let newshow = setArr.includes("9.9"); // 判断setArr 数组里面有没有‘9.9这个数据’
if (
newshow === false &&
i.ptbhs_supply_price - i.pt_fee < 9.9
) { // 这里是判断setArr里面没有9.9那个数据且两个价格相减小于9.9 就将9.9 这个数据push到setArr里面
setArr.push("9.9");
}
let d = new Date(i.create_time);
let t = d.getTime(d);
let totals = (timeStamp - t) / 1000;
var day = parseInt(totals / (24 * 60 * 60));
let days = setArr.includes("新品推荐");// 判断setArr 数组里面有没有‘新品推荐这个数据’
if (days === false && day < 7) {
setArr.push("新品推荐");
}
this.tableDatast.forEach(k => {
if (setArr.includes(k.name)) { // 如果setArr 数组里面跟tableDatast 数组比较,如果name相同项,就push到oneArr 数组中。
this.list[index]["oneArr"].push(k);
} else { 如果setArr 数组里面跟tableDatast 数组比较,如果name不相同项,就push到twoArr 数组中。
this.list[index]["twoArr"].push(k);
}
});
} else { // commend 为空的话,就将tableDatast 所有的数据push 到list里面的twoArr 数组中
this.tableDatast.forEach(p => {
this.list[index]["twoArr"].push(p);
});
}
});
}
}
两个数组之间将数组内的引用类型对比,相同的放一个数组,不同的放一个数组。
最后编辑于 :
©著作权归作者所有,转载或内容合作请联系作者
- 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
- 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
- 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...