preview.js 4.3 KB
// pages/preview/preview.js
const app=getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    imgUrls: [
      
    ],
    indicatorDots: false,
    autoplay: false,
    interval: 2000,
    duration: 1000,
    currentSwiper: 0,

    logolurl:'',
    logolfile:'',
    goods_id:'',
    email:'',
    simgUrls:'',
    sownloadnum:false,
    state:""
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    console.log(options)

    this.setData({
      goods_id: options.goods_id,
      logolurl: options.logolurl,
      logolfile:options.logolfile

    })
    console.log(this.data.logolfile)
    this.getpreivew();
    this.showbtn();

  },

  showbtn() {
    let that = this;
    var url = '/home/Welcome/paySwitch';
    var params = {


    }
    app.post(url, params).then((res) => {
      console.log(res);
      that.setData({
        state: res.state
      })



    }).catch((err) => {

    })

  },

  cancelchange() {
    this.setData({
      sownloadnum: false
    })
  },

  //预览教案
  getpreivew(){
    let that = this;
    var url = '/home/Preview/preview';
    var params = {
      goods_id: that.data.goods_id,
      logo: that.data.logolurl

    }
    app.post(url, params).then((res) => {
      console.log();
      if (typeof (res.photos)=='string'){
        that.setData({
          simgUrls: res.photos
        })

      }else{

        that.setData({
          imgUrls: res.photos
        })
      }




      console.log(that.data.imgUrls)



    }).catch((err) => {

    })
  },

  //购买并保存
  buy(){
    var url = '/home/Order/done',that = this;
    var params = {
      goods_id: that.data.goods_id,
      is_custom_logo: 1,
      logo: that.data.logolfile,
      email: that.data.email
    }

    var header = {
      'XX-Token': wx.getStorageSync('token'),
      'XX-Device-Type': 'wxapp'
    }
    app.post(url, params, header).then((res) => {
      console.log(res);
      if (res.current_download_num != 0) {
        that.setData({
          sownloadnum: true
        })
        that.setData({
          payres: res
        })

      } else if (res.current_download_num == 0) {
        that.payment(res)
      }
    }).catch((err) => {

    })
  },



  surechange(){
    let that = this;
    console.log(that.data.logolfile)
    var url = '/home/Order/done';
    var params = {
      goods_id: that.data.goods_id,
      is_custom_logo: 1,
      logo: that.data.logolfile,
      email: that.data.email
    }

    var header = {
      'XX-Token': wx.getStorageSync('token'),
      'XX-Device-Type': 'wxapp'
    }
    app.post(url, params, header).then((res) => {

        that.payment(res)
      
    }).catch((err) => {

    })

  },


  payment(res) {
    let that = this
    wx.requestPayment({
      timeStamp: res.wx_pay.timeStamp,
      nonceStr: res.wx_pay.nonceStr,
      package: res.wx_pay.package,
      signType: res.wx_pay.signType,
      paySign: res.wx_pay.paySign,
      success(res) {
        console.log(res)

        if (res.errMsg == 'requestPayment:ok') {

          wx.navigateTo({
            url: '../teachplan/teachplanlistdetail/teachplanlistdetail?id='+that.data.goods_id,
          })

          // that.setData({
          //   selectrue: false,
          // })
          // wx.switchTab({
          //   url: '../pocketlesson/pocketlesson',
          // })

          // wx.navigateBack({
          //   checked:true
          // })

        }
      },
      fail(res) { }
    })
  },


  //继续更换
  continue(){
    wx.navigateBack({ changed: true });
  },

  swiperChange: function (e) {
    this.setData({
      currentSwiper: e.detail.current
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

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

  },

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

  },

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

  },

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

  },

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

  }
})