project.js 10 KB

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