2024-01-25 13:47:25 +08:00

305 lines
6.8 KiB
JavaScript

import { imageBasUrl } from '../../utils/config'
const { httpRequest } = getApp();
Page({
data: {
swiperItemHeight: 0,
imageBasUrl,
// chasingDramasShow: false,
chasDraIconColor: '#fff',
orderList: [],
videoInfoObj: {},
activeTab: 0,
orderPopupShow: false,
systemInfo: {},
userInfo: {},
iosPayment: {},
swiperList: [],
swiperCurrent: 0,
swiperOrder: 0,
sid: '',
},
// 获取其它信息
isOtherFn() {
my.createSelectorQuery().select('#_video_box').boundingClientRect().exec((r) => {
this.setData({
swiperItemHeight: r[0].height
})
});
this.setData({
userInfo: getApp().globalData.userInfo,
systemInfo: getApp().globalData.systemInfo
})
},
// 处理显示的集数
isSwiperListFn(orNum, ls, orInfo) {
// 总共显示集数
let showOrder = 9;
// 平均前后的集数
let halfNum = Math.ceil(showOrder / 2) - 1;
// 集数减一为,列表的索引
const sum = orNum - 1;
// 当前的集数加上,平均前后的集数,不能超过总的集数
const all = orNum + halfNum;
// 新的列表
const list = [];
let swiperCurrent = 0;
if (ls.length < showOrder) {
showOrder = ls.length;
halfNum = Math.ceil(ls.length / 2) - 1;
}
if (all >= ls.length) {
let digit = 0;
let first = halfNum;
// let after = halfNum;
let cunIdx = 0;
if (ls.length >= orNum) {
digit = ls.length - orNum;
first = (halfNum - digit) + halfNum;
}
for (let y = 0; y < showOrder; y++) {
if (first == 0) {
list.push(orInfo);
swiperCurrent = y;
first = first - 1;
} else if (first > 0) {
list.push(ls[orNum - first]);
first = first - 1;
} else {
if (cunIdx == 0) {
list.push(ls[orNum]);
cunIdx = cunIdx + 1;
} else {
console.log(orNum + cunIdx, "orNum + cunIdx]")
list.push(ls[orNum + cunIdx]);
cunIdx = cunIdx + 1;
}
}
}
} else if (orNum > halfNum) {
let first = halfNum;
// let after = halfNum;
let cunIdx = 0;
for (let y = 0; y < showOrder; y++) {
if (first == 0) {
list.push(orInfo);
swiperCurrent = y;
first = first - 1;
} else if (first > 0) {
list.push(ls[orNum - first]);
first = first - 1;
} else {
if (cunIdx == 0) {
list.push(ls[orNum]);
cunIdx = cunIdx + 1;
} else {
list.push(ls[orNum + cunIdx]);
cunIdx = cunIdx + 1;
}
}
}
} else {
for (let y = 0; y < showOrder; y++) {
if (sum == y) {
list.push(orInfo);
swiperCurrent = y;
} else {
list.push(ls[y])
}
}
}
this.setData({
swiperList: list,
swiperCurrent
})
},
// 处理弹框的集数
async handelOrder(infoObj) {
const paramenter = {
path: '/batchlist',
method: 'POST',
body: {
sid: infoObj.sid,
start: 1,
end: infoObj.total.length
}
}
const isBatchlist = await httpRequest(paramenter);
console.log(isBatchlist, "isBatchlist")
const num = 2;
let remain = 0;
let temp = [];
const mlist = [];
// if (Array.isArray(isBatchlist.data)) {
// vls.forEach((m, idx) => {
// if ((num * remain + num) < (idx + 1)) {
// remain += 1;
// temp = [];
// }
// temp.push(m);
// let obj = {
// firstNum: num * remain + 1,
// lastNum: idx + 1,
// title: `${num * remain + 1}-${idx + 1}`,
// temp: [...temp],
// }
// mlist[remain] = obj;
// });
// this.setData({
// orderList: mlist
// })
// }
},
// 获取 剧情
async isIosPaymentFn(sid) {
const paramenter = {
path: '/iosPayment',
method: 'GET',
}
const iosPayment = await httpRequest(paramenter);
// console.log(iosPayment, "iosPayment")
const paramVideo = {
path: '/videoread',
method: 'POST',
body: {
sid: sid
}
}
const videoRead = await httpRequest(paramVideo);
console.log(videoRead, "videoRead")
if (Array.isArray(videoRead.data)) {
const videoInfoObj = videoRead.data[0];
const swiperList = Array.from({ length: videoInfoObj.total }, (v, k) => k + 1);
// console.log(swiperList, "swiperList")
this.isSwiperListFn(videoInfoObj.order, swiperList, videoInfoObj);
this.handelOrder(videoInfoObj);
this.setData({
iosPayment: iosPayment,
swiperOrder: videoInfoObj.order,
// swiperList: swiperList
videoInfoObj: videoInfoObj
})
my.setNavigationBar({
title: videoInfoObj.title,
});
}
},
videoErrorFn(e) {
console.log(e, "eee")
},
//显示 选择集数
selectEpisodesFn() {
this.setData({
orderPopupShow: true
})
},
// 关闭 选择集数
closeOrderPopup() {
this.setData({
orderPopupShow: false
})
},
// 切换 级数的
handleTabClick(e) {
// console.log(e, "handleTabClickhandleTabClick")
this.setData({
activeTab: e.index
})
},
handleOrderCurrent(e) {
console.log(e, "handleOrderCurrent");
},
onLoad(query) {
const sid = query.sid;
this.setData({
sid: sid
})
},
onShow() {
const sid = this.data.sid;
this.isOtherFn();
this.isIosPaymentFn(sid);
console.log("--------------")
},
// 不追剧
// noChasingDramasFn() {
// this.setData({
// chasingDramasShow: false
// })
// },
// 添加追剧
addChasingDramasFn() {
const videoInfoObj = this.data.videoInfoObj;
if (videoInfoObj.iskeep == 0) {
const paramenter = {
path: '/addkeep',
method: 'POST',
body: {
sid: videoInfoObj.sid
}
}
httpRequest(paramenter).then(() => {
my.showToast({
icon: 'none',
content: '追剧成功',
duration: 1000,
});
this.setData({
videoInfoObj: {
...videoInfoObj,
iskeep: 1
}
})
})
} else {
const paramenter = {
path: '/chasingdramadel',
method: 'POST',
body: {
sid: videoInfoObj.sid
}
}
httpRequest(paramenter).then(() => {
my.showToast({
icon: 'none',
content: '取消成功',
duration: 1000,
});
this.setData({
videoInfoObj: {
...videoInfoObj,
iskeep: 0
}
})
})
}
// this.setData({
// chasDraIconColor: '#FF2B2B'
// })
},
})