// pages/find/find.js
const app=getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    imgUrls: ['http://winesbook.cn/static/images_mini/aicon_60@2x.png',
    'http://winesbook.cn/static/images_mini/aicon_60@2x.png'
    ],
    indicatorDots: false,
    autoplay: true,
    interval: 2000,
    duration: 1000,
    currentSwiper: 0,
    banner:[],
    list:[],
    news: []
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    let that=this;
    setTimeout(function(){
      that.setData({
        url: app.globalData.url
      })
    },1000)
   

    
  },

  //获取发现列表
  getfindlist(){

    let that = this;
    let url = 'index/Find/index', params = {
      

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

      console.log(that.data.news)
      console.log(that.data.list)



    }).catch((err) => {

    })

  },
  swiperChange: function (e) {
    this.setData({
      currentSwiper: e.detail.current
    })
  },
//跳页
  jump(e){
    let type=e.currentTarget.dataset.type;
    let id=e.currentTarget.dataset.id
    console.log(type)
    if(type==1){
      wx.navigateTo({
        url: '/pages/findblock/jiulist/jiulist?type='+type,
      })
    }else if(type==2){
      wx.navigateTo({
        url: '/pages/findblock/zhuanjiapinjiu/zhuanjiapinjiu',
      })
    } else if (type == 3) {
      wx.navigateTo({
        url: '/pages/findblock/niangjiushi/niangjiushi',
      })
    } else if (type == 4){
      wx.navigateTo({
        url: '/pages/findblock/putongwenzhang/putongwenzhang?id='+id,
      })
    }
  },
  //进入视频
  entervideo(e){
    let url=e.currentTarget.dataset.url;
    wx.navigateTo({
      url: '/pages/homeblock/video/video?url='+url,
    })
  },
  //每日新酒发布
  everyjiu(){
    wx.navigateTo({
      url: '/pages/findblock/meirixinjiu/meirixinjiu',
    })
  },
  //点赞和取消点赞
  dianzan(e){
    let id=e.currentTarget.dataset.id;
    let userid=e.currentTarget.dataset.userid;
    let winemaker_id = e.currentTarget.dataset.winemaker_id
    console.log(winemaker_id)
    let type=e.currentTarget.dataset.type;
    let chuanid = type == 1 ? userid : type == 2 ? id : type == 3 ? winemaker_id:id
    let that = this;
    let url = 'index/Common/good', params = {
      sort: type,
      id: chuanid

    }
    app.post(url, params).then((res) => {
      console.log(res);
      wx.showToast({
        title: res,
        icon:'none'
      })


      that.getfindlist()


    }).catch((err) => {

      })

  },
  //进入评论页面
  ping(e){
    let id=e.currentTarget.dataset.id;
    let type=e.currentTarget.dataset.type;
    let winemaker_id = e.currentTarget.dataset.winemaker_id
    wx.navigateTo({
      url: '/pages/myblock/pingjia/pingjia?type=' + type + '&id=' + id + '&winemaker_id=' + winemaker_id,
    })
  },

  //新闻详情页
  jumpnewdetail(e){
    let id=e.currentTarget.dataset.id
    wx.navigateTo({
      url: '/pages/homeblock/jiuzidian/jiuzidian?id=' + id,
    })
  },
  //酒单推荐详情页
  enterdetail(e){
    let id=e.currentTarget.dataset.id;
    let type=e.currentTarget.dataset.type;
    let winemaker_id = e.currentTarget.dataset.winemaker_id
    if(type==1){
      wx.navigateTo({
        url: '/pages/findblock/jiudandetail/jiudandetail?id=' + id,
      })
    }else if(type==2){
      wx.navigateTo({
        url: '/pages/findblock/zhuanjiapinjiudetail/zhuanjiapinjiudetail?id=' + id,
      })
    }else if(type==3){
      wx.navigateTo({
        url: '/pages/homeblock/niangjiuteacher/niangjiuteacher?id=' + winemaker_id,
      })
    }else{
      wx.navigateTo({
        url: '/pages/findblock/wenzhangdetail/wenzhangdetail?id=' + id,
      })
    }

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

  },

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

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

  },

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

  },

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

  },

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

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function (e) {
    console.log(9090)
    let that = this;
    console.log(e)
    let id=e.target.dataset.id;
    console.log(id)
    let type=e.target.dataset.type;
    let url=''
    let winemaker_id = e.target.dataset.winemaker_id;
   
   
    if(type==1){
      url = '/pages/findblock/jiudandetail/jiudandetail?id=' + id
    }else if(type==2){
      url = '/pages/findblock/zhuanjiapinjiudetail/zhuanjiapinjiudetail?id=' + id
    }else if(type==3){
      url = '/pages/homeblock/niangjiuteacher/niangjiuteacher?id=' + winemaker_id
    }else if(type==4){
      url = '/pages/findblock/wenzhangdetail/wenzhangdetail?id=' + id
    }
    
    
    return {
      title: '发现', // 转发后 所显示的title
      // path: '/pages/home/buildtextdetail/buildtextdetail?buildid='+buildid+'&gettoken='+newtoken, // 相对的路径

      path: url,//建档攻略分享1
      // path:'',
      success: (res) => {    // 成功后要做的事情
        console.log(res)
       
      },
      fail: function (res) {
        // 分享失败
        console.log(res)
      }
    }
  
  }
})