attract.js 2.7 KB
// pages/attract/attract.js
const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    policyList: [
      // {
      //   "id": "",
      //   "name": "全部",
      //   "weigh": "权重",
      //   "status": "状态"
      // }
    ],
    navScrollLeft:0,
    currentTab: 0,
    page: 1,
    list:[],
    ifData:!1
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    wx.getSystemInfo({
      success: (res) => {
        this.setData({
          pixelRatio: res.pixelRatio,
          windowHeight: res.windowHeight,
          windowWidth: res.windowWidth,
          tabWidth: res.windowWidth -  39
        })
      },
    }), this.policyType();
  },
  policyType(){
    let url = '/api/Article/category',a = this;
    app.post(url,{header: true}).then((res)=>{
      a.setData({ 
        policyList:a.data.policyList.concat(res),
        category_id: res[0].id
      })
      a.getList(res[0].id,1)
    })
  },
  btn_matrix(){
    wx.navigateTo({
      url: '/pages/matrix/article/article',
    })
  },
  chooseLocation(){
    wx.chooseLocation({
      success: function(res) {},
    })
  },
  switchTab(e){
    let b = this,singlewidth = b.data.tabWidth/5,cur = e.currentTarget.dataset.current;
    b.setData({
      navScrollLeft:(cur-2)*singlewidth,
      category_id: e.currentTarget.id,
      page:1,
      list:[]
    }),b.data.currentTab != cur?b.setData({
      currentTab: cur
      }) : '', b.getList(e.currentTarget.id,1)
  },
  getList(id,page){
    let e = this, url = '/api/Article/index',params = {
      category_id: id,
      page: page,
      header: true
    };app.post(url,params).then((res)=>{
      e.setData({
        list: e.data.list.concat(res.data),
        page: res.current_page,
        lastPage: res.last_page,
        ifData: !0
      })
      !e.data.list.concat(res.data).length?e.setData({
        ifData:!1
      }):''
    })
  },
  bannerDetail(e){
    wx.navigateTo({
      url: '/pages/attract/detail/detail?id='+e.currentTarget.id,
    })
  },

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

  },

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

  },

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

  },

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

  },

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

  },

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

  },

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

  }
})