index.js 8.9 KB

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