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

  /**
   * 页面的初始数据
   */
  data: {
    policyList: [
      // {
      //   "id": "",
      //   "name": "全部",
      //   "weigh": "权重",
      //   "status": "状态"
      // }
    ],
    navScrollLeft:0,
    currentTab: 0,
    page: 1,
    list:[],
    ifData:!1,
    noMore:!1,
    imgUrls: ['http://txgyy.jjjtech.cn/uploads/20190409/7f686056aea2291e40351b38e8ef9a08.png',
    'http://txgyy.jjjtech.cn/uploads/20190409/7f686056aea2291e40351b38e8ef9a08.png'
    ],
    indicatorDots: false,
    autoplay: false,
    interval: 2000,
    duration: 1000,
    currentSwiper: 0,

  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    wx.getSystemInfo({
      success: (res) => {
        this.setData({
          pixelRatio: res.pixelRatio,
          windowHeight: res.windowHeight,
          windowWidth: res.windowWidth,
          tabWidth: res.windowWidth -  39
        })
      }
    }), this.policyType(), this.getBanner();
  },

  //轮播图
  swiperChange: function (e) {
    this.setData({
      currentSwiper: e.detail.current
    })
  },
  getBanner(){
    let url = '/api/Article/getAttractInvestmentBanner';
    app.post(url,{}).then(r=>{
      console.log(r)
      this.setData({
        banner: r.banner
      })
    })
  },
  policyType(){
    let url = '/api/Article/category',a = this;
    app.post(url,{header: true}).then((res)=>{
      a.setData({ 
        policyList:res,
        category_id: res[0].id
      })
      a.getList(res[0].id,1)
    })
  },  
  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
    }, list = page == 1 ? [] : t.data.list;app.post(url,params).then((res)=>{
      e.setData({
        list: list.concat(res.data),
        page: res.current_page,
        lastPage: res.last_page,
        ifData: !0,
        noMore: res.last_page==res.per_page?!0:!1
      })
      !e.data.list.concat(res.data).length?e.setData({
        ifData:!1
      }):''
      wx.stopPullDownRefresh();
    })
  },
  bannerDetail(e){
    wx.navigateTo({
      url: '/pages/attract/detail/detail?id='+e.currentTarget.id,
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成  v   
   */
  onReady: function () {

  },

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

  },

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

  },

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

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    let t = this;
    t.setData({
      page:1
    })
    t.getList(t.data.category_id,1)
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    let t = this;
    !t.data.noMore ? (t.setData({
      page:t.data.page+1
    }),t.getList(t.data.category_id,t.data.page)) : wx.showToast({
      title: '没有更多了',
    }) 
  },

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

  }
})