index.js 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388
  1. //index.js
  2. const {
  3. request,
  4. serverName,
  5. imgServer
  6. } = require('../../utils/services');
  7. const {
  8. Toast
  9. } = require('../../utils/util.js');
  10. const {
  11. defaultImg,
  12. noExhibitionImg,
  13. closeImg
  14. } = require('../../utils/images');
  15. const WxParse = require('../../common/component/wxParse/wxParse.js');
  16. const app = getApp();
  17. Page({
  18. data: {
  19. // navItem: [{ title: '热门', tag: 0 }, { title: '即将开始', tag: 2 }, { title: '展览中', tag: 4 }, { title: '已结束', tag: 6 }],
  20. indicatorDots: true,
  21. autoplay: true,
  22. interval: 2000,
  23. duration: 1000,
  24. activeIndex: 0,
  25. animationData: {},
  26. loading: false,
  27. isLike: true,
  28. commodityImgs: [],
  29. testImg: '../../imgs/testImg/fdkz.png',
  30. currentPage: 1,
  31. exhibitionList: [],
  32. likes: {},
  33. tag: 0,
  34. latitude: null,
  35. longitude: null,
  36. showRecommend:false
  37. },
  38. onLoad: function() {
  39. this.setData({
  40. serverName,
  41. defaultImg,
  42. noExhibitionImg,
  43. imgServer,
  44. closeImg,
  45. showRecommend:true
  46. // isLogin
  47. })
  48. this.getBanner();
  49. this.getList(1);
  50. wx.hideTabBar()
  51. },
  52. loadMore: function() {
  53. if (!this.data.lastPage) {
  54. console.log(this.data.currentPage + 1)
  55. this.getList(this.data.currentPage + 1);
  56. } else {
  57. return;
  58. }
  59. },
  60. onReachBottom: function() {
  61. if (!this.data.loading) {
  62. this.loadMore();
  63. console.log('reach Bottom');
  64. }
  65. },
  66. onShow: function() {
  67. let {
  68. collectedArr,
  69. collectedChange
  70. } = app.globalData;
  71. let {
  72. exhibitionList
  73. } = this.data
  74. let isLogin = app.globalData.isLogin;
  75. this.setData({
  76. isLogin
  77. })
  78. if (collectedChange) {
  79. for (let i = 0; i < exhibitionList.length; i++) {
  80. for (let j = 0; j < collectedArr.length; j++) {
  81. if (collectedArr[j].collectedId == exhibitionList[i].id) {
  82. exhibitionList[i].hasCollect = collectedArr[j].status
  83. if (exhibitionList[i].hasCollect) {
  84. exhibitionList[i].collectionsCount += 1;
  85. } else {
  86. exhibitionList[i].collectionsCount -= 1;
  87. }
  88. if (exhibitionList[i].collectionsCount < 0) {
  89. exhibitionList[i].collectionsCount = 0
  90. }
  91. }
  92. }
  93. // console.log(collectedArr.status, collectedArr.collectedId)
  94. }
  95. this.setData({
  96. exhibitionList,
  97. })
  98. }
  99. // app.globalData.clickToSelect = false;
  100. app.globalData.collectedChange = false;
  101. },
  102. onPullDownRefresh: function() {
  103. this.setData({
  104. exhibitionList: [],
  105. currentPage: 1
  106. });
  107. this.getBanner();
  108. this.getList(1);
  109. },
  110. hideRecommend:function(){
  111. this.setData({
  112. showRecommend:false
  113. })
  114. wx.showTabBar()
  115. },
  116. fetchData: function (page){
  117. request["getExhibitionList"]({
  118. page: page,
  119. type: 0,
  120. lat: this.data.latitude,
  121. lng: this.data.longitude
  122. }, '', res => {
  123. let tempContent = this.data.exhibitionList ?
  124. this.data.exhibitionList :
  125. [];
  126. let {
  127. last: lastPage,
  128. totalPages,
  129. content: exhibitionList
  130. } = res.data.data;
  131. let {
  132. openTime
  133. } = exhibitionList;
  134. console.log(res)
  135. exhibitionList.forEach((currentValue) => {
  136. currentValue.distance = Math.ceil(currentValue.distance);
  137. if (currentValue.product){
  138. currentValue.product.link = escape(currentValue.product.link);
  139. currentValue.product.imageUrl = escape(currentValue.product.imageUrl);
  140. }
  141. })
  142. this.setData({
  143. currentPage: res.data.data.number + 1,
  144. lastPage,
  145. loading: false,
  146. exhibitionList: tempContent.concat(exhibitionList),
  147. });
  148. console.log(exhibitionList)
  149. // WxParse.wxParseTemArray("replyTemArray", 'reply', replyArr.length, that)
  150. }, err => {
  151. }, complete => {
  152. wx.stopPullDownRefresh();
  153. })
  154. },
  155. getList: function(page) {
  156. let type = this.data.tag;
  157. this.setData({
  158. loading: true
  159. })
  160. if (this.data.latitude||this.data.longitude) {
  161. this.fetchData(page)
  162. } else {
  163. wx.getLocation({
  164. type: 'wgs84',
  165. success: (res) => {
  166. this.setData({
  167. latitude: res.latitude,
  168. longitude: res.longitude
  169. })
  170. this.fetchData(page)
  171. },
  172. fail: (res) => {
  173. this.fetchData(page)
  174. }
  175. })
  176. }
  177. },
  178. getBanner: function() {
  179. request["getBannerList"]({}, '', res => {
  180. let {
  181. content: commodityImgs
  182. } = res.data.data;
  183. // console.log("wdwdwd",commodityImgs)
  184. this.setData({
  185. commodityImgs: commodityImgs || []
  186. });
  187. console.log('banner', commodityImgs)
  188. }, err => {
  189. }, complete => {
  190. wx.stopPullDownRefresh()
  191. })
  192. },
  193. addLike: function(e) {
  194. let {
  195. type,
  196. id,
  197. idx
  198. } = e.currentTarget.dataset;
  199. console.log(idx, type, id)
  200. let likes = this.data.likes;
  201. likes[id] = !likes[id];
  202. let exhibitionList = this.data.exhibitionList;
  203. let {
  204. collectedArr,
  205. collectedChange
  206. } = app.globalData, hasItem = true;
  207. console.log('type', type)
  208. this.setData({
  209. likes: likes
  210. })
  211. Toast.showToast2('loading');
  212. let loginSessionKey = wx.getStorageSync('token') || "";
  213. // if (loginSessionKey){
  214. request['isCollect']({
  215. loginSessionKey,
  216. exhibitionId: id,
  217. type: Number(type),
  218. }, "post", res => {
  219. if (res.data.code > -1) {
  220. for (let i = 0; i < collectedArr.length; i++) {
  221. if (collectedArr[i].collectedId && id == collectedArr[i].collectedId) {
  222. console.log("true")
  223. collectedArr[i] = {
  224. collectedId: id,
  225. status: res.data.data.hasCollect,
  226. }
  227. hasItem = false;
  228. }
  229. }
  230. if (hasItem) {
  231. collectedArr.push({
  232. collectedId: id,
  233. status: res.data.data.hasCollect,
  234. })
  235. }
  236. app.globalData.collectedArr = collectedArr;
  237. app.globalData.collectedChange = true;
  238. exhibitionList[idx].hasCollect = res.data.data.hasCollect
  239. this.setData({
  240. exhibitionList: exhibitionList
  241. })
  242. }
  243. }, err => {
  244. }, complete => {
  245. Toast.hideLoading();
  246. })
  247. // }
  248. console.log(this.data.exhibitionList)
  249. },
  250. tabClick: function(e) {
  251. // console.log(e.currentTarget.dataset)
  252. // if (e.currentTarget.id == 1) {
  253. // wx.switchTab({
  254. // url: '../swkz/index',
  255. // success: function (res) { },
  256. // fail: function (res) { },
  257. // complete: function (res) { },
  258. // })
  259. // }
  260. // else {
  261. this.setData({
  262. exhibitionList: [],
  263. activeIndex: e.currentTarget.id,
  264. tag: e.currentTarget.dataset.tag,
  265. currentPage: 1
  266. });
  267. this.getList(1);
  268. // }
  269. },
  270. onShareAppMessage: function() {
  271. },
  272. to_pay: function(e) {
  273. // console.log('dwdwdw', e.currentTarget.dataset)
  274. let {
  275. url,
  276. pagetype,
  277. urltype,
  278. hasproduct,
  279. haspay,
  280. productlink,
  281. id,
  282. description,
  283. imageurl,
  284. relayUrl
  285. } = e.currentTarget.dataset;
  286. // app.globalData.currentUrl = url
  287. // console.log('dwdwdw', app.globalData.currentUrl)
  288. // console.log('dwdwdwd',wx.getStorageSync('url'))
  289. switch (urltype) {
  290. case 0:
  291. wx.navigateTo({
  292. url: `../wv_page/index`,
  293. success: function(res) {},
  294. fail: function(res) {},
  295. complete: function(res) {},
  296. })
  297. break;
  298. case 1:
  299. switch (pagetype) {
  300. case 0:
  301. wx.navigateTo({
  302. url: `../cg_detail/index?id=${url}`,
  303. success: function(res) {},
  304. fail: function(res) {},
  305. complete: function(res) {},
  306. })
  307. break;
  308. case 1:
  309. if (hasproduct) {
  310. wx.navigateTo({
  311. url: `../wv_page/index?&id=${url}`,
  312. success: function(res) {},
  313. fail: function(res) {},
  314. complete: function(res) {},
  315. })
  316. } else {
  317. wx.navigateTo({
  318. url: `../zl_detail/index?id=${url}`,
  319. success: function(res) {},
  320. fail: function(res) {},
  321. complete: function(res) {},
  322. })
  323. }
  324. break;
  325. default:
  326. break;
  327. }
  328. break;
  329. case 2:
  330. app.globalData.bannerHtml = description;
  331. wx.navigateTo({
  332. url: `./html_detail/index?id=${id}&imageUrl=${imageurl}&relayUrl=${relayUrl||''}`,
  333. success: function (res) { },
  334. fail: function (res) { },
  335. complete: function (res) { },
  336. })
  337. break;
  338. default:
  339. break;
  340. }
  341. }
  342. })