brandlist.js 3.7 KB
// pages/homeblock/brandlist/brandlist.js
const app=getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    navbar: ['在售','预售','停产在售','停售'],
    currentTab: 0,
    url:"",
    status:1,
    brandid:'',
    page:1,
    info:'',
    brandlist:[]

  },

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

    this.getbrandlist()
  },
  navbarTap: function (e) {
    this.setData({
      currentTab: e.currentTarget.dataset.idx,
      
      status:e.currentTarget.dataset.idx+1

    })
    this.setData({
      page:1,
      brandlist:[]
    })
    this.getbrandlist()
    
  },

  //获取品牌主主页
  getbrandlist(){
    let that = this;
    let url = 'index/Brand/index', params = {
      status: that.data.status,
      id: that.data.brandid,
      page:that.data.page


    }
    app.post(url, params).then((res) => {
      console.log(res);
      that.setData({
        info: res.info,
        brandlist:that.data.brandlist.concat(res.list)
      })



    }).catch((err) => {

    })

  },
  //收藏品牌
  collectbrand(e){
    let that = this;
    let id=e.currentTarget.dataset.id

    let url = 'index/Common/favorite', params = {
      sort: 2,
      id:id
    }
    app.post(url, params).then((res) => {
      console.log(res);
      wx.showToast({
        title: res,
        icon:'none',
       
      })
      let newinfo=that.data.info;
      if (newinfo.is_favorite==0){
        newinfo.is_favorite=1
      }else{
        newinfo.is_favorite = 0
      }
      that.setData({
        info:newinfo
      })
      // that.setData({
      //   page: 1,
      //   brandlist: []
      // })
      // that.getbrandlist()


    }).catch((err) => {

    })
  },
//收藏酒品
  collectwine(e){
    
    let that = this;
    let id = e.currentTarget.dataset.id;
    let url = 'index/Common/favorite', params = {
      sort:1,
      id:id

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

      let newbrandlist=that.data.brandlist;
      console.log(newbrandlist)
      console.log(id)
      for (var obj of newbrandlist){
       
          if(obj.id==id){
            console.log(888)
            if (obj.is_favorite==0){
              obj.is_favorite=1
            } else {
              obj.is_favorite = 0
            }
          }
      }
      that.setData({
        brandlist: newbrandlist
      })


    }).catch((err) => {

      })


  },
  //品牌详情页
  brandinfo(e){
    let id=e.currentTarget.dataset.id;
    wx.navigateTo({
      url: '/pages/homeblock/brandpage/brandpage?id='+id,
    })
  },
  jumpbrand(e) {
    let id = e.currentTarget.dataset.id
    wx.navigateTo({
      url: '/pages/homeblock/jiuzidian/jiuzidian?id=' + id,
    })
    

  },

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

  },

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

  },

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

  },

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

  },

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

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    let page=this.data.page;
    page++;
    this.setData({
      page:page
    })

    this.getbrandlist()
  },

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

  }
})