index.js 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  1. // pages/yuezhan/search/index.js
  2. const { request, serverName } = require('../../../utils/services');
  3. const {
  4. newRequestFns,
  5. newServerName
  6. } = require('../../../utils/newServices.js');
  7. const { Toast } = require('../../../utils/util.js');
  8. const QQMapWX = require('../../../common/component/mapSDK/qqmap-wx-jssdk.min.js');
  9. var qqmapsdk = "";
  10. const app = getApp();
  11. const WxParse = require('../../../common/component/wxParse/wxParse.js');
  12. Page({
  13. /**
  14. * 页面的初始数据
  15. */
  16. data: {
  17. tabs: ['国内', '国际'],
  18. testImg: '../../../imgs/testImg/thumbSmallImg2.jpg',
  19. avatar: '../../../imgs/testImg/1.jpg',
  20. activeIndex:0,
  21. domesticCityList:[],
  22. internationalCity:[]
  23. },
  24. /**
  25. * 生命周期函数--监听页面加载
  26. */
  27. onLoad: function (options) {
  28. qqmapsdk = new QQMapWX({
  29. key: '2Z3BZ-H7EWO-F4YWX-SG5JF-2VOK2-S2FUB'
  30. });
  31. this.getLocationName();
  32. this.getDomesticCity();
  33. this.setData({
  34. cityAction: app.globalData.city
  35. })
  36. },
  37. tabClick: function (e) {
  38. this.setData({
  39. loading: true,
  40. activeIndex: e.currentTarget.id,
  41. domesticCityList: [],
  42. internationalCity: []
  43. });
  44. if (this.data.activeIndex==0){
  45. this.getDomesticCity();
  46. }
  47. else{
  48. this.getInternationalCity();
  49. }
  50. },
  51. clickItem:function(e){
  52. console.log(e.currentTarget)
  53. let { name } = e.currentTarget.dataset;
  54. console.log(name);
  55. app.globalData.city = name;
  56. app.globalData.clickToSelect = true;
  57. wx.navigateBack({
  58. delta: 1,
  59. })
  60. },
  61. /**
  62. * 生命周期函数--监听页面初次渲染完成
  63. */
  64. onReady: function () {
  65. },
  66. getDomesticCity:function(){
  67. newRequestFns["getDomesticCity"]({},"",res=>{
  68. if(res.data.code==0){
  69. let { data: domesticCityList} = res.data;
  70. let exhibitionNum = 0;
  71. //暂时改成从城市列表获取
  72. domesticCityList.find((item) => {
  73. if(item[0] == '北京'){
  74. exhibitionNum = item[1];
  75. }
  76. })
  77. this.setData({
  78. domesticCityList,
  79. exhibitionNum
  80. })
  81. }
  82. // console.log(domesticCityList)
  83. })
  84. },
  85. getLocationName:function(){
  86. // 检查 globalData 是否已有位置信息
  87. // if (app.globalData.latitude && app.globalData.longitude && app.globalData.locationName) {
  88. // 使用 globalData 中的值
  89. this.setData({
  90. latitude: app.globalData.latitude,
  91. longitude: app.globalData.longitude,
  92. locationName: app.globalData.locationName
  93. });
  94. app.globalData.city = app.globalData.city || "北京";
  95. this.getList(1, app.globalData.city);
  96. return;
  97. // }
  98. // 没有完整位置信息,获取位置
  99. // wx.getLocation({
  100. // type: 'wgs84',
  101. // success: (res) => {
  102. // // 保存到 globalData
  103. // app.globalData.latitude = res.latitude;
  104. // app.globalData.longitude = res.longitude;
  105. // this.setData({
  106. // latitude: res.latitude,
  107. // longitude: res.longitude
  108. // })
  109. // // console.log('0202', res)
  110. // //2、根据坐标获取当前位置名称,显示在顶部:腾讯地图逆地址解析
  111. // qqmapsdk.reverseGeocoder({
  112. // location: {
  113. // latitude: res.latitude,
  114. // longitude: res.longitude
  115. // },
  116. // success: (res) =>{
  117. // let { city:locationName } = res.result.address_component;
  118. // locationName = locationName.substring(0,2);
  119. // // 保存到 globalData
  120. // app.globalData.city = locationName;
  121. // app.globalData.locationName = locationName;
  122. // this.getList(1, locationName)
  123. // this.setData({
  124. // locationName
  125. // })
  126. // },
  127. // fail: function (res) {
  128. // console.log(res)
  129. // // 失败时设置默认值
  130. // app.globalData.city = "北京";
  131. // app.globalData.locationName = "北京";
  132. // this.setData({
  133. // locationName:"北京"
  134. // })
  135. // },
  136. // complete: function (res) {
  137. // console.log(res);
  138. // }
  139. // });
  140. // }
  141. // })
  142. },
  143. getList: function (page, locationName) {
  144. let loginSessionKey = wx.getStorageSync("token");
  145. console.log(loginSessionKey)
  146. let { latitude, longitude, activeDist, activeType } = this.data;
  147. this.setData({
  148. loading: true
  149. })
  150. newRequestFns["getExhibitionListOffline"]({
  151. page: page,
  152. loginSessionKey,
  153. city: locationName||"",
  154. sort:0,
  155. type:0,
  156. lng: longitude,
  157. lat: latitude,
  158. }, '', res => {
  159. // let { total: exhibitionNum } = res.data.data;
  160. let exhibitionNum = 0;
  161. //暂时改成从城市列表获取
  162. this.data.domesticCityList.find((item) => {
  163. if(item[0] == '北京'){
  164. exhibitionNum = item[1];
  165. }
  166. })
  167. this.setData({
  168. exhibitionNum,
  169. loading: false,
  170. });
  171. wx.stopPullDownRefresh();
  172. }, err => {
  173. }, complete => {
  174. })
  175. },
  176. getInternationalCity(){
  177. newRequestFns["getInternationalCity"]({}, "", res => {
  178. if (res.data.code == 0) {
  179. let { data: internationalCity } = res.data;
  180. this.setData({
  181. internationalCity
  182. })
  183. }
  184. // console.log(res)
  185. })
  186. },
  187. /**
  188. * 生命周期函数--监听页面显示
  189. */
  190. onShow: function () {
  191. // 更新选中的城市状态
  192. console.log(app.globalData.city, 'app.globalData.city')
  193. this.setData({
  194. cityAction: app.globalData.city
  195. });
  196. },
  197. /**
  198. * 生命周期函数--监听页面隐藏
  199. */
  200. onHide: function () {
  201. },
  202. /**
  203. * 生命周期函数--监听页面卸载
  204. */
  205. onUnload: function () {
  206. },
  207. /**
  208. * 页面相关事件处理函数--监听用户下拉动作
  209. */
  210. onPullDownRefresh: function () {
  211. },
  212. /**
  213. * 页面上拉触底事件的处理函数
  214. */
  215. onReachBottom: function () {
  216. },
  217. /**
  218. * 用户点击右上角分享
  219. */
  220. onShareAppMessage: function () {
  221. }
  222. })