index.js 12 KB

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