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

  /**
   * 页面的初始数据
   */
  data: {
    url:'',
    imgUrls: ["http://winesbook.cn/static/images_mini/aicon_23@2x.png",
      "http://winesbook.cn/static/images_mini/aicon_23@2x.png",
      "http://winesbook.cn/static/images_mini/aicon_23@2x.png"],
    indicatorDots: false,
    autoplay: false,
    interval: 2000,
    duration: 1000,
    currentSwiper: 0,
    id:'',
    attr:[],
    companyinfo:''

  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({
      url: app.globalData.url,
      id:options.id
    })
    this.getcompanydetail()
  },
  swiperChange: function (e) {
    this.setData({
      currentSwiper: e.detail.current
    })
  },
  //获取企业详情
  getcompanydetail(){
    let that = this;
    let url = 'index/Company/detail', params = {
      id:that.data.id

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

      })

      let newattr = res.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) => {

    })
  },

  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
    })
  },
  //关注和取消关注
  attention(e){
    let that = this;
    let id=e.currentTarget.dataset.id;
    let url = 'index/Common/concern', params = {
      sort:1,
      id:id

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


    }).catch((err) => {

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

  },

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

  },

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

  },

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

  },

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

  },

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

  },

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

  }
})