index.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517
  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. console.log(this.data)
  87. },
  88. onShareAppMessage: function () {
  89. },
  90. onShow: function () {
  91. let { city, clickToSelect, collectedArr, collectedChange } = app.globalData;
  92. let { activeIndex, exhibitionList } = this.data
  93. if (clickToSelect) {
  94. // console.log(city)
  95. this.setData({
  96. locationName: city || "珠海",
  97. exhibitionList: [],
  98. activeIndex: 0,
  99. type: 5
  100. });
  101. if (activeIndex == 1) {
  102. this.getNearByList(1);
  103. }
  104. else {
  105. this.getList(1);
  106. }
  107. }
  108. if (collectedChange) {
  109. for (let i = 0; i < exhibitionList.length; i++) {
  110. for (let j = 0; j < collectedArr.length; j++) {
  111. if (collectedArr[j].collectedId == exhibitionList[i].id) {
  112. exhibitionList[i].hasCollect = collectedArr[j].status
  113. if (exhibitionList[i].hasCollect) {
  114. exhibitionList[i].collectionsCount += 1;
  115. }
  116. else {
  117. exhibitionList[i].collectionsCount -= 1;
  118. }
  119. if (exhibitionList[i].collectionsCount < 0) {
  120. exhibitionList[i].collectionsCount = 0
  121. }
  122. }
  123. }
  124. // console.log(collectedArr.status, collectedArr.collectedId)
  125. }
  126. this.setData({
  127. exhibitionList
  128. })
  129. }
  130. app.globalData.clickToSelect = false;
  131. // app.globalData.collectedChange = false;
  132. },
  133. addLike: function (e) {
  134. let { type, id, idx } = e.currentTarget.dataset;
  135. console.log(idx, type, id)
  136. let exhibitionList = this.data.exhibitionList;
  137. let { collectedArr, collectedChange } = app.globalData, hasItem = true;
  138. console.log('type', type)
  139. Toast.showToast2('loading');
  140. let loginSessionKey = wx.getStorageSync('token') || "";
  141. // if (loginSessionKey){
  142. request['isCollect']({
  143. loginSessionKey,
  144. exhibitionId: id,
  145. type: Number(type),
  146. }, "post", res => {
  147. if (res.data.code > -1) {
  148. for (let i = 0; i < collectedArr.length; i++) {
  149. if (collectedArr[i].collectedId && id == collectedArr[i].collectedId) {
  150. console.log("true")
  151. collectedArr[i] = {
  152. collectedId: id,
  153. status: res.data.data.hasCollect,
  154. }
  155. hasItem = false;
  156. }
  157. }
  158. if (hasItem) {
  159. collectedArr.push({
  160. collectedId: id,
  161. status: res.data.data.hasCollect,
  162. })
  163. }
  164. app.globalData.collectedArr = collectedArr;
  165. app.globalData.collectedChange = true;
  166. exhibitionList[idx].hasCollect = res.data.data.hasCollect
  167. this.setData({
  168. exhibitionList: exhibitionList
  169. })
  170. }
  171. }, err => {
  172. }, complete => {
  173. Toast.hideLoading();
  174. })
  175. // }
  176. console.log(this.data.exhibitionList)
  177. },
  178. showDrop: function (e) {
  179. let tag = e.target.dataset.id
  180. console.log(e)
  181. let name = e.target.dataset.test
  182. console.log(tag)
  183. if (tag==='type'){
  184. this.setData({
  185. navItem: {
  186. type: tag,
  187. name: name,
  188. arr: typeItems
  189. },
  190. isShow: !this.data.isShow
  191. })
  192. }
  193. else{
  194. this.setData({
  195. navItem: {
  196. type: tag,
  197. name: name,
  198. arr: distItems
  199. },
  200. isShow: !this.data.isShow
  201. })
  202. }
  203. },
  204. getLocationName: function () {
  205. // 调用接口
  206. wx.getLocation({
  207. type: 'wgs84',
  208. success: (res) => {
  209. this.setData({
  210. latitude: res.latitude,
  211. longitude: res.longitude
  212. })
  213. //2、根据坐标获取当前位置名称,显示在顶部:腾讯地图逆地址解析
  214. qqmapsdk.reverseGeocoder({
  215. location: {
  216. latitude: res.latitude,
  217. longitude: res.longitude
  218. },
  219. success: (res) => {
  220. let { city: locationName } = res.result.address_component;
  221. locationName = locationName.substring(0, 2);
  222. console.log(locationName);
  223. app.globalData.city = locationName;
  224. this.setData({
  225. locationName,
  226. locationNameDesp: locationName
  227. })
  228. this.getList(1)
  229. },
  230. fail: function (res) {
  231. console.log(res)
  232. this.setData({
  233. locationName: ""
  234. })
  235. },
  236. complete: function (res) {
  237. console.log(res);
  238. }
  239. });
  240. }
  241. })
  242. },
  243. offlineRecommend: function () {
  244. wx.getLocation({
  245. type: 'wgs84',
  246. success: (res) => {
  247. this.setData({
  248. latitude: res.latitude,
  249. longitude: res.longitude
  250. })
  251. }
  252. })
  253. let { latitude: lat, longitude: lng } = this.data;
  254. request["offlineRecommend"]({
  255. lat,
  256. lng,
  257. }, "", res => {
  258. this.setData({
  259. ExhibitionPopular: res.data.data
  260. })
  261. console.log(this.data.ExhibitionPopular)
  262. }, err => {
  263. }, complete => {
  264. })
  265. },
  266. getList: function (page) {
  267. let { locationNameDesp, locationName, latitude, longitude, activeDist, activeType } = this.data;
  268. let loginSessionKey = wx.getStorageSync("token");
  269. let sort = distItems.find(item => item.id === activeDist).idx
  270. let type = typeItems.find(item => item.id === activeType).idx
  271. console.log(sort, type)
  272. console.log(page)
  273. console.log(type, locationName, latitude, longitude);
  274. console.log(locationNameDesp)
  275. this.setData({
  276. loading: true
  277. })
  278. request["getExhibitionListOffline"]({
  279. page: page,
  280. type: type,
  281. loginSessionKey,
  282. city: locationName,
  283. sort,
  284. type,
  285. lng: longitude,
  286. lat: latitude
  287. }, '', res => {
  288. let tempContent = this.data.exhibitionList
  289. ? this.data.exhibitionList
  290. : [];
  291. let { last: lastPage, totalPages, totalElements, content: exhibitionList } = res.data.data;
  292. exhibitionList.forEach((currentValue) => {
  293. currentValue.product ? currentValue.product.link = escape(currentValue.product.link) : '';
  294. })
  295. let { openTime } = exhibitionList;
  296. this.setData({
  297. currentPage: res.data.data.number + 1,
  298. lastPage,
  299. loading: false,
  300. exhibitionList: tempContent.concat(exhibitionList),
  301. exhiNum: totalElements
  302. });
  303. console.log(this.data.exhibitionList)
  304. console.log(res.data.data)
  305. wx.stopPullDownRefresh();
  306. // WxParse.wxParseTemArray("replyTemArray", 'reply', replyArr.length, that)
  307. if (this.data.exhiNum <= 3){
  308. this.offlineRecommend();
  309. }
  310. }, err => {
  311. }, complete => {
  312. })
  313. },
  314. getNearByList: function (page) {
  315. let { type, locationName, latitude, longitude } = this.data;
  316. let loginSessionKey = wx.getStorageSync("token");
  317. wx.getSetting({
  318. success: res => {
  319. if (!res.authSetting['scope.userLocation']) {
  320. Toast.showToast('tip', "无法获取用户位置", () => {
  321. return;
  322. })
  323. this.setData({
  324. getLocationBtn: true
  325. })
  326. }
  327. else {
  328. this.setData({
  329. loading: true,
  330. getLocationBtn: false
  331. })
  332. if (!longitude && !latitude) {
  333. wx.getLocation({
  334. success: res => {
  335. let longitude = (this.longitude = res.longitude);
  336. let latitude = (this.latitude = res.latitude);
  337. request["getNearByList"]({
  338. page: page,
  339. loginSessionKey,
  340. city: locationName,
  341. lng: longitude,
  342. lat: latitude
  343. }, '', res => {
  344. let tempContent = this.data.exhibitionList
  345. ? this.data.exhibitionList
  346. : [];
  347. let { last: lastPage, totalPages, content: exhibitionList } = res.data.data;
  348. let { openTime } = exhibitionList;
  349. console.log(res)
  350. this.setData({
  351. currentPage: res.data.data.number + 1,
  352. lastPage,
  353. loading: false,
  354. longitude,
  355. latitude,
  356. exhibitionList: tempContent.concat(exhibitionList),
  357. });
  358. console.log(exhibitionList)
  359. wx.stopPullDownRefresh();
  360. // WxParse.wxParseTemArray("replyTemArray", 'reply', replyArr.length, that)
  361. }, err => {
  362. }, complete => {
  363. })
  364. },
  365. })
  366. } else {
  367. request["getNearByList"]({
  368. page: page,
  369. loginSessionKey,
  370. city: locationName,
  371. lng: longitude,
  372. lat: latitude
  373. }, '', res => {
  374. let tempContent = this.data.exhibitionList
  375. ? this.data.exhibitionList
  376. : [];
  377. let { last: lastPage, totalPages, content: exhibitionList } = res.data.data;
  378. let { openTime } = exhibitionList;
  379. console.log(res)
  380. this.setData({
  381. currentPage: res.data.data.number + 1,
  382. lastPage,
  383. loading: false,
  384. exhibitionList: tempContent.concat(exhibitionList),
  385. });
  386. console.log(exhibitionList)
  387. wx.stopPullDownRefresh();
  388. }, err => {
  389. }, complete => {
  390. })
  391. }
  392. }
  393. }
  394. })
  395. },
  396. closeDialog: function () {
  397. this.setData({
  398. showConfirm: false
  399. })
  400. },
  401. loadMore: function () {
  402. let { activeIndex } = this.data
  403. if (!this.data.lastPage) {
  404. console.log(this.data.currentPage + 1)
  405. if (activeIndex == 1) {
  406. this.getNearByList(this.data.currentPage + 1);
  407. }
  408. else {
  409. this.getList(this.data.currentPage + 1);
  410. }
  411. } else {
  412. return;
  413. }
  414. },
  415. onReachBottom: function () {
  416. if (!this.data.loading) {
  417. this.loadMore();
  418. console.log('reach Bottom');
  419. }
  420. },
  421. tabClick: function (e) {
  422. // console.log(e.currentTarget.dataset)
  423. this.setData({
  424. exhibitionList: [],
  425. activeIndex: e.currentTarget.id,
  426. type: e.currentTarget.dataset.tag,
  427. currentPage: 1
  428. });
  429. if (e.currentTarget.id == 1) {
  430. this.getNearByList(1);
  431. }
  432. else {
  433. this.getList(1);
  434. }
  435. },
  436. onIsclose: function (e) {
  437. this.setData({
  438. isShow: e.detail
  439. })
  440. },
  441. getActiveItem:function(e){
  442. console.log(e)
  443. let { activeDist, activeType} = e.detail
  444. this.setData({
  445. activeDist,
  446. activeType,
  447. exhibitionList:[]
  448. })
  449. this.getList(1)
  450. },
  451. to_search: function () {
  452. wx.navigateTo({
  453. url: './search/index',
  454. success: function (res) { },
  455. fail: function (res) { },
  456. complete: function (res) { },
  457. })
  458. }
  459. })