2024-03-11 15:53:28 +08:00

597 lines
14 KiB
JavaScript

import { imageBasUrl } from '../../utils/config'
const { httpRequest } = getApp();
// import { throttle } from 'lodash';
// import { throttle } from '../../utils/throttle'
var _ = require('underscore');
Page({
data: {
imageBasUrl,
// swiperItemHeight: 0,
orderList: [],
videoInfoObj: {},
posterCover: '',
activeTab: 0,
orderPopupShow: false,
systemInfo: {},
userInfo: {},
iosPayment: {},
swiperList: [],
swiperCurrent: 0,
changeCuurent: 0,
swiperOrder: 0,
sid: '',
popupShow: false,
batchAllOrder: 0,
batchAllList: [],
isThrottle: null,
pageHideFlag: true,
videoStatus: 1,
videoControlTimer: null,
videoDuration: '0.00',
currentTime: '0.00',
sliderMax: 100,
sliderValue: 0
},
// 获取其它信息
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
})
},
// 处理弹框的集数
handelOrder(isBatchlist) {
const num = 30;
let remain = 0;
let temp = [];
const mlist = [];
let orderObj = {};
if (Array.isArray(isBatchlist.data)) {
isBatchlist.data.forEach((m, idx) => {
if ((num * remain + num) < m.order) {
remain += 1;
temp = [];
}
temp.push(m);
orderObj[remain] = {
firstNum: num * remain + 1,
lastNum: m.order,
title: `${num * remain + 1}-${m.order}`,
temp: temp
}
});
Object.keys(orderObj).map((m) => {
mlist.push(orderObj[m]);
})
return {
orderList: mlist,
batchAllOrder: isBatchlist.data.length,
batchAllList: isBatchlist.data,
}
}
return {
orderList: [],
batchAllOrder: 0,
batchAllList: []
}
},
handelOrderIsVip(resData) {
const orderList = this.data.orderList;
const batchAllList = this.data.batchAllList;
// swiperList.splice(current, 1, resData);
if (resData.chackpay == 1) {
const ols = [];
orderList.forEach((j) => {
let jb = {
...j
}
const yus = [];
j.temp.forEach((y) => {
let yobj = {
...y,
}
if (yobj.id == resData.id) {
yobj.isvip = 0;
}
yus.push(yobj);
})
jb.temp = yus;
ols.push(jb);
})
let newBatchAllList = [...batchAllList];
newBatchAllList[resData.order - 1].isvip = 0;
this.setData({
batchAllList: newBatchAllList
})
return ols;
}
return orderList;
},
// 获取 剧情
async isVideoPaymentFn(sid) {
const paramVideo = {
path: '/videoread',
method: 'POST',
body: {
sid: sid
}
}
const videoRead = await httpRequest(paramVideo);
if (Array.isArray(videoRead.data)) {
const videoInfoObj = videoRead.data[0];
const paramenter = {
path: '/batchlist',
method: 'POST',
body: {
sid: videoInfoObj.sid,
start: 1,
end: videoInfoObj.total
}
}
const isBatchlist = await httpRequest(paramenter);
const selectOrderInfo = this.handelOrder(isBatchlist);
this.setData({
swiperOrder: videoInfoObj.order,
videoInfoObj: videoInfoObj,
swiperCurrent: videoInfoObj.order - 1,
changeCuurent: videoInfoObj.order - 1,
posterCover: videoInfoObj.videocover || videoInfoObj.cover,
orderList: selectOrderInfo.orderList,
batchAllOrder: selectOrderInfo.batchAllList,
batchAllList: selectOrderInfo.batchAllList,
})
my.setNavigationBar({
title: videoInfoObj.title,
});
}
},
toPathPlayAllOrder() {
const videoInfoObj = this.data.videoInfoObj;
const sid = this.data.sid;
const paramVideo = {
path: '/buyall',
method: 'POST',
body: {
sid: sid,
id: videoInfoObj.id,
allprice: videoInfoObj.allprice
},
errShowT: true
}
httpRequest(paramVideo).then(res => {
if (res.status == 1) {
my.showToast({
type: 'none',
content: res.msg || '购买成功',
duration: 1000,
})
this.isVideoPaymentFn(sid);
}
}).catch(err => {
if (err.status == 2) {
my.confirm({
title: '温馨提示',
content: err.msg,
confirmButtonText: '去充值',
cancelButtonText: '取消',
success: (result) => {
if (result.confirm) {
this.setData({
popupShow: true,
})
}
},
});
}
})
},
handelswiperCurrent(ev) {
const current = ev.detail.current;
const isThrottle = this.data.isThrottle;
isThrottle(current);
},
videoErrorFn(e) {
console.log(e, "eee")
},
videoEndedFn() {
const videoInfoObj = this.data.videoInfoObj;
const sid = this.data.sid;
// const swiperList = this.data.swiperList;
const id = videoInfoObj.nextid;
const videoControlTimer = this.data.videoControlTimer;
clearTimeout(videoControlTimer);
// const current = videoInfoObj.order;
const paramVideo = {
path: '/videoread',
method: 'POST',
body: {
sid: sid,
id: id
}
}
httpRequest(paramVideo).then(res => {
// swiperList.map()
const resData = res.data[0];
const ols = this.handelOrderIsVip(resData);
// swiperList.splice(current, 1, resData);
this.setData({
// swiperList: swiperList,
swiperCurrent: resData.order - 1,
changeCuurent: resData.order - 1,
videoInfoObj: resData,
orderList: ols,
videoStatus: 1
// swiperOrder: resData.order
})
})
},
onTimeUpdate(ev) {
// console.log(ev, "=========")
const videoDuration = ev.detail.videoDuration;
const currentTime = ev.detail.currentTime;
const videoDuration_m = parseInt(videoDuration / 60 % 60);
const videoDuration_s = parseInt(videoDuration % 60);
const currentTime_m = parseInt(currentTime / 60 % 60);
const currentTime_s = parseInt(currentTime % 60);
const vtime_m = videoDuration_m < 10 ? `0${videoDuration_m}` : videoDuration_m;
const vtime_s = videoDuration_s < 10 ? `0${videoDuration_s}` : videoDuration_s;
const ctime_m = currentTime_m < 10 ? `0${currentTime_m}` : currentTime_m;
const ctime_s = currentTime_s < 10 ? `0${currentTime_s}` : currentTime_s;
if (videoDuration != undefined && currentTime != undefined) {
this.setData({
videoDuration: `${vtime_m}:${vtime_s}`,
currentTime: `${ctime_m}:${ctime_s}`,
sliderMax: parseInt(videoDuration),
sliderValue: parseInt(currentTime)
})
}
},
videoPlayControl() {
const videoControlTimer = setTimeout(() => {
const videoStatus = this.data.videoStatus;
if (videoStatus == 2) {
this.setData({
videoStatus: 1
})
}
}, 3000)
this.setData({
videoStatus: 2,
videoControlTimer
})
},
// onTouchEndControls() {
// const videoControlTimer = setTimeout(() => {
// const videoStatus = this.data.videoStatus;
// if (videoStatus == 2) {
// this.setData({
// videoStatus: 1
// })
// }
// }, 3000);
// this.setData({
// videoControlTimer
// })
// },
// onTouchStartControls() {
// const videoControlTimer = this.data.videoControlTimer;
// clearTimeout(videoControlTimer);
// },
videoSliderChange(ev) {
const sliderValue = ev.detail.value;
const item = ev.currentTarget.dataset.item;
const videoContext = my.createVideoContext(`myVideo_${item.order}`);
videoContext.seek(sliderValue);
const videoControlTimer = setTimeout(() => {
const videoStatus = this.data.videoStatus;
if (videoStatus == 2) {
this.setData({
videoStatus: 1
})
}
}, 3000);
this.setData({
sliderValue,
videoControlTimer
})
},
videoSliderChanging() {
const videoControlTimer = this.data.videoControlTimer;
clearTimeout(videoControlTimer);
},
videoPlayPause(ev) {
const item = ev.currentTarget.dataset.item;
const videoControlTimer = this.data.videoControlTimer;
const videoContext = my.createVideoContext(`myVideo_${item.order}`);
videoContext.pause();
clearTimeout(videoControlTimer);
this.setData({
videoStatus: 3
})
},
videoPlayPlay(ev) {
const item = ev.currentTarget.dataset.item;
const videoContext = my.createVideoContext(`myVideo_${item.order}`);
videoContext.play();
const videoControlTimer = setTimeout(() => {
const videoStatus = this.data.videoStatus;
if (videoStatus == 2) {
this.setData({
videoStatus: 1
})
}
}, 3000);
this.setData({
videoStatus: 2,
videoControlTimer
})
},
//显示 选择集数
selectEpisodesFn() {
this.setData({
orderPopupShow: true
})
},
// 关闭 选择集数
closeOrderPopup() {
this.setData({
orderPopupShow: false
})
},
// 切换 级数的
handleTabClick(ev) {
// console.log(e, "handleTabClickhandleTabClick")
this.setData({
activeTab: ev.index
})
},
handleOrderCurrent(ev) {
const item = ev.target.dataset.item;
// const videoInfoObj = this.data.videoInfoObj;
// const orderList = this.data.orderList;
// const batchAllOrder = this.data.batchAllOrder;
const batchAllList = this.data.batchAllList;
// if(videoInfoObj.order == item.order) {
// }
if (item.order != 1) {
const nextVideoObj = batchAllList[item.order - 2];
if (nextVideoObj.isvip == 1) {
my.showToast({
type: 'info',
content: '为了保证剧情连贯,请按顺序观看'
})
return;
}
}
// const current = item.order - 1;
const sid = this.data.sid;
const videoControlTimer = this.data.videoControlTimer;
clearTimeout(videoControlTimer);
// const swiperList = this.data.swiperList;
const paramVideo = {
path: '/videoread',
method: 'POST',
body: {
sid: sid,
id: item.id
}
}
httpRequest(paramVideo).then(res => {
// swiperList.map()
const resData = res.data[0];
const ols = this.handelOrderIsVip(resData);
this.setData({
// swiperList: swiperList,
// swiperCurrent: current,
videoInfoObj: resData,
// swiperOrder: resData.order,
orderPopupShow: false,
orderList: ols,
swiperCurrent: resData.order - 1,
changeCuurent: resData.order - 1,
videoStatus: 1
})
})
},
onLoad(query) {
const sid = query.sid;
this.setData({
sid: sid
})
},
onShow() {
const sid = this.data.sid;
this.isOtherFn();
this.isVideoPaymentFn(sid);
// const lodash = require('lodash');
const isThrottle = _.throttle((current) => {
let id = '';
const changeCuurent = this.data.changeCuurent;
const videoInfoObj = this.data.videoInfoObj;
const sid = this.data.sid;
if (current > changeCuurent) {
id = videoInfoObj.nextid;
} else {
id = videoInfoObj.lastid;
}
const paramVideo = {
path: '/videoread',
method: 'POST',
body: {
sid: sid,
id: id
}
}
const videoControlTimer = this.data.videoControlTimer;
clearTimeout(videoControlTimer);
httpRequest(paramVideo).then(res => {
// swiperList.map()
const resData = res.data[0]
// swiperList.splice(current, 1, resData);
const ols = this.handelOrderIsVip(resData);
this.setData({
// swiperList: swiperList,
// swiperCurrent: current,
changeCuurent: current,
videoInfoObj: resData,
orderList: ols,
swiperOrder: resData.order,
videoStatus: 1
})
})
}, 300, { trailing: false });
this.setData({
isThrottle: isThrottle,
pageHideFlag: true
})
},
toPathPlayPage() {
this.setData({
popupShow: true,
})
},
onClosePopup(mi) {
const videoInfoObj = this.data.videoInfoObj;
if (mi.resultCode == 9000 && videoInfoObj.chackpay == 2) {
const sid = this.data.sid;
const paramVideo = {
path: '/videoread',
method: 'POST',
body: {
sid: sid,
id: videoInfoObj.id
}
}
httpRequest(paramVideo).then(res => {
const resData = res.data[0];
const ols = this.handelOrderIsVip(resData);
this.setData({
popupShow: false,
videoInfoObj: resData,
orderList: ols
})
})
} else {
this.setData({
popupShow: 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({
type: 'none',
content: '取消成功',
duration: 1000,
});
this.setData({
videoInfoObj: {
...videoInfoObj,
iskeep: 0
}
})
})
}
},
onHide() {
this.setData({
pageHideFlag: false
})
}
})