class Index {
constructor() {
this.indexList = [
{ id: 1, title: '推荐', content: [], page: 1, totalPage: 0 },
{ id: 2, title: '时令', content: [], page: 1, totalPage: 0 },
{ id: 3, title: '食肉', content: [], page: 1, totalPage: 0 },
{ id: 4, title: '素食', content: [], page: 1, totalPage: 0 },
{ id: 5, title: '烘焙', content: [], page: 1, totalPage: 0 },
];
this.index = 0;
this.getBanner();
this.getType();
this.threeMeals();
this.getIndex();
this.renderMRSC();
}
async threeMeals() {
var res = await server.threeMeals();
res.forEach((v,i) => {
$(".ddd ul").append(`
${v.title}
`);
$(".mrsc_swiper .swiper-wrapper").append(`
`);
})
$(".ddd ul li").click(function () {
// 链式调用
$(this).addClass("active").siblings().removeClass("active")
mySwiper.slideTo($(this).index())
});
var mySwiper = new Swiper ('.mrsc_swiper', {
direction: 'horizontal',
on: {
slideChangeTransitionEnd: function(){
$(".ddd ul li")
.eq(this.activeIndex)
.addClass("active")
.siblings()
.removeClass("active")
},
},
pagination: {
el: '.swiper-pagination',
},
})
}
async getType() {
var res = await server.type();
res.forEach(v => {
$(".menu").append(`
${v.title}
`)
})
}
async getBanner() {
var res = await server.banner();
res.forEach(v => {
$(".banner_swiper .swiper-wrapper")
.append(``)
});
new Swiper ('.banner_swiper', {
direction: 'horizontal',
pagination: {
el: '.swiper-pagination',
},
});
}
async getIndex() {
if (this.indexList[this.index].content.length == 0) {
var res = await server.index({
type: this.indexList[this.index].id,
page: this.indexList[this.index].page
});
this.indexList[this.index].page = res.current_page
this.indexList[this.index].totalPage = res.total_page
this.indexList[this.index].content = [
...this.indexList[this.index].content,
...res.items
]
item(
$(".do_together_content .roll_father").eq(this.index),
this.indexList[this.index].content
)
}
}
renderMRSC() {
this.indexList.forEach((v,i) => {
$(".alldo ul").append(`
${v.title}
`);
$(".do_together_content").append(`
`);
});
var self = this;
$(".alldo ul li").click(function () {
self.index = $(this).index();
$(this).addClass("active").siblings().removeClass("active")
$(".do_together_content .roll_father")
.eq(self.index)
.addClass("showRoll")
.siblings()
.removeClass("showRoll")
self.getIndex()
})
}
}
new Index();