// miniprogram/pages/indexapp/indexapp.js var app = getApp() Page({ /** * 页面的初始数据 */ data: { count:1, show: false, 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, width: 50, height: 50 }], }, /** * 生命周期函数--监听页面加载 */ onLoad: function (options) { }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady: function () { }, /** * 生命周期函数--监听页面显示 */ onShow: function () { // if( app.globalData.indexCount>1){ // this.setData({ // show:false // }) // }else{ // this.showNotice() // } if(app.globalData.indexCount==1){ this.setData({ show:true }) this.showNotice() } app.globalData.indexCount+=1 if(this.data.onshow){ this.initPages(); } }, showNotice: function() { var that = this var times = 0 var i = setInterval(function() { times++ if (times >= 15) { that.setData({ show:false }) wx.showTabBar({ animation: false, }) clearInterval(i) } else { wx.hideTabBar({ animation: false, }) } }, 1000) }, /** * 生命周期函数--监听页面隐藏 */ 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; that.setData({ latitude: latitude, longitude: longitude, markers: [{ latitude: latitude, longitude: longitude }] }) }, 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) }, // bindregionchange: function (e) { // var that = this // if (e.causedBy == "drag") { // var mapCtx = wx.createMapContext("map") // mapCtx.getCenterLocation({ // success: function (res) { // var markersArr = that.data.markers // for (var i = 0; i < markersArr.length; i++) { // if (markersArr[i].iconPath == undefined) { // markersArr.splice(i, 1) // } // } // var latitude = res.latitude // var longitude = res.longitude // markersArr = markersArr.concat({ // latitude: latitude, // longitude: longitude // }) // that.setData({ // latitude: latitude, // longitude: longitude, // markers: markersArr // }) // } // }) // } // }, 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) { this.showLoading("数据加载中...") wx.cloud.callFunction({ name: 'deviceDetail', data: { devcode: event.target.dataset.devcode, url: app.globalData.url + "appDeviceLog/deviceDetail", }, }).then(res => { this.hideLoading(); var resultObject = JSON.parse(res.result); var pageName='../indexapp/indexapp' if (resultObject.code == 200) { wx.navigateTo({ url: '../addDevicelog/addDeviceLog?detail=' + JSON.stringify(resultObject.data)+'&pageName='+pageName }) } }).catch(err => { this.hideLoading(); }) }, getlogs: function (devcode) { var that = this wx.cloud.callFunction({ name: 'devicelog', data: { devcode: devcode, url: app.globalData.url + "appDeviceLog/listPage", limit: 100, offset: that.data.deviceloglist.length % 100 > 0 ? parseInt(that.data.deviceloglist.length / 100) + 2 : parseInt(that.data.deviceloglist.length / 100) + 1 }, }).then(res => { if (res.result) { // var resultJson = JSON.parse(res.result) var resultJson = res.result that.setData({ deviceloglist: that.data.deviceloglist.concat(resultJson.data.rows) }) } console.log(res); }).catch(err => { console.error(err); }) }, searchlogs: function (devcode) { var that = this wx.cloud.callFunction({ name: 'devicelog', data: { devcode: devcode, url: app.globalData.url + "appDeviceLog/listPage", limit: 100, offset: 1 }, }).then(res => { if (res.result) { var resultJson = res.result that.setData({ deviceloglist: resultJson.data.rows, onshow:true }) } console.log(res); }).catch(err => { console.error(err); }) }, initPages: function () { var that = this; that.setData({ devcode: "" }); 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.searchlogs() }, })