// pages/report/report.js var app = getApp(); Page({ /** * 页面的初始数据 */ data: { show: false, popBoxTitle: '', popBoxDesc: '', headUrl: '', includepoints: [], longitude: 113.25222251985, latitude: 39.995607421389, markers: [], loactionList: [], reportTempInputValue: '', reportDesc: '', hiddenmodalput: true, nickTempInputValue: '', reportInputFocus: false, openid: '', locationid: '', location: '', city: '北京', scale: 10, orgName: '', orgId: '', projectList: [], reportCacheTime: '' }, /** * 生命周期函数--监听页面加载 */ onLoad: function (options) { this.data.openid = wx.getStorageSync('openid'); const lng = wx.getStorageSync('report_cache_lng'); const lat = wx.getStorageSync('report_cache_lat'); if (lng != null && lat != null && lng.length > 0 && lat.length > 0) { const reportCacheTime = wx.getStorageSync('reportCacheTime'); this.setData({ show: true, reportCacheTime: reportCacheTime }) } this.getLocation(); }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady: function () { }, /** * 生命周期函数--监听页面显示 */ onShow: function () { const lng = wx.getStorageSync('report_cache_lng'); const lat = wx.getStorageSync('report_cache_lat'); if (lng != null && lat != null && lng.length > 0 && lat.length > 0) { const reportCacheTime = wx.getStorageSync('reportCacheTime'); this.setData({ show: true, reportCacheTime: reportCacheTime }) } else { this.setData({ show: false }) } }, /** * 生命周期函数--监听页面隐藏 */ onHide: function () { }, /** * 生命周期函数--监听页面卸载 */ onUnload: function () { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh: function () { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom: function () { }, /** * 用户点击右上角分享 */ onShareAppMessage: function () { }, touchMap: function (e) { this.setData({ show: false }) }, orgSelectEvent: function (e) { wx.navigateTo({ url: "/pages/org/org" }); }, markertapHandle: function (e) { var location = this.data.loactionList[e.markerId]; this.setData({ headUrl: app.globalData.imageBase + "/" + location.headIcon, show: true, popBoxTitle: location.nick == null ? '' : location.nick, popBoxDesc: location.reportDesc, locationid: location.index }) }, reportWorkDetailHandle: function (e) { // var index = e.currentTarget.dataset.locationid; // var location = this.data.loactionList[index]; // var nick = location.nick == null || location.nick == undefined ? '' : location.nick; // this.setData({ // show: false // }) wx.navigateTo({ url: "/pages/report/rtuConstructionReport/rtuConstructionReport?type=1&address=" + this.data.location + "&weather=" + this.data.weatherInfo + "&lng=" + this.data.longitude + "&lat=" + this.data.latitude }) }, continueReportHandle: function (e) { wx.navigateTo({ url: "/pages/report/rtuConstructionReport/rtuConstructionReport?type=2" }) }, reportMyLocation: function (e) { var openid = wx.getStorageSync('openid'); var that = this; var url = app.globalData.cloudBase + "/cloud/Buy/ReportMyLocation"; wx.request({ url: url, method: 'GET', header: { "Content-Type": "json" }, data: { openid: openid, lon: this.data.longitude, lat: this.data.latitude, desc: this.data.reportTempInputValue }, success: function (res) { console.debug(res.data); if (res.data.status === "ok") { that.setData({ reportDesc: '' }); that.getLocationReportList(); } }, fail: function (error) { console.log(error) } }) }, reportInputHandle: function (e) { var url = "/pages/index/publish/publishPhoto?address=" + this.data.location + "&orgId=" + this.data.orgId + "&orgName=" + this.data.orgName + "&weather=" + this.data.weatherInfo + "&lng=" + this.data.longitude + "&lat=" + this.data.latitude; wx.navigateTo({ url: url }); // this.setData({ // reportTempInputValue: e.detail.value // }) }, nickCancelHandle: function () { this.setData({ hiddenmodalput: true }); }, nickConfirmHandle: function () { this.setData({ hiddenmodalput: true }) if (this.data.nickTempInputValue !== '' && this.data.nickTempInputValue !== null) { var that = this; var url = app.globalData.cloudBase + "/cloud/Wx/UpdateNick"; wx.request({ url: url, method: 'GET', data: { openid: this.data.openid, nick: this.data.nickTempInputValue }, header: { "Content-Type": "json" }, success: function (res) { if (res.data.status === "ok") { that.setData({ reportInputFocus: true }); } }, fail: function (error) { console.log(error) } }) } }, bindNickInputHandle: function (e) { this.setData({ nickTempInputValue: e.detail.value }) }, getProjectList: function () { wx.showNavigationBarLoading() var that = this; var url = app.globalData.cloudBase + "/Wx/User/Project/" + this.data.openid; wx.request({ url: url, method: 'GET', header: { "Content-Type": "json" }, success: function (res) { wx.hideNavigationBarLoading(); if (res.data.code === "0") { console.debug("success"); that.setData({ projectList: res.data.data }); } }, fail: function (error) { console.log(error) wx.hideNavigationBarLoading(); } }) }, radioChange: function (e) { //console.log('radio发生change事件,携带value值为:', e.detail.value); const value = e.detail.value; const values = value.split(":"); const id = values[0]; const name = values[1]; // const orgId = e.currentTarget.dataset.orgid; console.log("orgId", value) // var radioItems = this.data.runSetting.datagramTimes; // for (var i = 0, len = radioItems.length; i < len; ++i) { // radioItems[i].checked = radioItems[i].value == e.detail.value; // } // runSetting.datagramTimes=radioItems; //var pages = getCurrentPages(); // var currPage = pages[pages.length - 1]; //当前页面的数据data //var prevPage = pages[pages.length - 2]; //上一个页面 的数据data // prevPage.setData({ // orgId: id, // orgName: name // }) this.setData({ orgId: id, orgName: name }); }, getLocationReportList: function () { // wx.showNavigationBarLoading() var that = this; var url = app.globalData.cloudBase + "/cloud/Buy/GetLastLocationReports"; wx.request({ url: url, method: 'GET', header: { "Content-Type": "json" }, success: function (res) { console.debug(res.data); if (res.data.status === "ok") { that.processReportData(res.data.list); } }, fail: function (error) { console.log(error) } }) // wx.hideNavigationBarLoading(); }, processReportData: function (list) { this.data.loactionList = []; this.data.markers = []; app.globalData.marketIndex = 0; var tempmarkets = []; for (var i = 0; i < list.length; i++) { var report = list[i]; var currindex = app.globalData.marketIndex; app.globalData.marketIndex += 1; var icon = "../../images/location1.png"; var newmarket = { iconPath: icon, id: currindex, latitude: report.lat, longitude: report.lon, width: 40, height: 40, label: { content: report.nick == null ? '' : report.nick, color: '#FF0000DD', fontSize: 12, borderWidth: 1, borderColor: '#FFFFFFFF', bgColor: '#FFEEEEEE', x: 0, y: -60, textAlign: 'center', borderRadius: 6 } } tempmarkets.push(newmarket); var location = { index: currindex, openid: report.openId, headIcon: report.headIcon, reportDesc: report.desc, nick: report.nick, lon: report.lon, lat: report.lat, star: report.star, score: report.score }; this.data.loactionList.push(location); } this.setData({ markers: tempmarkets }); }, getLocation: function () { var that = this; wx.getLocation({ type: 'wgs84', success: function (res) { //当前的经度和纬度 let latitude = res.latitude let longitude = res.longitude // console.info(latitude + " " + longitude); that.setData({ longitude: longitude, latitude: latitude, }); wx.request({ url: `https://apis.map.qq.com/ws/geocoder/v1/?location=${latitude},${longitude}&key=${app.globalData.tencentMapKey}`, success: res => { console.info(res.data.result); var address = res.data.result.address; var city = res.data.result.ad_info.city; // app.globalData.defaultCity = app.globalData.defaultCity ? app.globalData.defaultCity : res.data.result.ad_info.city; // app.globalData.defaultCounty = app.globalData.defaultCounty ? app.globalData.defaultCounty : res.data.result.ad_info.district; // console.info(app.globalData.defaultCity + " " + app.globalData.defaultCity); that.getWeatherInfo() that.setData({ city: city, location: address }); } }) } }) }, getWeatherInfo: function () { var loc = this.data.longitude + "," + this.data.latitude; var url = 'https://devapi.qweather.com/v7/weather/now?location=' + loc + '&key=4408e93452474c74b8c8f4e6e9456261'; console.info(url); var that = this; wx.request({ url: url, success: res => { console.info(res); console.info(res.data); var weatherInfo = res.data.now.text + " " + res.data.now.temp + "度 " + res.data.now.windDir + " 风速" + res.data.now.windSpeed + "公里/小时 湿度" + res.data.now.humidity; that.setData({ weatherInfo: weatherInfo }); } }) }, takeProjectPhoto: function (event) { var url = "/pages/index/publish/publishPhoto?address=" + this.data.location + "&orgId=" + this.data.orgId + "&orgName=" + this.data.orgName + "&weather=" + this.data.weatherInfo + "&lng=" + this.data.longitude + "&lat=" + this.data.latitude; console.info(url); wx.navigateTo({ url: url }); }, checkProgHandle: function (e) { var projectId = e.currentTarget.dataset.projectid; wx.navigateTo({ url: '/pages/buyer/prog-rtu-List/prog-rtu-list?projectId=' + projectId }); } })