2024-05-24 17:24:28 +08:00

186 lines
4.3 KiB
TypeScript

// e:\project\dy_video_all\初晴剧场\pages\home\home.ts
import { httpRequest } from "../../utils/httpReques";
Page({
myModal: null as any,
data: {
swiperCurrent: 0,
carouselChart: [],
boutique: [],
optimalSelection: [],
classical: [],
page: 1,
newModule: [],
bookcase: [],
bookId: ''
},
onLoad: function () {
},
onShow() {
const page = this.data.page;
const appInstance = getApp();
tt.showLoading({
title: '加载中...',
})
appInstance.globalData.loginPromise.then(async () => {
const params = {
total: 10
}
const indexRes: any = await httpRequest('/index', 'POST');
const getNewModuleRes: any = await httpRequest('/getNewModule', 'POST', { page });
const chasingdramaRes: any = await httpRequest('/Chasingdrama', 'POST', params);
let carouselChart = [];
let boutique = [];
let optimalSelection = [];
let classical = [];
let bookcase = [];
let newModule = []
tt.hideLoading({});
if (indexRes.status == 1) {
const data = indexRes.data;
carouselChart = data?.ads;
boutique = data?.module1;
optimalSelection = data?.module3;
classical = data?.module4;
}
if (chasingdramaRes.status == 1) {
bookcase = chasingdramaRes?.data?.bookcase
}
if (getNewModuleRes.status == 1) {
newModule = getNewModuleRes.data.module
}
this.setData({
carouselChart,
boutique,
optimalSelection,
classical,
bookcase,
newModule
})
})
},
handelCount(count: any) {
if (count > 999) {
const isCount: any = (count / 100000).toFixed(2);
const ik = parseFloat(isCount) * 100
return `${ik}k`;
}
return count;
},
getNewModuleFn(page: any) {
const params = {
page: page
}
httpRequest('/getNewModule', 'POST', params).then((res: any) => {
if (res.status == 1 && Array.isArray(res?.data?.module)) {
const dataModule = res?.data?.module;
const ms = dataModule.map((m: any) => {
return {
...m,
count: this.handelCount(m.count)
}
})
if (page == 1) {
this.setData({
newModule: ms,
page: page
})
} else {
const newModule: any = this.data.newModule;
const ls: any = [...newModule, ...ms]
this.setData({
newModule: ls,
page: page
})
}
}
})
},
handelSwiperChange(ev: any) {
const current = ev.detail.current;
this.setData({
swiperCurrent: current
})
},
toPathTap() {
tt.navigateTo({
url: `/pages/search/search`,
});
},
toPathVideo(ev: any) {
const sid = ev.currentTarget.dataset.sid;
tt.navigateTo({
url: `/pages/videoDetail/videoDetail?sid=${sid}`,
});
},
onReachBottom() {
const page = this.data.page;
this.getNewModuleFn(page + 1);
},
handelKeepFn(sid: any, bok: any) {
let newModule: any = this.data.newModule;
const idx = newModule.findIndex((m: any) => m.id == sid)
newModule[idx].bookcase = bok
this.setData({
newModule: newModule
})
},
chasingdramadel(ev: any) {
const sid = ev.currentTarget.dataset.sid;
this.myModal?.show?.();
this.setData({
bookId: sid
})
},
addkeep(ev: any) {
const sid = ev.currentTarget.dataset.sid;
const params = {
sid: sid
}
httpRequest('/addkeep', 'POST', params).then((res: any) => {
if (res.status == 1) {
this.handelKeepFn(sid, 1);
tt.showToast({
title: '订阅成功',
icon: 'none'
});
}
})
},
myModalRef(ref: any) {
this.myModal = ref
},
handelMyModal(ev: any) {
const sid = ev.currentTarget.dataset.sid;
this.myModal?.show?.();
this.setData({
bookId: sid
})
},
modalConfirm() {
const bookId = this.data.bookId;
const params = {
ids: bookId
}
httpRequest('/chasingdramadel', 'POST', params).then((res: any) => {
if (res.status == 1) {
this.handelKeepFn(bookId, 0);
tt.showToast({
title: '取消成功',
icon: 'none'
});
}
})
},
toPathSubScribe() {
tt.navigateTo({
url: `/pages/subscribe/subscribe`,
});
}
})