index.js 8.3 KB

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