Newer
Older
smart_construction / miniprogram / pages / indexapp / indexapp.js
dutingting on 12 Dec 2022 5 KB first commit
// miniprogram/pages/indexapp/indexapp.js
var app = getApp()
Page({

  /**
   * 页面的初始数据
   */

  data: {
    count: 1,
    onshow: true,
    value: "",
    deviceloglist: [],
    devcode: "",
    longitude: 113.324520,
    latitude: 23.099994,
    time: 15 * 1000,
    markers: [{
      id: 0,
      // iconPath: "../../images/point.png",
      latitude: 23.099994,
      longitude: 113.324520,
      label:'1',
      width: 50,
      height: 50
    }],
  },


  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
  
  },

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

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

    if (this.data.onshow) {
      this.initPages();
    }
  },

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

  },

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

  },

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

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    this.getlogs(this.data.devcode)
  },

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

  },
  jump: function (event) {
    var that = this;
    var latitude = event.target.dataset.pointLat;
    var longitude = event.target.dataset.pointLon;
    let devcode = event.target.dataset.pointCode;
    that.setData({
      latitude: latitude,
      longitude: longitude,
      markers: [{
        latitude: latitude,
        longitude: longitude,
        callout: {
            display:'ALWAYS',// 常显气泡
            content: devcode,  //名称文本
            color: '#fff',  //文本颜色
            borderRadius: 5,  //边框圆角
            borderWidth: 1,  //边框宽度
            borderColor: '#0060ff',  //边框颜色
            bgColor: '#0060ff',  //背景色
            padding: 5,  //文本边缘留白
            textAlign: 'center'  //文本对齐方式。有效值: left, right, center
          }
      }]
    })
  },
  onClick: function () {
    var _this = this;
    wx.scanCode({
      success(res) {
        var devcode = res.result
        _this.setData({
          devcode: devcode,
          onshow: false
        });
        _this.searchlogs(devcode)
      }
    })
  },

  onSearch: function (event) {
    this.setData({
      devcode: event.detail
    })
    this.searchlogs(event.detail)
  },

  showLoading: function (message) {
    if (wx.showLoading) {
      // 基础库 1.1.0 微信6.5.6版本开始支持,低版本需做兼容处理
      wx.showLoading({
        title: message,
        mask: true
      });
    } else {
      // 低版本采用Toast兼容处理并将时间设为20秒以免自动消失
      wx.showToast({
        title: message,
        icon: 'loading',
        mask: true,
        duration: 20000
      });
    }
  },
  hideLoading: function () {
    if (wx.hideLoading) {
      // 基础库 1.1.0 微信6.5.6版本开始支持,低版本需做兼容处理
      wx.hideLoading();
    } else {
      wx.hideToast();
    }
  },

  //加载设备运维详细信息
  toDetail: function (event) {
    var that = this
    that.showLoading("数据加载中...")
    wx.request({
      method: "POST",
      url: app.globalData.httpsUrl + "appDeviceLog/deviceDetail",
      data: {
        devcode: event.target.dataset.devcode,
      },
      header: {
        'content-type': 'application/x-www-form-urlencoded;charset=utf-8'
      },
      success(res) {
        that.hideLoading();
        var resultObject = res.data;
        var pageName = '../indexapp/indexapp'
        if (resultObject.code == 200) {
            wx.setStorageSync('resultObject', resultObject.data)
          wx.navigateTo({
            url: '../addDevicelog/addDeviceLog?detail=' +'&pageName=' + pageName
          })
        }
      },
      fail(err){
        that.hideLoading();
      }
    })
  },

  //加载列表
  getlogs: function (devcode) {
    var that = this
    wx.request({
      method: "POST",
      url: app.globalData.httpsUrl + "appDeviceLog/listPage",
      data: {
        devcode: devcode,
        limit: 100,
        offset: that.data.deviceloglist.length % 100 > 0 ? parseInt(that.data.deviceloglist.length / 100) + 2 : parseInt(that.data.deviceloglist.length / 100) + 1
      },
      header: {
        'content-type': 'application/x-www-form-urlencoded;charset=utf-8'
      },
      success(res) {
        if (res.data) {
          // var resultJson = JSON.parse(res.result)
          var resultJson = res.data
          that.setData({
            deviceloglist: that.data.deviceloglist.concat(resultJson.data.rows)
          })
        }
      }
    })
  },
  //查询列表
  searchlogs: function (devcode) {
    var that = this
    wx.request({
      method: "POST",
      url: app.globalData.httpsUrl + "appDeviceLog/listPage",
      data: {
        devcode: devcode,
        limit: 100,
        offset: 1
      },
      header: {
        'content-type': 'application/x-www-form-urlencoded;charset=utf-8'
      },
      success(res) {
        if (res.data) {
          var resultJson = res.data
          that.setData({
            deviceloglist: resultJson.data.rows,
            onshow: true
          })
        }
      }
    })
  },

  initPages: function () {
    var that = this;
    wx.getLocation({
      type: "gcj02",
      success: function (res) {
        var latitude = res.latitude;
        var longitude = res.longitude;
        //console.log(res.latitude);
        that.setData({
          latitude: latitude,
          longitude: longitude,
          markers: [{
            latitude: latitude,
            longitude: longitude
          }]
        })
      }
    })
    this.data.devcode !== '' ? this.searchlogs(this.data.devcode) : this.searchlogs()
  },
})