active.js 3.5 KB
const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    city_id: '',
    clickIndex: true,
    index:0,
    datalist: [],
    activity_page: 0,
    activity: [],
    city_arr: [],
    city_arrid: [],
    class_arr: [],
    class_arrid: [],
    city:'选择城市',
    category: '选择分类',
  },
  selecteCtiy(e){
    this.setData({
      city: this.data.city_arr[e.detail.value],
      city_id: this.data.city_arrid[e.detail.value]
    })
    this.city_active()
  },
  selecteClass(e) {
    this.setData({
      category: this.data.class_arr[e.detail.value],
      type: this.data.class_arrid[e.detail.value]
    })
    this.type_active()
  },
  /**
   * 切换
   */
  clicktab(e) {
    let that = this
    let id = e.currentTarget.dataset.id
    if (id == '2') {
      that.setData({
        clickIndexs: true,
        clickIndex: false
      })
    } else if (id == '1') {
      that.setData({
        clickIndexs: false,
        clickIndex: true
      })
    }
    //调用接口
  },
  //获取城市列表
  get_city(){
    let that = this;
    let url = '/index/index/cityList'
    let head = {
      'XX-Token': wx.getStorageSync('token')
    }
    
    app.post(url, {}, head).then((res) => {
       
      that.setData({
        city_arr: res.city,
        city_arrid: res.id
      })
    }).catch((err) => {
      
    })
  },
  //获取分类列表
  get_class() {
    let that = this;
    let url = '/index/index/activityType';
    let head = {
      'XX-Token': wx.getStorageSync('token')
    }
    app.post(url, {}, head).then((res) => {
      
      that.setData({
        class_arr: res.type_name,
        class_arrid: res.id
      })
    }).catch((err) => {
      
    })
  },
  //获取城市活动
  city_active(){
    let that = this;
    let url = '/index/index/cityGetActivity';
    let head = {
      'XX-Token': wx.getStorageSync('token')
    }
   
    let params = {
      city_id: that.data.city_id
    }
    if (that.data.end_type) {
      params.end = 1
    }
    app.post(url, params, head).then((res) => {
       
      that.setData({
        activity: res
      })
    }).catch((err) => {
      
    })
  },

  //获取分类活动
  type_active() {
    let that = this;
    let url = '/index/index/typeGetActivity';
    let head = {
      'XX-Token': wx.getStorageSync('token')
    }
    let params = {
      type: that.data.type
    }
    if (that.data.end_type) {
      params.end = 1
    }
    app.post(url, params, head).then((res) => {
       
      that.setData({
        activity: res
      })
    }).catch((err) => {
      
    })
  },

 
 
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    let that = this
    if (options.end_type){
      that.setData({
        end_type: 1
      })
    }
    that.get_city()
    that.get_class()
    that.city_active()
  },

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

  },

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

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

  },

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

  },

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

  },

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

  },

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

  }
})