|
- 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: 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);
- // },
- 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() {
- 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() {//支付
- 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
- })
- _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: '唤起支付失败', // 内容
- 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.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
- })
- })
- },
- 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)
- }
-
- }).catch(err => {
- tt.showToast({
- title: err.messagea, // 内容
- icon: "none"
- });
- })
- },
- getVideoUrl(id) {//获取视频url
- Http.get({
- url: config.api.getViodUrl,
- data: {
- videoId: id
- }
- }).then(res => {
-
- 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')
- })
- },
- 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() {
- },
- onShareAppMessage: function (shareOption) {
- console.log(this.data.data.dyTitle);
- let that = this
- if (shareOption.channel == 'video') { // 判断是是不是分享视频
- return {
- channel: 'video', // 必写 video
- // templateId: '', // 分享的模版 id (如果未设置就是默认,下面会说如何设置)
- title: '知播堂', // 分享的标题
- // desc: '我是简介', // 分享的内容介绍目前没有用
- // path: `/pages/index/index`, // 分享的路径
- extra: {
- videoTopics: ["知播堂", that.data.data.dyTitle] // 只有抖音才会有的属性
- },
- }
- } else { // 右上角分享
- return {
- templateId: '', //分享的模版 id
- title: '', //分享的标题
- desc: '', // 分享的内容
- // path: ``, // 分享的路径
- }
- }
- },
-
- })
|