dangjianwork.js 4.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,
    noMore: !1,
    top:'',
    interval: 2000,
    duration: 1000,
    currentSwiper:0,
    indicatorDots: false,
    autoplay: true,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  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
    })

  },
  //获取轮播图
  getopbanner() {
    let that=this
    let url = '/api/Article/getSlideList';
    app.post(url, {}).then(r => {
      console.log(r)
      this.setData({
        imgUrls: r
      })

      if(r.length==0){
        that.setData({
          top:'50px'
        })
      }else{
        that.setData({
          top:'195px'
        })
      }
    })
    console.log(that.data.top)
    console.log(this.data.imgUrls)
  },
  getBanner() {
    let url = '/api/Article/getAttractInvestmentBanner';
    app.post(url, {}).then(r => {
      this.setData({
        banner: r.banner
      })
    })
  },
  policyType() {
    let url = '/api/Party/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 t = this, url = '/api/Party/index', params = {
      category_id: id,
      page: page,
      header: true
    }, list = page == 1 ? [] : t.data.list; app.post(url, params).then((res) => {
      console.log(res)
      t.setData({
        list: list.concat(res.data),
        page: res.current_page,
        lastPage: res.last_page,
        ifData: !0,
        noMore: res.last_page == res.current_page ? !0 : !1
      })
      !t.data.list.concat(res.data).length ? t.setData({
        ifData: !1
      }) : ''
      wx.stopPullDownRefresh();
    })
  },
  bannerDetail(e) {
    let url = e.currentTarget.dataset.src
    console.log(url)
    wx.setStorageSync('tempArticle', e.currentTarget.dataset.content)
    wx.navigateTo({
      //url: '/' + url + '?id=' + e.currentTarget.dataset.id,
      url: '/pages/attract/dangjianbannerdetail/dangjianbannerdetail?name=' + e.currentTarget.dataset.title 
      // + '&content=' + JSON.stringify(e.currentTarget.dataset.content)
    })
  },

  getUserInfo() {
    let d = this, url = '/api/user/index';
    app.post(url, {}).then((r) => {
      console.log(r.noticeNum)
      d.setData({ userInfo: r.userInfo, noticeNum: r.noticeNum })
      if (r.noticeNum != 0) {
        let num = r.noticeNum
        num = num.toString()
        wx.setTabBarBadge({
          index: 4,
          text: num
        })
      } else {
        wx.hideTabBarRedDot({
          index: 4,
        })
      }
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成  v   
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    this.getopbanner();
    this.getUserInfo()
  },

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

  },

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

  },

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

    t.getopbanner();
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  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: '没有更多了',
      icon:'none'
    })
  },

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

  }
})