teachplanlist.js 4.5 KB
// pages/teachplan/teachplanlist/teachplanlist.js
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    imgUrls: [
      'http://bronet.wangshuwen.com/kliuytyt@2x.png',
      'http://bronet.wangshuwen.com/kliuytyt@2x.png',
      'http://bronet.wangshuwen.com/kliuytyt@2x.png'
    ],
    indicatorDots: false,
    autoplay: false,
    interval: 2000,
    duration: 1000,
    currentSwiper: 0,

    navbar: ["综合", "年级", "价格"],
    currentTab: 0,
    list: [],
    goods_list: [],
    listselecthide: false,
    order: '',
    category_id: '',
    grade_id: '',
    page: 1,
    state: ''
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    console.log(options)
    if (options.id == undefined) {
      this.setData({
        category_id: ""
      })
    } else {
      this.setData({
        category_id: options.id
      })
    }


    console.log(options.id)
    this.getlist();
    this.showbtn()
  },
  //是否显示按钮、
  showbtn() {
    let that = this;
    var url = '/home/Welcome/paySwitch';
    var params = {


    }
    app.post(url, params).then((res) => {
      console.log(res);
      that.setData({
        state: res.state
      })



    }).catch((err) => {

    })

  },

  getlist() {
    let that = this;
    var url = '/home/Classify/index2';
    var params = {
      category_id: that.data.category_id,
      order: that.data.order,
      grade_id: that.data.grade_id,
      p: that.data.page

    }
    app.post(url, params).then((res) => {
      console.log(res);
      console.log(res.condition.comprehensive)
      that.setData({
        imgUrls: res.slide,
        list: res,
        goods_list: that.data.goods_list.concat(res.goods_list)
        // comprehensive: that.data.comprehensive.concat(res.condition.comprehensive),
        // grade:that.data.concat(res.condition.grade),
        // price:that.data.price.concat(res.condition.price)




      })



    }).catch((err) => {

    })
  },

  //排序
  rank(e) {
    let that = this;
    let index = e.currentTarget.dataset.idx;
    if (that.data.currentTab == 0) {
      that.setData({
        order: that.data.list.condition.comprehensive[index].order,
        grade_id: '',
        listselecthide: false,
        list: [],
        goods_list: [],
        page: 1
      })

      that.getlist();
    } else if (that.data.currentTab == 1) {
      that.setData({
        order: '',
        grade_id: that.data.list.condition.grade[index].grade_id,
        listselecthide: false,
        list: [],
        goods_list: [],
        page: 1
      })

      that.getlist();
    } else if (that.data.currentTab == 2) {
      that.setData({
        order: that.data.list.condition.price[index].order,
        grade_id: '',
        listselecthide: false,
        list: [],
        goods_list: [],
        page: 1
      })

      that.getlist();
    }


    console.log(that.data.order);
    console.log(that.data.grade_id)
  },

  //隐藏弹层
  listselecthide() {
    this.setData({
      listselecthide: false
    })
  },

  //教学方案列表详情
  detail(e) {
    let id = e.currentTarget.dataset.id;
    let free = e.currentTarget.dataset.free;
    wx.navigateTo({
      url: '../teachplanlistdetail/teachplanlistdetail?id=' + id + '&free=' + free,
    })
    // wx.navigateTo({
    //   url: '../teachplanlistdetail/teachplanlistdetail?id='+id,
    // })
  },
  //跳转搜索页
  search() {
    wx.navigateTo({
      url: '../../searchpage/searchpage',
    })
  },

  swiperChange: function(e) {
    this.setData({
      currentSwiper: e.detail.current
    })
  },
  navbarTap: function(e) {
    this.setData({
      currentTab: e.currentTarget.dataset.idx,
      listselecthide: true

    })

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

  },

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

  },

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

  },

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

  },

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

  },

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

    let page = that.data.page;
    page++;
    that.setData({
      page: page
    })
    that.getlist()
  },

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

  }
})