index.js 8.5 KB

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