index.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462
  1. var app = getApp();
  2. var util = require('../../utils/util.js');
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. location: '',
  9. county: '',
  10. showBoxList: [],
  11. weatherData: '',
  12. selsectState: [1, 0],
  13. hasMore: true,
  14. publish_button_state: true,
  15. openid: null,
  16. nick: null,
  17. headIcon: null,
  18. hiddenmodalput: true,
  19. nickTempInputValue: '',
  20. rtuCode: '',
  21. hiddenlogin: true,
  22. user:'',
  23. pw:''
  24. },
  25. onLoad: function (options) {
  26. const openid = wx.getStorageSync('openid');
  27. this.setData({
  28. openid:openid
  29. })
  30. //刷新数据列表
  31. this.getShowBoxList();
  32. //定位当前城市
  33. //this.getLocation();
  34. const that = this;
  35. wx.connectSocket({
  36. url: 'wss://wx.dahengsi.com/websocket/'+that.data.openid
  37. // header: {
  38. // 'content-type': 'application/json'
  39. // },
  40. // protocols: ['protocol1']
  41. });
  42. wx.onSocketOpen(res => {
  43. console.info('open');
  44. });
  45. wx.onSocketMessage(res =>{
  46. console.info('message '+res.data);
  47. });
  48. wx.onSocketError(res =>{
  49. console.info('error '+res.errMsg);
  50. });
  51. wx.onSocketClose(res =>{
  52. console.info('close '+res.code+" "+res.reason);
  53. });
  54. },
  55. onUnload: function(){
  56. wx.closeSocket()
  57. },
  58. onReady: function () {
  59. },
  60. onShow: function () {
  61. //this.getShowBoxList();
  62. },
  63. onPullDownRefresh: function () {
  64. console.log("+++++onPullDownRefresh");
  65. },
  66. onReachBottom: function () {
  67. // Do something when page reach bottom.
  68. console.log("+++++onReachBottom");
  69. },
  70. onPageScroll: function () {
  71. // Do something when page scroll
  72. },
  73. show_move_s: function () {
  74. var publish_button_state = this.data.publish_button_state;
  75. console.debug("move+++++++++++++++++++++++++++ " + publish_button_state);
  76. this.setData({
  77. publish_button_state: true
  78. })
  79. },
  80. show_move_h: function () {
  81. var publish_button_state = this.data.publish_button_state;
  82. console.debug("move+++++++++++++++++++++++++++ " + publish_button_state);
  83. this.setData({
  84. publish_button_state: false
  85. })
  86. },
  87. findRtuInfo: function (event) {
  88. // if (this.data.rtuCode !== '' && this.data.rtuCode !== null) {
  89. console.log(this.data.rtuCode);
  90. wx.showNavigationBarLoading()
  91. var that = this;
  92. var url = app.globalData.cloudBase + "/Wx/Rtu/List";
  93. wx.request({
  94. url: url,
  95. method: 'GET',
  96. data: {
  97. openId: this.data.openid,
  98. rtuCode: this.data.rtuCode
  99. },
  100. header: {
  101. "Content-Type": "json"
  102. },
  103. success: function (res) {
  104. if (res.data.code === "0") {
  105. console.log(res.data.data)
  106. var list = that.processShowBoxData(res.data.data);
  107. that.setData({
  108. showBoxList: list
  109. });
  110. }
  111. wx.hideNavigationBarLoading();
  112. },
  113. fail: function (error) {
  114. console.log(error)
  115. wx.hideNavigationBarLoading();
  116. }
  117. })
  118. // wx.navigateTo({
  119. // url: "/pages/index/showBoxDetail/showBoxDetail?rtuCode=" + this.data.rtuCode + "&openId=" + this.data.openid
  120. // });
  121. //}
  122. },
  123. findRtuInfoByQr(){
  124. console.log(this.data.rtuCode);
  125. wx.showNavigationBarLoading()
  126. var that = this;
  127. var url = app.globalData.cloudBase + "/Wx/Rtu/List";
  128. wx.request({
  129. url: url,
  130. method: 'GET',
  131. data: {
  132. openId: this.data.openid,
  133. rtuCode: this.data.rtuCode
  134. },
  135. header: {
  136. "Content-Type": "json"
  137. },
  138. success: function (res) {
  139. if (res.data.code === "0") {
  140. console.log(res.data.data)
  141. var list = that.processShowBoxData(res.data.data);
  142. that.setData({
  143. showBoxList: list
  144. });
  145. }
  146. },
  147. fail: function (error) {
  148. console.log(error)
  149. }
  150. })
  151. wx.hideNavigationBarLoading();
  152. }
  153. ,
  154. scanQr: function (event) {
  155. var _this = this;
  156. // 允许从相机和相册扫码
  157. wx.scanCode({
  158. success: (res) => {
  159. var result = res.result;
  160. _this.setData({
  161. rtuCode: result,
  162. })
  163. _this.findRtuInfoByQr()
  164. }
  165. })
  166. },
  167. bindRtuCodeInput: function (e) {
  168. this.setData({
  169. rtuCode: e.detail.value
  170. })
  171. },
  172. takePhoto: function (event) {
  173. // var _this = this;
  174. // // 允许从相机和相册扫码
  175. // wx.scanCode({
  176. // success: (res) => {
  177. // var result = res.result;
  178. // _this.setData({
  179. // result: result,
  180. // })
  181. // }
  182. // })
  183. // try {
  184. // var value = wx.getStorageSync('nick')
  185. // if (value !== null && value !== undefined && value !== "" && value.length > 0) {
  186. // this.data.nick = value;
  187. // } else {
  188. // this.data.nick = null;
  189. // }
  190. // } catch (e) {
  191. // console.log(e);
  192. // return;
  193. // }
  194. // if (this.data.nick === null) {
  195. // this.data.nickTempInputValue = '';
  196. // // this.setData({
  197. // // hiddenmodalput: !this.data.hiddenmodalput
  198. // // });
  199. // } else {
  200. // wx.navigateTo({
  201. // url: "/pages/index/publish/publishPhoto"
  202. // });
  203. // }
  204. },
  205. nickCancel: function () {
  206. // this.setData({
  207. // hiddenmodalput: true
  208. // });
  209. },
  210. nickConfirm: function () {
  211. // this.setData({
  212. // hiddenmodalput: true
  213. // })
  214. if (this.data.user !== '' && this.data.user !== null && this.data.pw !== '' && this.data.pw !== null) {
  215. wx.showNavigationBarLoading()
  216. var that = this;
  217. var openid = this.data.openid;
  218. var url = app.globalData.cloudBase + "/Wx/user/login";
  219. wx.request({
  220. url: url,
  221. method: 'GET',
  222. data: {
  223. openid: this.data.openid,
  224. user: this.data.user,
  225. pw: this.data.pw
  226. },
  227. header: {
  228. "Content-Type": "json"
  229. },
  230. success: function (res) {
  231. if (res.data.code === "0") {
  232. //that.data.nick = that.data.nickTempInputValue;
  233. // wx.navigateTo({
  234. // url: "/pages/index/publish/publishPhoto"
  235. //});
  236. that.setData({
  237. hiddenlogin: true
  238. })
  239. }else{
  240. }
  241. },
  242. fail: function (error) {
  243. console.log(error)
  244. }
  245. })
  246. wx.hideNavigationBarLoading();
  247. }
  248. },
  249. bindNickInput: function (e) {
  250. this.setData({
  251. user: e.detail.value
  252. })
  253. },
  254. bindPwInput:function(e){
  255. this.setData({
  256. pw: e.detail.value
  257. })
  258. },
  259. //查询展柜列表
  260. getShowBoxList: function () {
  261. wx.showNavigationBarLoading()
  262. var that = this;
  263. that.data.showBoxList = [];
  264. var openid = this.data.openid;
  265. var url = app.globalData.cloudBase + "/Wx/Rtu/History";
  266. wx.request({
  267. url: url,
  268. method: 'GET',
  269. data: {
  270. openid: this.data.openid
  271. },
  272. header: {
  273. "Content-Type": "json"
  274. },
  275. success: function (res) {
  276. //console.debug("list"+res.data);
  277. if (res.data.code === "0") {
  278. console.debug("success");
  279. var list = that.processShowBoxData(res.data.data);
  280. that.setData({
  281. showBoxList: list
  282. });
  283. }
  284. },
  285. fail: function (error) {
  286. console.log(error)
  287. }
  288. })
  289. wx.hideNavigationBarLoading();
  290. },
  291. clickNation: function () {
  292. this.setData({
  293. hasMore: true
  294. })
  295. this.setData({
  296. selsectState: [1, 0]
  297. })
  298. },
  299. clickSport: function () {
  300. this.setData({
  301. hasMore: false
  302. })
  303. this.setData({
  304. selsectState: [0, 1]
  305. })
  306. },
  307. //处理展柜数据f
  308. processShowBoxData: function (list) {
  309. var rtus = [];
  310. for (var i = 0; i < list.length; i++) {
  311. var rtu = list[i];
  312. // var photolist = [];
  313. // for (var j = 0; j < box.photos.length; j++) {
  314. // var photo = box.photos[j];
  315. // var photoitem = {
  316. // id: photo.id,
  317. // showBoxId: photo.showBoxId,
  318. // name: photo.photo,
  319. // large: app.globalData.imageBase + "/" + photo.photo,
  320. // middle: app.globalData.imageBase + "/mid_" + photo.photo,
  321. // small: app.globalData.imageBase + "/thumb_" + photo.photo
  322. // }
  323. //photolist.push(photoitem);
  324. //}
  325. var temprtu = {
  326. //stars: util.convertToStarsArray("" + box.star),
  327. //star: box.star,
  328. //openid:box.openid,
  329. rtuName: rtu.rtuName,
  330. orgName: rtu.orgName,
  331. //average: box.score,
  332. //photos: photolist,
  333. itemId: rtu.id,
  334. rtuCode: rtu.rtuCode,
  335. lastTime: rtu.lastTime
  336. //buyer: box.nick,
  337. //headIcon: box.headIcon
  338. }
  339. // console.debug("temp box "+tempbox);
  340. rtus.push(temprtu)
  341. }
  342. return rtus;
  343. },
  344. //定位当前城市
  345. getLocation: function () {
  346. var that = this;
  347. wx.getLocation({
  348. type: 'wgs84',
  349. success: function (res) {
  350. //当前的经度和纬度
  351. let latitude = res.latitude
  352. let longitude = res.longitude
  353. wx.request({
  354. url: 'https://apis.map.qq.com/ws/geocoder/v1/?location=${latitude},${longitude}&key=${app.globalData.tencentMapKey}',
  355. success: res => {
  356. app.globalData.defaultCity = app.globalData.defaultCity ? app.globalData.defaultCity : res.data.result.ad_info.city;
  357. app.globalData.defaultCounty = app.globalData.defaultCounty ? app.globalData.defaultCounty : res.data.result.ad_info.district;
  358. that.setData({
  359. location: app.globalData.defaultCity,
  360. county: app.globalData.defaultCounty
  361. });
  362. }
  363. })
  364. }
  365. })
  366. },
  367. onMovieTap: function (event) {
  368. var imageName = event.currentTarget.dataset.image;
  369. wx.navigateTo({
  370. url: "showBoxDetail/showBoxDetail?imageName=" + imageName
  371. })
  372. },
  373. //获取天气
  374. getWeather: function (e) {
  375. var length = this.data.location.length;
  376. var city = this.data.location.slice(0, length - 1); //分割字符串
  377. console.log(city);
  378. var that = this;
  379. var param = {
  380. key: app.globalData.heWeatherKey,
  381. location: city
  382. };
  383. //发出请求
  384. wx.request({
  385. url: app.globalData.heWeatherBase + "/s6/weather",
  386. data: param,
  387. header: {
  388. 'content-type': 'application/json'
  389. },
  390. success: function (res) {
  391. app.globalData.weatherData = res.data.HeWeather6[0].status == "unknown city" ? "" : res.data.HeWeather6[0];
  392. var weatherData = app.globalData.weatherData ? app.globalData.weatherData.now : "暂无该城市天气信息";
  393. var dress = app.globalData.weatherData ? res.data.HeWeather6[0].lifestyle[1] : {
  394. txt: "暂无该城市天气信息"
  395. };
  396. that.setData({
  397. weatherData: weatherData, //今天天气情况数组
  398. dress: dress //生活指数
  399. });
  400. }
  401. })
  402. },
  403. openTalkBoxHandle: function (e) {
  404. // var openid = e.currentTarget.dataset.openId;
  405. var rtucode = e.currentTarget.dataset.rtucode;
  406. // var score = e.currentTarget.dataset.score;
  407. // var headicon = e.currentTarget.dataset.headicon;
  408. // var nick = e.currentTarget.dataset.nick;
  409. //var location = this.data.loactionList[index];
  410. // this.setData({
  411. // show: false
  412. // })
  413. wx.navigateTo({
  414. url: "/pages/index/showBoxDetail/showBoxDetail?rtuCode=" + rtucode + "&openId=" + this.data.openid
  415. });
  416. // wx.navigateTo({
  417. // url: "/pages/buyer/talkToBuyer/talkToBuyer?headIcon=" + headicon + "&nick=" + nick + "&star=" + star + "&score=" + score + "&openid=" + openid
  418. // })
  419. }
  420. })