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

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

    logolurl: '',
    goods_id: '',
    email: '',
    hidedown:true,
    order_id:'',
    headlogolurl:'',
    download:false
  },

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

    console.log(options.type)

    this.setData({
      imgs: wx.getStorageSync('imgs')
    })


    console.log(this.data.imgs)
    // if(that.data.imgs){

    // }

    if (options.type==2){
      this.setData({
        imgUrls: this.data.imgs,
        headlogolurl: options.headlogolurl,
      })

      console.log(this.data.imgUrls)
    }else{
      this.setData({
        // goods_id: options.goods_id,
        // logolurl: options.logolurl
        order_id: options.goods_id,
        headlogolurl: options.headlogolurl,

      })

      console.log(this.data.order_id)

      this.getmodel()
    }

    

  },

  //购买并保存
  getmodel() {
    let that = this;
    var url = '/home/Order/downloadFile';
    var params = {

      id:that.data.order_id,
      format:'',
      email:'',
    }

    var header = {
      'XX-Token': wx.getStorageSync('token'),
      'XX-Device-Type': 'wxapp'
    }
    app.post(url, params,header).then((res) => {
      console.log(res);
      that.setData({
        imgUrls:res,
        logolurl:res[0]
      })
    }).catch((err) => {

    })

  },

  againgetmodel(){
    let that = this;
    var url = '/home/Order/downloadFile';
    var params = {

      id: that.data.order_id,
      format: '',
      email: '',
    }

    var header = {
      'XX-Token': wx.getStorageSync('token'),
      'XX-Device-Type': 'wxapp'
    }
    app.post(url, params, header).then((res) => {
      console.log(res);
      that.setData({
        imgUrls: res,
        logolurl: res[0]
      })
    }).catch((err) => {

    })
  },
 

  swiperChange: function (e) {
    console.log(e)
    this.setData({
      currentSwiper: e.detail.current,
      current:e.detail.current,
      logolurl: this.data.imgUrls[e.detail.current]

    })
  },


  //下载并保存
  savedowm() {
   let that = this;
    // let arr=that.data.imgUrls;
    // console.log(arr)
    // arr=arr.join(",");
    // console.log(arr)

    that.setData({
      download:true
    })

    let arr=that.data.imgUrls;
    for(var i=0;i<arr.length;i++){
      wx.getImageInfo({         //下载图片

        //src: that.data.logolurl,      //这里放你要下载图片的数组(多张) 或 字符串(一张)          下面代码不用改动
        src:  arr[i],

        success: function (ret) {
          console.log(ret)

          var path = ret.path;



          wx.saveImageToPhotosAlbum({

            filePath: path,

            success(result) {
              console.log(result)

              console.log("成功");
              that.setData({
                hidedown: true
              })
            },
            fail(res) {
              that.setData({
                hidedown: false
              })

            }

          });

        }

      });
    }
   
  },

 

  downset() {
    let that=this;
    that.setData({
      download:true
    })
    console.log(88)
    wx.openSetting({
      success(settingdata) {
        console.log(settingdata)
        if (settingdata.authSetting["scope.writePhotosAlbum"]) {
          console.log("获取权限成功,再次点击图片保存到相册")
          that.setData({
            hidedown: true
          })
        } else {
          console.log("获取权限失败")
        }
      }
    })
  },
//下载完成
  finishload(){
    // wx.navigateTo({
    
    //   url: '../teachplan/teachplanlistdetail/teachplanlistdetail',
    // })

    wx.navigateBack({
      checked:true
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

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

  },

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

  },

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

  },

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

  },

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

  },

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

  }
})