Volunteer_dynamic.js 1.4 KB
const app = getApp();
Page({
  data: {
    navbar: [],
    currentTab: 1,
    list: [],


  },
  //切换navbar
  navbarTap: function (e) {
    console.log(e)
    this.setData({
      currentTab: e.currentTarget.dataset.id
    })

    //全局变量
    // app.globalData.currentTab = e.currentTarget.dataset.id;
    this.getactive();
  },
  onShow() {
    // this.setData({
    //   currentTab: app.globalData.currentTab
    // })

    let that = this;
    that.getNewsType()
    that.getactive();

  },

  onLoad: function () {

  },
  // 志愿动态栏目类型
  getNewsType() {
    let that = this;
    let url = '/index/second/getNewsType';
    let head = {
      'XX-Token': wx.getStorageSync('token')
    }
    app.post(url, head).then((res) => {
      console.log(res)
      that.setData({
        navbar: res,

      })
    }).catch((err) => {

    })

  },

  // 列表
  getactive() {

    let that = this;
    let url = '/index/second/getNewsList';
    let head = {
      'XX-Token': wx.getStorageSync('token')
    }
    let params = {

      type_id: that.data.currentTab

    }
    console.log(params)
    app.post(url, params, head).then((res) => {
      // console.log(res)
      that.setData({
        list: res
      })
    }).catch((err) => {
    })

  },

  // 列表详情
  getNewsInfo(e) {
    var id = e.currentTarget.dataset.id
    wx.navigateTo({
      url: '/pages/getNewsInfo/getNewsInfo?id=' + id,
    })
  }





})