courseDetail.js 4.3 KB
// pages/course/courseDetail/courseDetail.js
const app = getApp()
var wxParse = require('../../../wxParse/wxParse.js')
Page({
  /**
   * 页面的初始数据
   */
  data: {
    temshow: false,
    listdata:'',
    myinfo:'',
    price:'',//会员价格
    state:0//会员弹框控制,0关闭,1打开
  },
 settemshow() {
  this.setData({
   temshow: true
  })
 },
 temshowno() {
  this.setData({
   temshow: false
  })
 },
  //列表详情
  listDetail() {
    let that = this
    let url = 'Show/getShow1Detail'
    let params = {
      id: this.data.id
    }
    app.post(url, params).then((res) => {
      if (res.data.code == 1) {
        this.setData({
         listdata:res.data.data
        })
        wxParse.wxParse('content', 'html', res.data.data.content, that, 5);
      }
    }).catch((errMsg)=>{
      console.log(errMsg)
    })
  },
  //是否能观看视频
  videoplay(){
   console.log(1);
    let that=this;
    let myinfo = that.data.myinfo;
    if (that.data.myinfo.is_member){
console.log('1111111111111')
    }else{
     console.log('222222222222222');
      that.videoContext.pause()
      wx.showModal({
        title: '提示',
        content: '您还不是会员,不能观看,是否开通',
        success:function(res){
          if(res.confirm){
           that.setData({
             // state:1
            temshow: true
           })
          }else if(res.cancel){

          }
        }
      })
    }   
  }, 
  //获取个人信息判断是否开通会员
  getMyMessage() {
    let that = this;
    let url = 'Mine/getMyMessage';
    let params = {
      token: wx.getStorageSync("token")
    }
    app.post(url, params).then((res) => {
      if (res.data.code == 1) {
        that.setData({
          myinfo: res.data.data
        })
      }
    }).catch((errMsg) => {
      console.log(errMsg)
    })
  },
  setstate0(){
    let that=this;
    that.setData({
      state:0
    })
  },
  voidfun(){

  },
  //获取会员价格
  getPrice() {
    let that = this;
    let url = 'Mine/getPrice';
    app.post(url, {}).then((res) => {
      if (res.data.code == 1) {
        that.setData({
          price: res.data.data
        })
      }
    })
  },
  //确认开通
  confirmOpen() {
    let that = this;
   that.setData({
    temshow: false
   })
    let url = 'Mine/memberOrder';
    let params = {
      token: wx.getStorageSync('token')
    }
    app.post(url, params).then((res) => {
      if (res.data.code == 1) {
        wx.requestPayment({
          'timeStamp': res.data.data.timeStamp,
          'nonceStr': res.data.data.nonceStr,
          'package': res.data.data.package,
          'signType': 'HMAC-SHA256',
          'paySign': res.data.data.paySign,
          'success': function (res) {
            wx.showToast({
              title: '开通成功',
              icon: 'success',
              duration: 2000,
            })
            that.setData({
              state: 0,
              vipstate: 1,
            })
            that.getMyMessage();
          },
          'fail': function (res) {
            wx.showToast({
              title: '开通失败',
              icon: 'success',
              duration: 2000,
            })
          }
        })
      }
    }).catch((errMsg) => {
      console.log(errMsg)
    })
  },
  //取消开通
  cancelOpen() {
    this.setData({
      state: 0,
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    this.setData({
      id: parseInt(options.id)
    })
    this.listDetail();
    this.getMyMessage();
    this.getPrice();
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {
    this.videoContext = wx.createVideoContext('myVideo')
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {
    this.listDetail();
    this.getMyMessage();
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function() {

  }
})