var app = getApp(); var util = require('../../utils/util.js'); Page({ /** * 页面的初始数据 */ data: { location: '', county: '', showBoxList: [], weatherData: '', selsectState: [1, 0], hasMore: true, publish_button_state: true, openid: null, nick: null, headIcon: null, hiddenmodalput: true, nickTempInputValue: '', rtuCode: '', hiddenlogin: true, user:'', pw:'' }, onLoad: function (options) { const openid = wx.getStorageSync('openid'); this.setData({ openid:openid }) //刷新数据列表 this.getShowBoxList(); //定位当前城市 //this.getLocation(); const that = this; wx.connectSocket({ url: 'wss://wx.dahengsi.com/websocket/'+that.data.openid // header: { // 'content-type': 'application/json' // }, // protocols: ['protocol1'] }); wx.onSocketOpen(res => { console.info('open'); }); wx.onSocketMessage(res =>{ console.info('message '+res.data); }); wx.onSocketError(res =>{ console.info('error '+res.errMsg); }); wx.onSocketClose(res =>{ console.info('close '+res.code+" "+res.reason); }); }, onUnload: function(){ wx.closeSocket() }, onReady: function () { }, onShow: function () { //this.getShowBoxList(); }, onPullDownRefresh: function () { console.log("+++++onPullDownRefresh"); }, onReachBottom: function () { // Do something when page reach bottom. console.log("+++++onReachBottom"); }, onPageScroll: function () { // Do something when page scroll }, show_move_s: function () { var publish_button_state = this.data.publish_button_state; console.debug("move+++++++++++++++++++++++++++ " + publish_button_state); this.setData({ publish_button_state: true }) }, show_move_h: function () { var publish_button_state = this.data.publish_button_state; console.debug("move+++++++++++++++++++++++++++ " + publish_button_state); this.setData({ publish_button_state: false }) }, findRtuInfo: function (event) { // if (this.data.rtuCode !== '' && this.data.rtuCode !== null) { console.log(this.data.rtuCode); wx.showNavigationBarLoading() var that = this; var url = app.globalData.cloudBase + "/Wx/Rtu/List"; wx.request({ url: url, method: 'GET', data: { openId: this.data.openid, rtuCode: this.data.rtuCode }, header: { "Content-Type": "json" }, success: function (res) { if (res.data.code === "0") { console.log(res.data.data) var list = that.processShowBoxData(res.data.data); that.setData({ showBoxList: list }); } wx.hideNavigationBarLoading(); }, fail: function (error) { console.log(error) wx.hideNavigationBarLoading(); } }) // wx.navigateTo({ // url: "/pages/index/showBoxDetail/showBoxDetail?rtuCode=" + this.data.rtuCode + "&openId=" + this.data.openid // }); //} }, findRtuInfoByQr(){ console.log(this.data.rtuCode); wx.showNavigationBarLoading() var that = this; var url = app.globalData.cloudBase + "/Wx/Rtu/List"; wx.request({ url: url, method: 'GET', data: { openId: this.data.openid, rtuCode: this.data.rtuCode }, header: { "Content-Type": "json" }, success: function (res) { if (res.data.code === "0") { console.log(res.data.data) var list = that.processShowBoxData(res.data.data); that.setData({ showBoxList: list }); } }, fail: function (error) { console.log(error) } }) wx.hideNavigationBarLoading(); } , scanQr: function (event) { var _this = this; // 允许从相机和相册扫码 wx.scanCode({ success: (res) => { var result = res.result; _this.setData({ rtuCode: result, }) _this.findRtuInfoByQr() } }) }, bindRtuCodeInput: function (e) { this.setData({ rtuCode: e.detail.value }) }, takePhoto: function (event) { // var _this = this; // // 允许从相机和相册扫码 // wx.scanCode({ // success: (res) => { // var result = res.result; // _this.setData({ // result: result, // }) // } // }) // try { // var value = wx.getStorageSync('nick') // if (value !== null && value !== undefined && value !== "" && value.length > 0) { // this.data.nick = value; // } else { // this.data.nick = null; // } // } catch (e) { // console.log(e); // return; // } // if (this.data.nick === null) { // this.data.nickTempInputValue = ''; // // this.setData({ // // hiddenmodalput: !this.data.hiddenmodalput // // }); // } else { // wx.navigateTo({ // url: "/pages/index/publish/publishPhoto" // }); // } }, nickCancel: function () { // this.setData({ // hiddenmodalput: true // }); }, nickConfirm: function () { // this.setData({ // hiddenmodalput: true // }) if (this.data.user !== '' && this.data.user !== null && this.data.pw !== '' && this.data.pw !== null) { wx.showNavigationBarLoading() var that = this; var openid = this.data.openid; var url = app.globalData.cloudBase + "/Wx/user/login"; wx.request({ url: url, method: 'GET', data: { openid: this.data.openid, user: this.data.user, pw: this.data.pw }, header: { "Content-Type": "json" }, success: function (res) { if (res.data.code === "0") { //that.data.nick = that.data.nickTempInputValue; // wx.navigateTo({ // url: "/pages/index/publish/publishPhoto" //}); that.setData({ hiddenlogin: true }) }else{ } }, fail: function (error) { console.log(error) } }) wx.hideNavigationBarLoading(); } }, bindNickInput: function (e) { this.setData({ user: e.detail.value }) }, bindPwInput:function(e){ this.setData({ pw: e.detail.value }) }, //查询展柜列表 getShowBoxList: function () { wx.showNavigationBarLoading() var that = this; that.data.showBoxList = []; var openid = this.data.openid; var url = app.globalData.cloudBase + "/Wx/Rtu/History"; wx.request({ url: url, method: 'GET', data: { openid: this.data.openid }, header: { "Content-Type": "json" }, success: function (res) { //console.debug("list"+res.data); if (res.data.code === "0") { console.debug("success"); var list = that.processShowBoxData(res.data.data); that.setData({ showBoxList: list }); } }, fail: function (error) { console.log(error) } }) wx.hideNavigationBarLoading(); }, clickNation: function () { this.setData({ hasMore: true }) this.setData({ selsectState: [1, 0] }) }, clickSport: function () { this.setData({ hasMore: false }) this.setData({ selsectState: [0, 1] }) }, //处理展柜数据f processShowBoxData: function (list) { var rtus = []; for (var i = 0; i < list.length; i++) { var rtu = list[i]; // var photolist = []; // for (var j = 0; j < box.photos.length; j++) { // var photo = box.photos[j]; // var photoitem = { // id: photo.id, // showBoxId: photo.showBoxId, // name: photo.photo, // large: app.globalData.imageBase + "/" + photo.photo, // middle: app.globalData.imageBase + "/mid_" + photo.photo, // small: app.globalData.imageBase + "/thumb_" + photo.photo // } //photolist.push(photoitem); //} var temprtu = { //stars: util.convertToStarsArray("" + box.star), //star: box.star, //openid:box.openid, rtuName: rtu.rtuName, orgName: rtu.orgName, //average: box.score, //photos: photolist, itemId: rtu.id, rtuCode: rtu.rtuCode, lastTime: rtu.lastTime //buyer: box.nick, //headIcon: box.headIcon } // console.debug("temp box "+tempbox); rtus.push(temprtu) } return rtus; }, //定位当前城市 getLocation: function () { var that = this; wx.getLocation({ type: 'wgs84', success: function (res) { //当前的经度和纬度 let latitude = res.latitude let longitude = res.longitude wx.request({ url: 'https://apis.map.qq.com/ws/geocoder/v1/?location=${latitude},${longitude}&key=${app.globalData.tencentMapKey}', success: res => { 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; that.setData({ location: app.globalData.defaultCity, county: app.globalData.defaultCounty }); } }) } }) }, onMovieTap: function (event) { var imageName = event.currentTarget.dataset.image; wx.navigateTo({ url: "showBoxDetail/showBoxDetail?imageName=" + imageName }) }, //获取天气 getWeather: function (e) { var length = this.data.location.length; var city = this.data.location.slice(0, length - 1); //分割字符串 console.log(city); var that = this; var param = { key: app.globalData.heWeatherKey, location: city }; //发出请求 wx.request({ url: app.globalData.heWeatherBase + "/s6/weather", data: param, header: { 'content-type': 'application/json' }, success: function (res) { app.globalData.weatherData = res.data.HeWeather6[0].status == "unknown city" ? "" : res.data.HeWeather6[0]; var weatherData = app.globalData.weatherData ? app.globalData.weatherData.now : "暂无该城市天气信息"; var dress = app.globalData.weatherData ? res.data.HeWeather6[0].lifestyle[1] : { txt: "暂无该城市天气信息" }; that.setData({ weatherData: weatherData, //今天天气情况数组 dress: dress //生活指数 }); } }) }, openTalkBoxHandle: function (e) { // var openid = e.currentTarget.dataset.openId; var rtucode = e.currentTarget.dataset.rtucode; // var score = e.currentTarget.dataset.score; // var headicon = e.currentTarget.dataset.headicon; // var nick = e.currentTarget.dataset.nick; //var location = this.data.loactionList[index]; // this.setData({ // show: false // }) wx.navigateTo({ url: "/pages/index/showBoxDetail/showBoxDetail?rtuCode=" + rtucode + "&openId=" + this.data.openid }); // wx.navigateTo({ // url: "/pages/buyer/talkToBuyer/talkToBuyer?headIcon=" + headicon + "&nick=" + nick + "&star=" + star + "&score=" + score + "&openid=" + openid // }) } })