index.js 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387
  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. currentValue.product ? currentValue.product.link = escape(currentValue.product.link) : '';
  126. })
  127. this.setData({
  128. currentPage: res.data.data.number + 1,
  129. lastPage,
  130. loading: false,
  131. exhibitionList: tempContent.concat(exhibitionList),
  132. });
  133. console.log(exhibitionList)
  134. // WxParse.wxParseTemArray("replyTemArray", 'reply', replyArr.length, that)
  135. }, err => {
  136. }, complete => {
  137. wx.stopPullDownRefresh();
  138. })
  139. },
  140. getList: function(page) {
  141. let type = this.data.tag;
  142. this.setData({
  143. loading: true
  144. })
  145. if (this.data.latitude||this.data.longitude) {
  146. this.fetchData(page)
  147. } else {
  148. wx.getLocation({
  149. type: 'wgs84',
  150. success: (res) => {
  151. this.setData({
  152. latitude: res.latitude,
  153. longitude: res.longitude
  154. })
  155. this.fetchData(page)
  156. },
  157. fail: (res) => {
  158. this.fetchData(page)
  159. }
  160. })
  161. }
  162. },
  163. getBanner: function() {
  164. request["getBannerList"]({}, '', res => {
  165. let {
  166. content: commodityImgs
  167. } = res.data.data;
  168. // console.log("wdwdwd",commodityImgs)
  169. this.setData({
  170. commodityImgs: commodityImgs || []
  171. });
  172. console.log('banner', commodityImgs)
  173. }, err => {
  174. }, complete => {
  175. wx.stopPullDownRefresh()
  176. })
  177. },
  178. addLike: function(e) {
  179. let {
  180. type,
  181. id,
  182. idx
  183. } = e.currentTarget.dataset;
  184. console.log(idx, type, id)
  185. let likes = this.data.likes;
  186. likes[id] = !likes[id];
  187. let exhibitionList = this.data.exhibitionList;
  188. let {
  189. collectedArr,
  190. collectedChange
  191. } = app.globalData, hasItem = true;
  192. console.log('type', type)
  193. this.setData({
  194. likes: likes
  195. })
  196. Toast.showToast2('loading');
  197. let loginSessionKey = wx.getStorageSync('token') || "";
  198. // if (loginSessionKey){
  199. request['isCollect']({
  200. loginSessionKey,
  201. exhibitionId: id,
  202. type: Number(type),
  203. }, "post", res => {
  204. if (res.data.code > -1) {
  205. for (let i = 0; i < collectedArr.length; i++) {
  206. if (collectedArr[i].collectedId && id == collectedArr[i].collectedId) {
  207. console.log("true")
  208. collectedArr[i] = {
  209. collectedId: id,
  210. status: res.data.data.hasCollect,
  211. }
  212. hasItem = false;
  213. }
  214. }
  215. if (hasItem) {
  216. collectedArr.push({
  217. collectedId: id,
  218. status: res.data.data.hasCollect,
  219. })
  220. }
  221. app.globalData.collectedArr = collectedArr;
  222. app.globalData.collectedChange = true;
  223. exhibitionList[idx].hasCollect = res.data.data.hasCollect
  224. this.setData({
  225. exhibitionList: exhibitionList
  226. })
  227. }
  228. }, err => {
  229. }, complete => {
  230. Toast.hideLoading();
  231. })
  232. // }
  233. console.log(this.data.exhibitionList)
  234. },
  235. tabClick: function(e) {
  236. // console.log(e.currentTarget.dataset)
  237. // if (e.currentTarget.id == 1) {
  238. // wx.switchTab({
  239. // url: '../swkz/index',
  240. // success: function (res) { },
  241. // fail: function (res) { },
  242. // complete: function (res) { },
  243. // })
  244. // }
  245. // else {
  246. this.setData({
  247. exhibitionList: [],
  248. activeIndex: e.currentTarget.id,
  249. tag: e.currentTarget.dataset.tag,
  250. currentPage: 1
  251. });
  252. this.getList(1);
  253. // }
  254. },
  255. onShareAppMessage: function() {
  256. },
  257. to_pay: function(e) {
  258. // console.log('dwdwdw', e.currentTarget.dataset)
  259. let {
  260. url,
  261. pagetype,
  262. urltype,
  263. hasproduct,
  264. haspay,
  265. productlink,
  266. id
  267. } = e.currentTarget.dataset;
  268. console.log(e.currentTarget.dataset)
  269. app.globalData.currentUrl = url
  270. console.log('dwdwdw', app.globalData.currentUrl)
  271. // console.log('dwdwdwd',wx.getStorageSync('url'))
  272. switch (urltype) {
  273. case 0:
  274. wx.navigateTo({
  275. url: `../wv_page/index`,
  276. success: function(res) {},
  277. fail: function(res) {},
  278. complete: function(res) {},
  279. })
  280. break;
  281. case 1:
  282. switch (pagetype) {
  283. case 0:
  284. wx.navigateTo({
  285. url: `../cg_detail/index?id=${url}`,
  286. success: function(res) {},
  287. fail: function(res) {},
  288. complete: function(res) {},
  289. })
  290. break;
  291. case 1:
  292. if (hasproduct) {
  293. wx.navigateTo({
  294. url: `../wv_page/index?link=${escape(productlink)}&id=${id}`,
  295. success: function(res) {},
  296. fail: function(res) {},
  297. complete: function(res) {},
  298. })
  299. } else {
  300. wx.navigateTo({
  301. url: `../zl_detail/index?id=${url}`,
  302. success: function(res) {},
  303. fail: function(res) {},
  304. complete: function(res) {},
  305. })
  306. }
  307. break;
  308. default:
  309. break;
  310. }
  311. break;
  312. default:
  313. break;
  314. }
  315. // let { url } = e.currentTarget.dataset;
  316. // app.globalData.currentUrl = url
  317. // console.log('dwdwdw', app.globalData.currentUrl)
  318. // // console.log('dwdwdwd',wx.getStorageSync('url'))
  319. // if (String(url).indexOf('http')>-1){
  320. // wx.navigateTo({
  321. // url: `../wv_page/index`,
  322. // success: function (res) { },
  323. // fail: function (res) { },
  324. // complete: function (res) { },
  325. // })
  326. // }else{
  327. // wx.navigateTo({
  328. // url: `../zl_detail/index?id=${url}`,
  329. // success: function (res) { },
  330. // fail: function (res) { },
  331. // complete: function (res) { },
  332. // })
  333. // }
  334. }
  335. })