// packageE/questionnaire/history_details/history_details.js
var app = getApp();
var int = (app.globalData.statusBarHeight * 2) + 20;
Page({

  /**
   * 页面的初始数据
   */
  data: {
    statusBarHeight: int,
    page:1
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    if (options.id) {
      this.setData({
        id: options.id
      });
    }
    if (options.questionnaire_id) {
      this.setData({
        questionnaire_id: options.questionnaire_id
      });
    }
    this._detail();
  },
  back() {
    wx.navigateBack({
      delta: 1,
    });
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

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

  },

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

  },

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

  },

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

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    if (this.data.current_page >= this.data.last_page) {
      return;
    } else {
      let pages = 1 + this.data.page;
      this.setData({
        page:pages
      });
      // this.getMoreData();
    }
  },

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

  },
  getMoreData() {
    let that = this;
    let urlStr = app.getNetAddresss("plugin.questionnaire.api.index.indexInfo");
    app._getNetWork({
      url: urlStr,
      data: {
        details: 'details',
        record_id: that.data.id,
        questionnaire_id: that.data.questionnaire_id,
        page: that.data.page
      },
      success: function (resdata) {
        var res = resdata.data;
        console.log(res);
        if (res.result == 1) {
          that.setData({
            choice: that.data.choice.concat(res.data.details.choice.data),
            record: res.data.details.record.answers,
            current_page: res.data.details.choice.current_page,
            last_page: res.data.details.choice.last_page,
            title:res.data.details.record.has_one_questionnaire.title
          });
        } else {
          wx.showToast({
            icon: 'none',
            title: res.msg,
            duration: 1500
          });

        }
      },
      fail: function (res) {
        console.log(res);
      }
    });
  },
  _detail(e) {
    let that = this;
    let urlStr = app.getNetAddresss("plugin.questionnaire.api.index.indexInfo");
    app._getNetWork({
      url: urlStr,
      data: {
        details: 'details',
        record_id: that.data.id,
        questionnaire_id: that.data.questionnaire_id,
        page:that.data.page
      },
      success: function (resdata) {
        var res = resdata.data;
        console.log(res);
        if (res.result == 1) {
          that.setData({
            choice: res.data.details.choice,
            record: res.data.details.record.answers,
            current_page: res.data.details.choice.current_page,
            last_page: res.data.details.choice.last_page,
            title:res.data.details.record.has_one_questionnaire.title
          });
        } else {
          wx.showToast({
            icon: 'none',
            title: res.msg,
            duration: 1500
          });

        }
      },
      fail: function (res) {
        console.log(res);
      }
    });
  }
});