const app = getApp() const navigationBarHeight = (getApp().statusBarHeight + 44) + "px" const config = require("../../config/config") const Http = require("../../utils/HttpBasics.js") Page({ data: { ifPay:app.globalData.platform, classTitle:"",//课程标题 showIos:false,//ios字符提示 showHie: false,//提示框 anthology: 0,//选集 classNumber: "",//有多少集 imgHttps: app.globalData.imgHttps, extraClasses: 'addBox-transition ', navigationBarHeight, videoContext: "", ifpay: 0,//是否支付 0免费 1付费 goPayFlag: false,//支付按钮显隐 btnSuspend: true,//控制播放按钮 columnIndex: 0, addFlag: true, thenIndex: 0,//播放选合集 popupNum: 0,//弹出选集 popupIndex: 0,////播放选集 showPopup: false,//选集弹框 id: "",//课程id data: {},//数据源 iscollect: false,//是否收藏 mp4Url: "", tiemLsit: [{//试看时间 value: 1, name: 60 }, { value: 2, name: 180, }, { value: 3, name: 300, }], }, // goIndent(e){ // console.log(e.dataset.url); // }, showIos(){ this.setData({ showIos:true }) }, cancel(e) { this.setData({ showHie: e.detail.data }) }, cancelIos(e) { this.setData({ showIos: e.detail.data }) }, hiePopup() { this.setData({ showPopup: false }) }, setShowPopup() { this.setData({ showPopup: true }) }, setPopupIndex(e) { let index = e.currentTarget.dataset.index this.setData({ popupIndex: index }) }, setPopupNum(e) { let index = e.currentTarget.dataset.index this.setData({ popupNum: index }) }, setThenIndex(e) { let index = e.currentTarget.dataset.index let id = e.currentTarget.dataset.id console.log(id); this.getVideoUrl(id) this.setData({ anthology: index }) }, siteVid(e) {//切换视频 let index = e.currentTarget.dataset.index let id = e.currentTarget.dataset.id this.getVideoUrl(id) this.setData({ anthology: index, goPayFlag: false, btnSuspend: true, }) }, hieaddCheck() { this.setData({ extraClasses: 'addBox-transition', addFlag: true }) }, addCheck() {//动画 this.setData({ addFlag: false }) if (this.data.extraClasses == 'addBox-transition addBox-moved') { this.setData({ extraClasses: 'addBox-transition', }) } else { this.setData({ extraClasses: 'addBox-transition addBox-moved' }) } }, setColumnIndex(e) { let index = e.currentTarget.dataset.index this.setData({ columnIndex: index }) }, order() {//支付 Http.post({//下订单 url: config.api.order, data: { couponId: this.data.id } }).then(res => { console.log(res.data, "订单成功"); let id = res.data.id console.log(id); Http.post({//拿orderInfo url: config.api.pay, data: { orderId: res.data.id } }).then(item => { console.log(item, "orderId"); tt.pay({ service: 5, orderInfo: { order_id: item.data.orderId, order_token: item.data.token, }, success(res) { if (res.code === 0) { this.getData() tt.showToast({ title: '支付成功!', // 内容 }); // 支付成功处理逻辑,只有res.code=0时,才表示支付成功 // 但是最终状态要以商户后端结果为准 } else if (res.code === 1) { tt.showToast({ title: '支付超时', // 内容 icon: "none" }); Http.post({ url: config.api.ifPayOk, data: { code: 1, orderId: res.data.id } }) } else if (res.code === 2) { tt.showToast({ title: '支付失败', // 内容 icon: "none" }); } else if (res.code === 3) { tt.showToast({ title: '支付关闭', // 内容 icon: "none" }); } else if (res.code === 4) { tt.showToast({ title: '支付取消', // 内容 icon: "none" }); } else if (res.code === 9) { tt.showToast({ title: '订单状态开发者自行获取', // 内容 icon: "none" }); } }, fail(res) { // handle fail }, }) }).catch(err => { tt.showToast({ title: '唤起支付失败', // 内容 icon: "none" }); }) }).catch(err => { if (err.code === 3013) { this.setData({ showHie: true }) } else { tt.showToast({ title: err.message, // 内容 icon: "none" }); } }) }, goPay() { this.order() console.log("我支付了"); this.setData({ goPayFlag: false, btnSuspend: true, }) }, time(e) { let time = e.detail.currentTime.toFixed(0); if (!this.data.ifpay || this.data.data.view) {//已经支付过或免费 if(this.data.data.columnCoupons){ this.setData({ classNumber: this.data.data.columnCoupons.length }) } return } else {//需要付费或已支付 let tempTime = "" //预览时间 if (this.data.data.columnCoupons) {//是不是集合 this.setData({ classNumber: this.data.data.columnCoupons.length }) tempTime = this.data.tiemLsit.filter(item => { return this.data.data.columnCoupons[this.data.anthology].previewDuration == item.value })[0].name } else { tempTime = this.data.tiemLsit.filter(item => { return this.data.data.previewDuration == item.value })[0].name } if (time >= tempTime) { this.data.videoContext.pause()//暂停 this.data.videoContext.exitFullScreen()//退出全屏 this.setData({ goPayFlag: true, btnSuspend: false,//禁止播放 }) } } }, setCollect() {//设置收藏 if (this.data.iscollect) {//已收藏 Http.get({ url: config.api.Fcollect, data: { id: this.data.id } }).then(res => { this.ifCollect() }).catch(err => { tt.showToast({ title: err.data, // 内容 icon: "none" }); }) } else {//未收藏 Http.get({ url: config.api.Tcollect, data: { id: this.data.id } }).then(res => { this.ifCollect() }).catch(err => { tt.showToast({ title: err.data, // 内容 icon: "none" }); }) } }, ifCollect() {//是否收藏课程 Http.get({ url: config.api.iscollect, data: { id: this.data.id } }).then(res => { this.setData({ iscollect: res.data }) }) }, getData() {//订单详情 Http.get({ url: config.api.classDetails, data: { id: this.data.id } }).then(res => { this.setData({ data: res.data, ifpay: res.data.isPayment }) if (res.data.columnCoupons) { this.getVideoUrl(res.data.columnCoupons[0].videoId) } else { this.getVideoUrl(res.data.videoId) } }).catch(err => { tt.showToast({ title: err.data, // 内容 icon: "none" }); }) }, getVideoUrl(id) {//获取视频url Http.get({ url: config.api.getViodUrl, data: { videoId: id } }).then(res => { console.log(res); this.setData({ mp4Url: res.data.videoUrl }) }) }, onReady() { this.setData({ videoContext: wx.createVideoContext('myVideo') }) }, onLoad(options) { if (options.id) { this.setData({ id: options.id, classTitle:options.title }) this.ifCollect() // this.getData() } }, onShow(){ this.getData() }, onShareAppMessage: function () { // return custom share data when user share. }, })