brandpage.js 2.8 KB
// pages/homeblock/brandpage/brandpage.js
 var WxParse = require('../../../wxParse/wxParse.js');
const app=getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    url:"",
    id:'',
    detailinfo:'',
    attr:[]
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({
      url: app.globalData.url,
      id:options.id
    })
    this.getbrandtail()
  },
  //获取品牌详情页
  getbrandtail(){
    let that = this;
    let url = 'index/Brand/detail', params = {
    id:that.data.id

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

      })
      let newattr = res.info.attr;
      for (let i = 0; i < newattr.length; i++) {
        newattr[i].show=true

        WxParse.wxParse('content' + i, 'html', newattr[i]['content'], that, 5);

        if (i === newattr.length - 1) {

          WxParse.wxParseTemArray("artileList", 'content', newattr.length, that)
        }
      }

      that.setData({
        attr: newattr
      })

    }).catch((err) => {

    })
  },
  //收藏
  collect(e){
    let id=e.currentTarget.dataset.id;
    let that = this;
    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'
      })
      that.getbrandtail()




    }).catch((err) => {

    })

  },
  //关注和取消关注
  attention(e){
    let id=e.currentTarget.dataset.id;
    let that = this;
    let url = 'index/Common/concern', params = {
      sort:1,
      id:id

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


    }).catch((err) => {

    })
  },
  showinfo(e){
    let idx=e.currentTarget.dataset.idx;
    console.log(idx)
    let newattr = this.data.attr;
    for (var i = 0; i < newattr.length;i++){
      if(i==idx){
        newattr[i].show = !newattr[i].show
      }
    }
    this.setData({
      attr:newattr
    })
    console.log(this.data.attr)
  },  
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

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

  },

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

  },

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

  },

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

  },

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

  },

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

  }
})