report.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426
  1. // pages/report/report.js
  2. var app = getApp();
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. show: false,
  9. popBoxTitle: '',
  10. popBoxDesc: '',
  11. headUrl: '',
  12. includepoints: [],
  13. longitude: 113.25222251985,
  14. latitude: 39.995607421389,
  15. markers: [],
  16. loactionList: [],
  17. reportTempInputValue: '',
  18. reportDesc: '',
  19. hiddenmodalput: true,
  20. nickTempInputValue: '',
  21. reportInputFocus: false,
  22. openid: '',
  23. locationid: '',
  24. location: '',
  25. city: '北京',
  26. scale: 10,
  27. orgName: '',
  28. orgId: '',
  29. projectList: [],
  30. reportCacheTime: ''
  31. },
  32. /**
  33. * 生命周期函数--监听页面加载
  34. */
  35. onLoad: function (options) {
  36. this.data.openid = wx.getStorageSync('openid');
  37. const lng = wx.getStorageSync('report_cache_lng');
  38. const lat = wx.getStorageSync('report_cache_lat');
  39. if (lng != null && lat != null && lng.length > 0 && lat.length > 0) {
  40. const reportCacheTime = wx.getStorageSync('reportCacheTime');
  41. this.setData({
  42. show: true,
  43. reportCacheTime: reportCacheTime
  44. })
  45. }
  46. this.getLocation();
  47. },
  48. /**
  49. * 生命周期函数--监听页面初次渲染完成
  50. */
  51. onReady: function () {
  52. },
  53. /**
  54. * 生命周期函数--监听页面显示
  55. */
  56. onShow: function () {
  57. const lng = wx.getStorageSync('report_cache_lng');
  58. const lat = wx.getStorageSync('report_cache_lat');
  59. if (lng != null && lat != null && lng.length > 0 && lat.length > 0) {
  60. const reportCacheTime = wx.getStorageSync('reportCacheTime');
  61. this.setData({
  62. show: true,
  63. reportCacheTime: reportCacheTime
  64. })
  65. } else {
  66. this.setData({
  67. show: false
  68. })
  69. }
  70. },
  71. /**
  72. * 生命周期函数--监听页面隐藏
  73. */
  74. onHide: function () {
  75. },
  76. /**
  77. * 生命周期函数--监听页面卸载
  78. */
  79. onUnload: function () {
  80. },
  81. /**
  82. * 页面相关事件处理函数--监听用户下拉动作
  83. */
  84. onPullDownRefresh: function () {
  85. },
  86. /**
  87. * 页面上拉触底事件的处理函数
  88. */
  89. onReachBottom: function () {
  90. },
  91. /**
  92. * 用户点击右上角分享
  93. */
  94. onShareAppMessage: function () {
  95. },
  96. touchMap: function (e) {
  97. this.setData({
  98. show: false
  99. })
  100. },
  101. orgSelectEvent: function (e) {
  102. wx.navigateTo({
  103. url: "/pages/org/org"
  104. });
  105. },
  106. markertapHandle: function (e) {
  107. var location = this.data.loactionList[e.markerId];
  108. this.setData({
  109. headUrl: app.globalData.imageBase + "/" + location.headIcon,
  110. show: true,
  111. popBoxTitle: location.nick == null ? '' : location.nick,
  112. popBoxDesc: location.reportDesc,
  113. locationid: location.index
  114. })
  115. },
  116. reportWorkDetailHandle: function (e) {
  117. // var index = e.currentTarget.dataset.locationid;
  118. // var location = this.data.loactionList[index];
  119. // var nick = location.nick == null || location.nick == undefined ? '' : location.nick;
  120. // this.setData({
  121. // show: false
  122. // })
  123. wx.navigateTo({
  124. url: "/pages/report/rtuConstructionReport/rtuConstructionReport?type=1&address=" + this.data.location + "&weather=" + this.data.weatherInfo + "&lng=" + this.data.longitude + "&lat=" + this.data.latitude
  125. })
  126. },
  127. continueReportHandle: function (e) {
  128. wx.navigateTo({
  129. url: "/pages/report/rtuConstructionReport/rtuConstructionReport?type=2"
  130. })
  131. },
  132. reportMyLocation: function (e) {
  133. var openid = wx.getStorageSync('openid');
  134. var that = this;
  135. var url = app.globalData.cloudBase + "/cloud/Buy/ReportMyLocation";
  136. wx.request({
  137. url: url,
  138. method: 'GET',
  139. header: {
  140. "Content-Type": "json"
  141. },
  142. data: {
  143. openid: openid,
  144. lon: this.data.longitude,
  145. lat: this.data.latitude,
  146. desc: this.data.reportTempInputValue
  147. },
  148. success: function (res) {
  149. console.debug(res.data);
  150. if (res.data.status === "ok") {
  151. that.setData({
  152. reportDesc: ''
  153. });
  154. that.getLocationReportList();
  155. }
  156. },
  157. fail: function (error) {
  158. console.log(error)
  159. }
  160. })
  161. },
  162. reportInputHandle: function (e) {
  163. 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;
  164. wx.navigateTo({
  165. url: url
  166. });
  167. // this.setData({
  168. // reportTempInputValue: e.detail.value
  169. // })
  170. },
  171. nickCancelHandle: function () {
  172. this.setData({
  173. hiddenmodalput: true
  174. });
  175. },
  176. nickConfirmHandle: function () {
  177. this.setData({
  178. hiddenmodalput: true
  179. })
  180. if (this.data.nickTempInputValue !== '' && this.data.nickTempInputValue !== null) {
  181. var that = this;
  182. var url = app.globalData.cloudBase + "/cloud/Wx/UpdateNick";
  183. wx.request({
  184. url: url,
  185. method: 'GET',
  186. data: {
  187. openid: this.data.openid,
  188. nick: this.data.nickTempInputValue
  189. },
  190. header: {
  191. "Content-Type": "json"
  192. },
  193. success: function (res) {
  194. if (res.data.status === "ok") {
  195. that.setData({
  196. reportInputFocus: true
  197. });
  198. }
  199. },
  200. fail: function (error) {
  201. console.log(error)
  202. }
  203. })
  204. }
  205. },
  206. bindNickInputHandle: function (e) {
  207. this.setData({
  208. nickTempInputValue: e.detail.value
  209. })
  210. },
  211. getProjectList: function () {
  212. wx.showNavigationBarLoading()
  213. var that = this;
  214. var url = app.globalData.cloudBase + "/Wx/User/Project/" + this.data.openid;
  215. wx.request({
  216. url: url,
  217. method: 'GET',
  218. header: {
  219. "Content-Type": "json"
  220. },
  221. success: function (res) {
  222. wx.hideNavigationBarLoading();
  223. if (res.data.code === "0") {
  224. console.debug("success");
  225. that.setData({
  226. projectList: res.data.data
  227. });
  228. }
  229. },
  230. fail: function (error) {
  231. console.log(error)
  232. wx.hideNavigationBarLoading();
  233. }
  234. })
  235. },
  236. radioChange: function (e) {
  237. //console.log('radio发生change事件,携带value值为:', e.detail.value);
  238. const value = e.detail.value;
  239. const values = value.split(":");
  240. const id = values[0];
  241. const name = values[1];
  242. // const orgId = e.currentTarget.dataset.orgid;
  243. console.log("orgId", value)
  244. // var radioItems = this.data.runSetting.datagramTimes;
  245. // for (var i = 0, len = radioItems.length; i < len; ++i) {
  246. // radioItems[i].checked = radioItems[i].value == e.detail.value;
  247. // }
  248. // runSetting.datagramTimes=radioItems;
  249. //var pages = getCurrentPages();
  250. // var currPage = pages[pages.length - 1]; //当前页面的数据data
  251. //var prevPage = pages[pages.length - 2]; //上一个页面 的数据data
  252. // prevPage.setData({
  253. // orgId: id,
  254. // orgName: name
  255. // })
  256. this.setData({
  257. orgId: id,
  258. orgName: name
  259. });
  260. },
  261. getLocationReportList: function () {
  262. // wx.showNavigationBarLoading()
  263. var that = this;
  264. var url = app.globalData.cloudBase + "/cloud/Buy/GetLastLocationReports";
  265. wx.request({
  266. url: url,
  267. method: 'GET',
  268. header: {
  269. "Content-Type": "json"
  270. },
  271. success: function (res) {
  272. console.debug(res.data);
  273. if (res.data.status === "ok") {
  274. that.processReportData(res.data.list);
  275. }
  276. },
  277. fail: function (error) {
  278. console.log(error)
  279. }
  280. })
  281. // wx.hideNavigationBarLoading();
  282. },
  283. processReportData: function (list) {
  284. this.data.loactionList = [];
  285. this.data.markers = [];
  286. app.globalData.marketIndex = 0;
  287. var tempmarkets = [];
  288. for (var i = 0; i < list.length; i++) {
  289. var report = list[i];
  290. var currindex = app.globalData.marketIndex;
  291. app.globalData.marketIndex += 1;
  292. var icon = "../../images/location1.png";
  293. var newmarket = {
  294. iconPath: icon,
  295. id: currindex,
  296. latitude: report.lat,
  297. longitude: report.lon,
  298. width: 40,
  299. height: 40,
  300. label: {
  301. content: report.nick == null ? '' : report.nick,
  302. color: '#FF0000DD',
  303. fontSize: 12,
  304. borderWidth: 1,
  305. borderColor: '#FFFFFFFF',
  306. bgColor: '#FFEEEEEE',
  307. x: 0,
  308. y: -60,
  309. textAlign: 'center',
  310. borderRadius: 6
  311. }
  312. }
  313. tempmarkets.push(newmarket);
  314. var location = {
  315. index: currindex,
  316. openid: report.openId,
  317. headIcon: report.headIcon,
  318. reportDesc: report.desc,
  319. nick: report.nick,
  320. lon: report.lon,
  321. lat: report.lat,
  322. star: report.star,
  323. score: report.score
  324. };
  325. this.data.loactionList.push(location);
  326. }
  327. this.setData({
  328. markers: tempmarkets
  329. });
  330. },
  331. getLocation: function () {
  332. var that = this;
  333. wx.getLocation({
  334. type: 'wgs84',
  335. success: function (res) {
  336. //当前的经度和纬度
  337. let latitude = res.latitude
  338. let longitude = res.longitude
  339. // console.info(latitude + " " + longitude);
  340. that.setData({
  341. longitude: longitude,
  342. latitude: latitude,
  343. });
  344. wx.request({
  345. url: `https://apis.map.qq.com/ws/geocoder/v1/?location=${latitude},${longitude}&key=${app.globalData.tencentMapKey}`,
  346. success: res => {
  347. console.info(res.data.result);
  348. var address = res.data.result.address;
  349. var city = res.data.result.ad_info.city;
  350. // app.globalData.defaultCity = app.globalData.defaultCity ? app.globalData.defaultCity : res.data.result.ad_info.city;
  351. // app.globalData.defaultCounty = app.globalData.defaultCounty ? app.globalData.defaultCounty : res.data.result.ad_info.district;
  352. // console.info(app.globalData.defaultCity + " " + app.globalData.defaultCity);
  353. that.getWeatherInfo()
  354. that.setData({
  355. city: city,
  356. location: address
  357. });
  358. }
  359. })
  360. }
  361. })
  362. },
  363. getWeatherInfo: function () {
  364. var loc = this.data.longitude + "," + this.data.latitude;
  365. var url = 'https://devapi.qweather.com/v7/weather/now?location=' + loc + '&key=4408e93452474c74b8c8f4e6e9456261';
  366. console.info(url);
  367. var that = this;
  368. wx.request({
  369. url: url,
  370. success: res => {
  371. console.info(res);
  372. console.info(res.data);
  373. var weatherInfo = res.data.now.text + " " + res.data.now.temp + "度 " + res.data.now.windDir + " 风速" + res.data.now.windSpeed + "公里/小时 湿度" + res.data.now.humidity;
  374. that.setData({
  375. weatherInfo: weatherInfo
  376. });
  377. }
  378. })
  379. },
  380. takeProjectPhoto: function (event) {
  381. 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;
  382. console.info(url);
  383. wx.navigateTo({
  384. url: url
  385. });
  386. },
  387. checkProgHandle: function (e) {
  388. var projectId = e.currentTarget.dataset.projectid;
  389. wx.navigateTo({
  390. url: '/pages/buyer/prog-rtu-List/prog-rtu-list?projectId=' + projectId
  391. });
  392. }
  393. })