Newer
Older
smart_construction / miniprogram / pages / applog / applog.js
zhout on 16 Jun 2020 1 KB 初版提交
// miniprogram/pages/applog/applog.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    deviceloglist: []
  },


  /**
   * 生命周期函数--监听页面加载var_this=this;
   */
  onLoad: function (options) {
    if (options.applogList) {
      var _this = this;
      _this.setData({
        deviceloglist: JSON.parse(options.applogList)
      })
    } else {
      wx.cloud.callFunction({
        name: 'devicelog'
      }).then(res => {
        var that = this;
        that.setData({
          deviceloglist: res.result.data.rows
        })
        console.log(res);
      }).catch(err => {
        console.error(err);
      })
    }
  },

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

  },

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

  },

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

  },

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

  },

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

  },

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

  },

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

  },

  add: function (event) {

    wx.cloud.callFunction({
      name: 'deviceDetail',
      data: {
        devcode: event.target.dataset.devcode,
      },
    }).then(res => {
      if (res.result.code == 200) {
        wx.reLaunch({
          url: '../addDevicelog/addDeviceLog?detail=' +
            JSON.stringify(res.result.data)
        })
      }
    }).catch(err => {
      console.error(err);
      wx.showToast({
        title: "加载失败",
      })
    })
  },
  onSearch: function () {
    wx.navigateTo({
      url: '../searchLog/searchLog'
    })
  }
})