guanimg.js 2.4 KB
// pages/homeblock/guanimg/guanimg.js
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    url: '',
    id: "",
    picture:[],
    banner:[],
    arrbanner: [],
    arrpicture: []
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    this.setData({
      url: app.globalData.url,
      id: options.wineid
    })

    this.getguantu()
  },
  //获取官图
  getguantu() {
    let that = this;
    let url = 'index/Wine/wine_images',
      params = {
        wine_id:that.data.id,

      }
    app.post(url, params).then((res) => {
      console.log(res);
      that.setData({
        banner:res.banner,
        picture: res.picture
      })
      let bannerarr=[];
      let picturearr=[]

      let newbanner=that.data.banner;
      let newpicture = that.data.picture
      for(var obj of newbanner){
        bannerarr.push(obj.url)
      } 

      for (var obj of newpicture){
        picturearr.push(obj.url)
      }

      that.setData({
        arrbanner: bannerarr,
        arrpicture: picturearr
      })



    }).catch((err) => {

    })
  },

  //图片预览标准图
  viewImg(e) {
    let that = this;
    let index = e.currentTarget.dataset.index;
  
    wx.previewImage({
      current: that.data.banner[index].url,
      urls: that.data.arrbanner,
      success: function (res) { },
      fail: function (res) { },
      complete: function (res) { },
    })
  },

//图片预览写真图
  viewImg1(e) {
    let that = this;
    let index = e.currentTarget.dataset.index;
    

    wx.previewImage({
      current: that.data.picture[index].url,
      urls: that.data.arrpicture,
      success: function (res) { },
      fail: function (res) { },
      complete: function (res) { },
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {

  },

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

  },

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

  },

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

  },

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

  },

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

  },

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

  }
})