1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
| getWeatherData:function(city){ var _this = this, thisdata = this.data, historyArea = thisdata.historyArea; wx.request({ url: _this.data.api, data: { "city": city }, method: 'get', header: { 'Content-Type': 'application/json' }, dataType: 'jsonp', jsonp: 'callback', success: function (res) { var res = res.data res = JSON.parse(res) if (res.status === "0") { var data = res['result'] data.img = '../images/condicon/'+data.img+'b.png' _this.setData({ getSuccess: 'true', getLotion: city, realdata: data, clock: data.updatetime, aqi: data['aqi'], aqiMsg: data.aqi.aqiinfo['affect'] + ',' + data.aqi.aqiinfo['measure'], life: data['index'], daily: data['daily'], hourly: data['hourly'], airPredict: '两小时之后天气' + data.hourly[2].weather + ' ,温度 ' + data.hourly[2].temp + '°', quality: data['aqi'].quality }) // 搜索返回成功后 清除 输入框,将搜索结果放入历史记录 // _this.$refs.clearText.value = '' if (thisdata.inpuText !== '') { if (thisdata.historyArea.indexOf(thisdata.inpuText) === -1) { historyArea.push(thisdata.inpuText) _this.setData({ historyArea: historyArea }) } } _this.back() } else { wx.showModal({ title: '提示', content: res.msg, success: function (res) { if (res.confirm) { _this.setData({ msgText: '位置获取失败!!!请手动选择', loadingBtn: true }) } else if (res.cancel) { console.log('用户点击取消') } } }) } },
|