2024-11-22 09:19:49 +08:00

233 lines
5.8 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: '',
subscribeType: 1,
canUsePlayletExtension: getApp().globalData.canUsePlayletExtension,
useVideoByte: getApp().globalData.useVideoByte,
},
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 && Array.isArray(getNewModuleRes?.data?.module)) {
const ms = getNewModuleRes.data.module
newModule = ms.map((m: any) => {
return {
...m,
isCount: this.handelCount(m.count)
}
})
}
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,
isCount: 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;
const album_id = ev.currentTarget.dataset.item.album_id;
const episode_id = ev.currentTarget.dataset.item.episode_id;
let url = `/pages/videoDetail/videoDetail?sid=${sid}`;
if(this.data.canUsePlayletExtension&&this.data.useVideoByte){
url = `/pages/videoByte/videoByte?is_continue=0&tt_album_id=${album_id}&tt_episode_id=${episode_id}&sid=${sid}`;
}
console.log("url",url);
tt.navigateTo({
url: url,
});
// tt.navigateTo({
// url: `/pages/videoDetail/videoDetail?sid=${sid}`,
// });
},
onReachBottom() {
const page = this.data.page;
this.getNewModuleFn(page + 1);
},
async handelKeepFn(sid: any, bok: any) {
let newModule: any = this.data.newModule;
const idx = newModule.findIndex((m: any) => m.id == sid);
const count = newModule[idx]?.count || 0;
if (idx != -1) {
newModule[idx].bookcase = bok;
if (bok == 1) {
newModule[idx].isCount = this.handelCount(count + 1);
newModule[idx].count = count + 1;
} else {
newModule[idx].isCount = this.handelCount(count - 1);
newModule[idx].count = count - 1;
}
}
const params = {
total: 10
}
const chasingdramaRes: any = await httpRequest('/Chasingdrama', 'POST', params);
let bookcase = [];
if (chasingdramaRes.status == 1) {
bookcase = chasingdramaRes?.data?.bookcase
}
if (bok == 1) {
tt.showToast({
title: '订阅成功',
icon: 'none'
});
} else {
tt.showToast({
title: '取消成功',
icon: 'none'
});
}
this.setData({
newModule: newModule,
bookcase
})
},
chasingdramadel(ev: any) {
const sid = ev.currentTarget.dataset.sid;
this.myModal?.show?.();
this.setData({
bookId: sid,
subscribeType: 2
})
},
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);
}
})
},
myModalRef(ref: any) {
this.myModal = ref
},
handelMyModal(ev: any) {
const sid = ev.currentTarget.dataset.sid;
this.myModal?.show?.();
this.setData({
bookId: sid,
subscribeType: 1
})
},
modalConfirm() {
const bookId = this.data.bookId;
const params = {
ids: bookId
}
httpRequest('/chasingdramadel', 'POST', params).then((res: any) => {
if (res.status == 1) {
console.log('handelKeepFn',"handelKeepFn")
this.handelKeepFn(bookId, 0);
}
})
},
toPathSubScribe() {
tt.navigateTo({
url: `/pages/subscribe/subscribe`,
});
}
})