|
- const app = getApp()
- const navigationBarHeight = (getApp().statusBarHeight + 44) + "px"
- const config = require("../../config/config")
- const Http = require("../../utils/HttpBasics.js")
-
- Page({
- data: {
- showGoDouDian: false,
- direction: -90,
- screenFlag: false,
- showAddBox: {},
- // signal: app.globalData.platform,
- signal:'Android',//零时 写死不走积分
- flagSystem: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: 1,
- addFlag: true,
- thenIndex: 0,//播放选合集
- popupNum: 0,//弹出选集
- popupIndex: 0,////播放选集
- showPopup: false,//选集弹框
- id: "",//课程id
- data: {},//数据源
- iscollect: false,//是否收藏
- mp4Url: "",
- tiemLsit: [
- {//不预览
- value: -1,
- name: 0
- },
- {//试看时间
- value: 1,
- name: 1000000000000000000//无限大=》免费观看
- }, {
- value: 2,
- name: 30,
- }, {
- value: 3,
- name: 60,
- }, {
- value: 4,
- name: 180,
- }
- , {
- value: 5,
- name: 300,
- }],
- },
- // goIndent(e){
- // console.log(e.dataset.url);
- // },
- itiRecording() {//防止录屏初始化函数
- console.log(this.data.flagSystem);
- if (this.data.flagSystem == 'ios') {
- this.onRecord()
- } else {
- this.disable()
- }
- },
- disable: function () {// 防止录屏录制 安卓
- tt.disableUserScreenRecord({
- success(res) {
- console.log("disableUserScreenRecord 调用成功", res)
- },
- fail(res) {
- console.log("disableUserScreenRecord 调用失败", res);
- },
- })
- },
- onRecord: function () { // 防止录屏录制 ios
- const callback = (res) => {
- console.log("我执行了")
- if (res.state === 'start') {
- this.data.videoContext.pause()//暂停
- this.data.videoContext.exitFullScreen()//退出全屏
- this.setData({
- screenFlag: true,
- btnSuspend: false,//禁止播放
- })
- } else if (res.state === 'stop') {
- this.data.videoContext.play();
- this.setData({
- screenFlag: false,
- btnSuspend: true,//禁止播放
- })
- }
- }
- tt.onUserScreenRecord(callback)
- },
- 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) {
- tt.showLoading({
- title: '加载中...', // 内容
- });
- let index = e.currentTarget.dataset.index
- let id = e.currentTarget.dataset.id
- this.getVideoUrl(id)
- this.setData({
- anthology: index,
- goPayFlag: false,
- btnSuspend: true,
- })
- },
- siteVid(e) {//切换视频
- tt.showLoading({
- title: '加载中...', // 内容
- });
- let index = e.currentTarget.dataset.index
- let id = e.currentTarget.dataset.id
- this.getVideoUrl(id)
- this.setData({
- anthology: index,
- goPayFlag: false,
- btnSuspend: true,
- })
- },
- hieaddCheck() {
- let animation = tt.createAnimation({
- duration: 1000,
- timingFunction: "ease",
- });
- animation.translateX(400).step()
- this.setData({
- // extraClasses: 'addBox-transition',
- showAddBox: animation.export(),
- addFlag: true
- })
- },
- showAddCheck: function () {
- this.setData({
- addFlag: false
- })
- let animation = tt.createAnimation({
- duration: 1000,
- timingFunction: "ease",
- });
- animation.translateX(0).step()
- this.setData({
- showAddBox: animation.export(),
-
- })
- },
- setColumnIndex(e) {
- let index = e.currentTarget.dataset.index
- this.setData({
- columnIndex: index
- })
- },
- order() {//支付
- let _this = this
- 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 => {
- tt.pay({
- service: 5,
- orderInfo: {
- order_id: item.data.orderId,
- order_token: item.data.token,
- },
- success(res) {
- console.log(res.code, Http.address, "支付成功回调code");
- let id = res.id
- if (res.code === 0) {
- tt.request({
- url: Http.address + config.api.ifPayOk, // 目标服务器url
- method: "post",
- headers: {
- "Content-Type": "application/json;charset=UTF-8",
- token: app.globalData.token
- },
- data: {
- code: 0,
- orderId: id
- },
- success: (res) => {
- _this.setData({
- goPayFlag: false,
- btnSuspend: true,
- })
- _this.getData()
- },
- fail: (err) => {
- tt.showToast({
- title: err.message, // 内容
- icon: "none"
- });
- console.log("我失败; err", err);
- _this.getData()
- }
- });
-
-
- tt.showToast({
- title: '支付成功!', // 内容
- });
-
- // 支付成功处理逻辑,只有res.code=0时,才表示支付成功
- // 但是最终状态要以商户后端结果为准
- } else if (res.code === 1) {
- tt.showToast({
- title: '支付超时', // 内容
- icon: "none"
- });
-
- } 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: err.message ? err.message : err.data, // 内容
- icon: "none"
- });
- })
- }).catch(err => {
- if (err.code === 3013) {
- this.setData({
- showHie: true
- })
- } else {
- tt.showToast({
- title: err.message, // 内容
- icon: "none"
- });
- }
-
- })
- },
-
- goPay() {
- if (this.data.signal == 'ios') {
- tt.showLoading({
- title: '支付中...', // 内容
- });
- let _this = this
- //获取积分信息
- Http.get({
- url: config.api.getUserInfo
- }).then(res => {
- //获取当前用户积分
- let integral = res.data.credit
- if (Number(_this.data.data.salePrice) <= integral) {//判断用户积分是否大于购买该课程的积分
- Http.post({
- url: config.api.creditsave,
- data: {
- couponId: _this.data.id
- }
- }).then(res => {
- tt.showToast({
- title: '购买成功', // 内容
- duration: 2000,
- success: (res) => {
- _this.setData({
- goPayFlag: false,
- btnSuspend: true,
- })
- _this.getData()
- tt.hideLoading();
- }
- });
- }).catch(err => {
- tt.showToast({
- title: err.message ? err.message : err.data,
- icon: "none"
- });
- })
- } else {
- tt.hideLoading();
- //积分不足
- this.setData({
- showGoDouDian: true
- })
- }
-
- }).catch(err => {
- tt.showToast({
- title: err.message ? err.message : err.data,
- icon: "none"
- });
- })
- } else {
- this.order()
- }
- },
- 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.message, // 内容
- icon: "none"
- });
- })
- } else {//未收藏
- Http.get({
- url: config.api.Tcollect,
- data: { id: this.data.id }
- }).then(res => {
- this.ifCollect()
- }).catch(err => {
- tt.showToast({
- title: err.message, // 内容
- icon: "none"
- });
- })
- }
- },
- ifCollect() {//是否收藏课程
- Http.get({
- url: config.api.iscollect,
- data: {
- id: this.data.id
- }
- }).then(res => {
- this.setData({
- iscollect: res.data
- })
- }).catch(err => {
- this.setData({
- iscollect: false
- })
- })
- },
- openGood(e) {
- this.setData({
- showGoDouDian: false,
- })
- console.log(e.target.dataset.id);
- tt.openEcGood({
- promotionId: e.target.dataset.id,
- success(res) {
- console.log("调用成功", res);
- },
- fail(res) {
- console.log("调用失败", res);
- },
- });
- },
- hieGoDou() {
- this.setData({
- showGoDouDian: false,
- })
- },
- getData() {//课程详情
- Http.get({
- url: config.api.classDetails,
- data: { id: this.data.id }
- }).then(res => {
- this.setData({
- data: res.data,
- ifpay: res.data.isPayment,
- columnIndex: res.data.type == 1 ? 0 : 1
- })
- if (res.data.columnCoupons) {
- this.getVideoUrl(res.data.columnCoupons[0].videoId)
- } else {
- this.getVideoUrl(res.data.videoId)
- }
- console.log(res.data.view, "支付状态");
-
- }).catch(err => {
- tt.showToast({
- title: err.messagea, // 内容
- icon: "none"
- });
- })
- },
- getVideoUrl(id) {//获取视频url
- Http.get({
- url: config.api.getViodUrl,
- data: {
- videoId: id
- }
- }).then(res => {
- console.log(res.data.width, res.data.height);
- if ((res.data.width) * 1 >= (res.data.height) * 1) {
- //横屏
- console.log("横屏");
- this.setData({
- direction: -90
- })
- } else {
- //竖屏
- console.log("竖屏");
- this.setData({
- direction: 0
- })
- }
- this.setData({
- mp4Url: res.data.videoUrl
- })
- tt.hideLoading();
- }).catch(err => {
- t.hideLoading();
- tt.showToast({
- title: err.messagea, // 内容
- icon: "none"
- });
- })
- },
-
- onReady() {
- this.setData({
- videoContext: wx.createVideoContext('myVideo')
- })
- this.itiRecording()
- },
- onLoad(options) {
- if (app.globalData.token) {
- if (options.id) {
- this.setData({
- id: options.id,
- classTitle: options.title
- })
- this.ifCollect()
- this.getData()
- }
- } else {
- app.tokenCallback = token => {
- if (options.id) {
- this.setData({
- id: options.id,
- classTitle: options.title
- })
- this.ifCollect()
- this.getData()
- }
- }
- }
-
-
- },
- onShow() {
- let animation = tt.createAnimation({
- duration: 0,
- // timingFunction: "ease",
- });
- animation.translateX(400).step()
- this.setData({
- showAddBox: animation.export(),
- screenFlag: false,//初始化防录屏弹框
- })
- this.itiRecording()
-
- },
- onShareAppMessage: function (shareOption) {
- console.log(this.data.data.dyTitle);
- let that = this
- if (shareOption.channel == 'video') { // 判断是是不是分享视频
- return {
- channel: 'video', // 必写 video
- // templateId: '', // 分享的模版 id (如果未设置就是默认,下面会说如何设置)
- title: `${that.data.data.dyTitle}`, // 分享的标题
- // desc: `${that.data.data.dyTitle}`, // 分享的内容介绍目前没有用
- // path: `/pages/index/index`, // 分享的路径
- // extra: {
- // videoTopics: [ that.data.data.dyTitle] // 只有抖音才会有的属性
- // },
- }
- } else { // 右上角分享
- return {
- extra: {
- videoTopics: [ that.data.data.dyTitle] // 只有抖音才会有的属性
- },
- templateId: '', //分享的模版 id
- title: `${that.data.data.dyTitle}`, //分享的标题
- // desc: `${that.data.data.dyTitle}`, // 分享的内容
- // path: ``, // 分享的路径
- }
- }
- },
-
- })
|