index.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490
  1. //index.js
  2. //获取应用实例
  3. const { request, serverName,imgServer } = require('../../utils/services');
  4. const { Toast, qqmapsdk } = require('../../utils/util.js');
  5. const { defaultImg, noExhibitionImg } = require('../../utils/images');
  6. const WxParse = require('../../common/component/wxParse/wxParse.js');
  7. // const QQMapWX = require('../../common/component/mapSDK/qqmap-wx-jssdk.min.js');
  8. const app = getApp();
  9. const distItems = [
  10. {
  11. name: '按距离排序',
  12. id: '距离排序',
  13. idx: 1
  14. },
  15. {
  16. name: '按热度排序',
  17. id: '热度排序',
  18. idx: 2
  19. }
  20. ]
  21. const typeItems = [
  22. {
  23. name: '展览中',
  24. id: '展览中',
  25. idx: 1
  26. },
  27. {
  28. name: '即将开始',
  29. id: '即将开始',
  30. idx: 2
  31. },
  32. {
  33. name: '已结束',
  34. id: '已结束',
  35. idx: 3
  36. },
  37. {
  38. name: '全部状态',
  39. id: '全部状态',
  40. idx: 0
  41. }
  42. ]
  43. Page({
  44. data: {
  45. navItem: distItems,
  46. indicatorDots: true,
  47. autoplay: true,
  48. interval: 5000,
  49. duration: 1000,
  50. activeIndex: 0,
  51. locationName: "珠海",
  52. locationNameDesp:"",
  53. isLike: false,
  54. showConfirm: false,
  55. tag: "",
  56. exhibitionList: [],
  57. commodityImgs: [
  58. '../../imgs/testImg/thumbSmallImg.jpg',
  59. '../../imgs/testImg/thumbSmallImg.jpg',
  60. ],
  61. type: 5,
  62. testImg: '../../imgs/testImg/fdkz.png',
  63. getLocationBtn: false,
  64. isShow: false,
  65. exhiNum:0,
  66. activeDist:'距离排序',
  67. activeType:'展览中'
  68. },
  69. to_search_exhibition: function () {
  70. wx.navigateTo({
  71. url: '../yuezhan/search/index',
  72. success: function (res) { },
  73. fail: function (res) { },
  74. complete: function (res) { },
  75. })
  76. },
  77. onLoad: function () {
  78. this.getLocationName();
  79. // this.getList(1)
  80. this.setData({
  81. serverName,
  82. noExhibitionImg,
  83. defaultImg,
  84. imgServer
  85. });
  86. },
  87. onShareAppMessage: function () {
  88. },
  89. onShow: function () {
  90. let { city, clickToSelect, collectedArr, collectedChange } = app.globalData;
  91. let { activeIndex, exhibitionList } = this.data
  92. if (clickToSelect) {
  93. this.setData({
  94. locationName: city || "珠海",
  95. exhibitionList: [],
  96. activeIndex: 0,
  97. type: 5
  98. });
  99. if (activeIndex == 1) {
  100. this.getNearByList(1);
  101. }
  102. else {
  103. this.getList(1);
  104. }
  105. }
  106. if (collectedChange) {
  107. for (let i = 0; i < exhibitionList.length; i++) {
  108. for (let j = 0; j < collectedArr.length; j++) {
  109. if (collectedArr[j].collectedId == exhibitionList[i].id) {
  110. exhibitionList[i].hasCollect = collectedArr[j].status
  111. if (exhibitionList[i].hasCollect) {
  112. exhibitionList[i].collectionsCount += 1;
  113. }
  114. else {
  115. exhibitionList[i].collectionsCount -= 1;
  116. }
  117. if (exhibitionList[i].collectionsCount < 0) {
  118. exhibitionList[i].collectionsCount = 0
  119. }
  120. }
  121. }
  122. }
  123. this.setData({
  124. exhibitionList
  125. })
  126. }
  127. app.globalData.clickToSelect = false;
  128. // app.globalData.collectedChange = false;
  129. },
  130. addLike: function (e) {
  131. let { type, id, idx } = e.currentTarget.dataset;
  132. let exhibitionList = this.data.exhibitionList;
  133. let { collectedArr, collectedChange } = app.globalData, hasItem = true;
  134. Toast.showToast2('loading');
  135. let loginSessionKey = wx.getStorageSync('token') || "";
  136. // if (loginSessionKey){
  137. request['isCollect']({
  138. loginSessionKey,
  139. exhibitionId: id,
  140. type: Number(type),
  141. }, "post", res => {
  142. if (res.data.code > -1) {
  143. for (let i = 0; i < collectedArr.length; i++) {
  144. if (collectedArr[i].collectedId && id == collectedArr[i].collectedId) {
  145. collectedArr[i] = {
  146. collectedId: id,
  147. status: res.data.data.hasCollect,
  148. }
  149. hasItem = false;
  150. }
  151. }
  152. if (hasItem) {
  153. collectedArr.push({
  154. collectedId: id,
  155. status: res.data.data.hasCollect,
  156. })
  157. }
  158. app.globalData.collectedArr = collectedArr;
  159. app.globalData.collectedChange = true;
  160. exhibitionList[idx].hasCollect = res.data.data.hasCollect
  161. this.setData({
  162. exhibitionList: exhibitionList
  163. })
  164. }
  165. }, err => {
  166. }, complete => {
  167. Toast.hideLoading();
  168. })
  169. // }
  170. },
  171. showDrop: function (e) {
  172. let tag = e.target.dataset.id
  173. let name = e.target.dataset.test
  174. if (tag==='type'){
  175. this.setData({
  176. navItem: {
  177. type: tag,
  178. name: name,
  179. arr: typeItems
  180. },
  181. isShow: !this.data.isShow
  182. })
  183. }
  184. else{
  185. this.setData({
  186. navItem: {
  187. type: tag,
  188. name: name,
  189. arr: distItems
  190. },
  191. isShow: !this.data.isShow
  192. })
  193. }
  194. },
  195. getLocationName: function () {
  196. // 调用接口
  197. wx.getLocation({
  198. type: 'wgs84',
  199. success: (res) => {
  200. this.setData({
  201. latitude: res.latitude,
  202. longitude: res.longitude
  203. })
  204. //2、根据坐标获取当前位置名称,显示在顶部:腾讯地图逆地址解析
  205. qqmapsdk.reverseGeocoder({
  206. location: {
  207. latitude: res.latitude,
  208. longitude: res.longitude
  209. },
  210. success: (res) => {
  211. let { city: locationName } = res.result.address_component;
  212. locationName = locationName.substring(0, 2);
  213. app.globalData.city = locationName;
  214. this.setData({
  215. locationName,
  216. locationNameDesp: locationName
  217. })
  218. this.getList(1)
  219. },
  220. fail: function (res) {
  221. this.setData({
  222. locationName: ""
  223. })
  224. },
  225. complete: function (res) {
  226. }
  227. });
  228. }
  229. })
  230. },
  231. offlineRecommend: function () {
  232. wx.getLocation({
  233. type: 'wgs84',
  234. success: (res) => {
  235. this.setData({
  236. latitude: res.latitude,
  237. longitude: res.longitude
  238. })
  239. }
  240. })
  241. let { latitude: lat, longitude: lng } = this.data;
  242. request["offlineRecommend"]({
  243. lat,
  244. lng,
  245. }, "", res => {
  246. this.setData({
  247. ExhibitionPopular: res.data.data
  248. })
  249. }, err => {
  250. }, complete => {
  251. })
  252. },
  253. getList: function (page) {
  254. let { locationNameDesp, locationName, latitude, longitude, activeDist, activeType } = this.data;
  255. let loginSessionKey = wx.getStorageSync("token");
  256. let sort = distItems.find(item => item.id === activeDist).idx
  257. let type = typeItems.find(item => item.id === activeType).idx
  258. this.setData({
  259. loading: true
  260. })
  261. request["getExhibitionListOffline"]({
  262. page: page,
  263. type: type,
  264. loginSessionKey,
  265. city: locationName,
  266. sort,
  267. type,
  268. lng: longitude,
  269. lat: latitude
  270. }, '', res => {
  271. let tempContent = this.data.exhibitionList
  272. ? this.data.exhibitionList
  273. : [];
  274. let { last: lastPage, totalPages, totalElements, content: exhibitionList } = res.data.data;
  275. exhibitionList.forEach((currentValue) => {
  276. currentValue.product ? currentValue.product.link = escape(currentValue.product.link) : '';
  277. })
  278. let { openTime } = exhibitionList;
  279. this.setData({
  280. currentPage: res.data.data.number + 1,
  281. lastPage,
  282. loading: false,
  283. exhibitionList: tempContent.concat(exhibitionList),
  284. exhiNum: totalElements
  285. });
  286. wx.stopPullDownRefresh();
  287. // WxParse.wxParseTemArray("replyTemArray", 'reply', replyArr.length, that)
  288. if (this.data.exhiNum <= 3){
  289. this.offlineRecommend();
  290. }
  291. }, err => {
  292. }, complete => {
  293. })
  294. },
  295. getNearByList: function (page) {
  296. let { type, locationName, latitude, longitude } = this.data;
  297. let loginSessionKey = wx.getStorageSync("token");
  298. wx.getSetting({
  299. success: res => {
  300. if (!res.authSetting['scope.userLocation']) {
  301. Toast.showToast('tip', "无法获取用户位置", () => {
  302. return;
  303. })
  304. this.setData({
  305. getLocationBtn: true
  306. })
  307. }
  308. else {
  309. this.setData({
  310. loading: true,
  311. getLocationBtn: false
  312. })
  313. if (!longitude && !latitude) {
  314. wx.getLocation({
  315. success: res => {
  316. let longitude = (this.longitude = res.longitude);
  317. let latitude = (this.latitude = res.latitude);
  318. request["getNearByList"]({
  319. page: page,
  320. loginSessionKey,
  321. city: locationName,
  322. lng: longitude,
  323. lat: latitude
  324. }, '', res => {
  325. let tempContent = this.data.exhibitionList
  326. ? this.data.exhibitionList
  327. : [];
  328. let { last: lastPage, totalPages, content: exhibitionList } = res.data.data;
  329. let { openTime } = exhibitionList;
  330. this.setData({
  331. currentPage: res.data.data.number + 1,
  332. lastPage,
  333. loading: false,
  334. longitude,
  335. latitude,
  336. exhibitionList: tempContent.concat(exhibitionList),
  337. });
  338. wx.stopPullDownRefresh();
  339. // WxParse.wxParseTemArray("replyTemArray", 'reply', replyArr.length, that)
  340. }, err => {
  341. }, complete => {
  342. })
  343. },
  344. })
  345. } else {
  346. request["getNearByList"]({
  347. page: page,
  348. loginSessionKey,
  349. city: locationName,
  350. lng: longitude,
  351. lat: latitude
  352. }, '', res => {
  353. let tempContent = this.data.exhibitionList
  354. ? this.data.exhibitionList
  355. : [];
  356. let { last: lastPage, totalPages, content: exhibitionList } = res.data.data;
  357. let { openTime } = exhibitionList;
  358. this.setData({
  359. currentPage: res.data.data.number + 1,
  360. lastPage,
  361. loading: false,
  362. exhibitionList: tempContent.concat(exhibitionList),
  363. });
  364. wx.stopPullDownRefresh();
  365. }, err => {
  366. }, complete => {
  367. })
  368. }
  369. }
  370. }
  371. })
  372. },
  373. closeDialog: function () {
  374. this.setData({
  375. showConfirm: false
  376. })
  377. },
  378. loadMore: function () {
  379. let { activeIndex } = this.data
  380. if (!this.data.lastPage) {
  381. if (activeIndex == 1) {
  382. this.getNearByList(this.data.currentPage + 1);
  383. }
  384. else {
  385. this.getList(this.data.currentPage + 1);
  386. }
  387. } else {
  388. return;
  389. }
  390. },
  391. onReachBottom: function () {
  392. if (!this.data.loading) {
  393. this.loadMore();
  394. }
  395. },
  396. tabClick: function (e) {
  397. this.setData({
  398. exhibitionList: [],
  399. activeIndex: e.currentTarget.id,
  400. type: e.currentTarget.dataset.tag,
  401. currentPage: 1
  402. });
  403. if (e.currentTarget.id == 1) {
  404. this.getNearByList(1);
  405. }
  406. else {
  407. this.getList(1);
  408. }
  409. },
  410. onIsclose: function (e) {
  411. this.setData({
  412. isShow: e.detail
  413. })
  414. },
  415. getActiveItem:function(e){
  416. let { activeDist, activeType} = e.detail
  417. this.setData({
  418. activeDist,
  419. activeType,
  420. exhibitionList:[]
  421. })
  422. this.getList(1)
  423. },
  424. to_search: function () {
  425. wx.navigateTo({
  426. url: './search/index',
  427. success: function (res) { },
  428. fail: function (res) { },
  429. complete: function (res) { },
  430. })
  431. }
  432. })