download.js 3.6 KB
// pages/download/download.js
const app=getApp()
Page({

 /**
  * 页面的初始数据
  */
 data: {
   navbar: ["阅读", "考试", "写作", "语法", "免费资源", "免费资源", "免费资源", "免费资源"],
   currentTab: 0,
   keyword:'',
   category_id:'',
   is_free:0,

   downlist:[],
   page:1,
   state:""

 },

 /**
  * 生命周期函数--监听页面加载
  */
 onLoad: function (options) {
   this.mydownload();
   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) => {

    })

  },

 //输入关键字
  enterword(e){
    this.setData({
      keyword:e.detail.value,
      downlist:[],
      page:1,
    })
    this.mydownload()
  },

 mydownload(){
   let that = this;
   var url = '/home/Center/download';
   var params = {

     keyword: that.data.keyword,
     category_id: that.data.category_id,
     is_free: that.data.is_free,
     p:that.data.page
   }

   var header={
     'XX-Token': wx.getStorageSync('token'),
     'XX-Device-Type':'wxapp'
   }
   app.post(url, params,header).then((res) => {
     console.log(res);
     that.setData({
       navbar: res.category,
       downlist: that.data.downlist.concat(res.list)
     })



   }).catch((err) => {

   })
 },
  navbarTap: function (e) {
    let free=e.currentTarget.dataset.free;
    let category_id = e.currentTarget.dataset.id;
   
    if(free==undefined){
      this.setData({
        page: 1,
        currentTab: e.currentTarget.dataset.idx,
        category_id: e.currentTarget.dataset.id,
        is_free: '',
        downlist: []
      })
     

      this.mydownload()
    }else{
      console.log(8080)
      this.setData({
        page: 1,
        currentTab: e.currentTarget.dataset.idx,
        category_id:'',
        is_free: e.currentTarget.dataset.free,
        downlist: []
      })
       this.mydownload()
    }

   

    // if (e.currentTarget.dataset.idx==6){
    //   this.setData({
    //     page:1,
    //     currentTab: e.currentTarget.dataset.idx,
    //     category_id: '',
    //     is_free: e.currentTarget.dataset.free,
    //     downlist:[]
    //   })
    // }else{
    //   this.setData({
    //     page: 1,
    //     currentTab: e.currentTarget.dataset.idx,
    //     category_id: e.currentTarget.dataset.id,
    //     is_free:'',
    //     downlist:[]
    //   })

    // }

    
  },

  entercomment(e){
    let id=e.currentTarget.dataset.id;
    wx.navigateTo({
      url: '../comment/comment?id='+id,
    })
  },

  //教学方案列表详情
  detail(e) {
    console.log(e)
    let id = e.currentTarget.dataset.id;
    let free = e.currentTarget.dataset.free;
    wx.navigateTo({
      url: '../teachplan/teachplanlistdetail/teachplanlistdetail?id=' + id + '&free=' + free,
    })
  },
 /**
  * 生命周期函数--监听页面初次渲染完成
  */
 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.mydownload()
 },

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

 }
})