// pages/questionnaire/questionnaireLsit/questionnaireLsit.js
const Http = require("../../../utils/HttpBasics");
var config = require("../../../config/config.js");
var app = getApp();
var app = getApp();
const navigationBarHeight = (getApp().statusBarHeight + 50) + 'px'
Page({

  /**
   * 页面的初始数据
   */
  data: {
    navigationBarHeight,
    list: [],
    pageNum: 1,
    pageSize: 4,
    thenDate:"",
  },
  goDetails(e){
    let id = e.currentTarget.dataset.id
    console.log(id)
    tt.navigateTo({
      url: `/pages/questionnaire/questionnaire?id=${id}`,
    })
  },
  getQuest() { //查询问卷
    let param = {
      pageNum: this.data.pageNum,
      pageSize: this.data.pageSize
    }
    Http.get({
      url: config.api.questionnaire,
      data: param
    }).then(res => {
      if(this.data.pageNum<=1){
        let temp = res.data.list
        this.setData({
          list: temp
        })
      }else{
        let temp = res.data.list
        let formerLsit = this.data.list
        formerLsit.push(...temp)
        this.setData({
          list:formerLsit
        })
      }
      }).catch(err=>{
        tt.showToast({
          title: err.errMsg,
          icon: 'none',
          duration: 2000,
          // mask: false
        });
      })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    
  },

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

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    this.getQuest()
    this.setData({
      thenDate: new Date().getTime()
    })
  },

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

  },

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

  },

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

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    console.log("我到底了！")
    let pageNumFlge = this.data.pageNum+1
    this.setData({
      pageNum: pageNumFlge
    })
    this.getQuest()

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
    var that = this;
    var shareObj = {
      title: "问卷调查",
      path: `/pages/main/index?&type=wjLsit`,
      success: function (res) {
        if (res.errMsg == 'shareAppMessage:ok') { }
      },
      fail: function (error) {
        if (res.errMsg == 'shareAppMessage:fail cancel') { } else if (res.errMsg == 'shareAppMessage:fail') { }
      }
    };
    console.log(shareObj)
    // 返回shareObj
    return shareObj;
  }
})