index.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418
  1. const util = require('../../utils/util.js');
  2. const app = getApp();
  3. // var crypto = require('../../utils/crypto.js');//注意路径是否正确
  4. Page({
  5. data: {
  6. region: '',
  7. showVideoColumn: 0,
  8. pageIndex: 1, //当前页
  9. activeData: [], //活动列表
  10. historyData: [], //往期活动列表
  11. bottom: false,
  12. imgPath: '',
  13. showBack: false,
  14. screenHid: true,
  15. info: {},
  16. openTips: wx.getStorageSync("safeTips") || {
  17. "num": 0,
  18. "oldDate": util.getNowFormatDate('yyyy-MM-dd')
  19. },
  20. screen: [{
  21. id: 0,
  22. txt: '全部'
  23. }, {
  24. id: 1,
  25. txt: '周末单日'
  26. }, {
  27. id: 2,
  28. txt: '小长假'
  29. }, {
  30. id: 3,
  31. txt: '冬夏令营'
  32. }, {
  33. id: 4,
  34. txt: '往期活动'
  35. }],
  36. days: 0,
  37. default: [{
  38. id: 0,
  39. txt: '默认排序'
  40. }, {
  41. id: 1,
  42. txt: '开始时间由近到远'
  43. }, {
  44. id: 2,
  45. txt: '人气从高到低'
  46. }],
  47. sort: 0,
  48. defaultHid: true,
  49. activityStatus: true, // true - 上架活动可继续查询 false - 不可继续查询
  50. HistorypageIndex: 1,
  51. tabbar: {}
  52. },
  53. openServicePopup() {
  54. this.setData({
  55. showChat: true
  56. })
  57. },
  58. closeChat(e) {
  59. this.setData({
  60. showChat: e.detail
  61. })
  62. },
  63. // 获取弹窗广告信息
  64. safetyTip() {
  65. let that = this,
  66. safeTips = wx.getStorageSync("safeTips"),
  67. getInfo = {};
  68. util.ajax({
  69. func: '/v2/index/advert/popup',
  70. load: false
  71. }, function (res) {
  72. if (res.code == 0) {
  73. getInfo.data = res.data;
  74. getInfo.entryPage = 'homePage';
  75. getInfo.showPopup = true;
  76. that.safeTip = that.selectComponent('#safeTip');
  77. that.safeTip.getSafeTips(getInfo);
  78. }
  79. })
  80. this.setData({
  81. isShow: safeTips.show
  82. });
  83. },
  84. onLoad(options) {
  85. console.log(options)
  86. app.editTabbar();
  87. let that = this;
  88. // this.safetyTip();
  89. this.setData({
  90. imgPath: util.config.imgPath
  91. });
  92. if (!util.isEmpty(options.scene)) {
  93. // 调用渠道访问记录接口
  94. let channelParam = options.scene.replace("channel%3D", "").replace("channel=", ""),
  95. that = this;
  96. // wx.setStorageSync("channelCode",{channel:channelParam,channelTimes:1});
  97. util.config.channelInfo = {
  98. channel: channelParam,
  99. channelTimes: 1
  100. }
  101. util.getChannelMsg(channelParam).then((res) => {
  102. console.log('是否创建渠道记录', res)
  103. });
  104. }
  105. this.safetyTip();
  106. if (options.invite) {
  107. wx.setStorageSync("WX-invite", options.invite);
  108. }
  109. if (options.channel) {
  110. util.config.channelInfo = {
  111. channel: options.channel,
  112. channelTimes: 1
  113. }
  114. util.getChannelMsg(options.channel)
  115. }
  116. },
  117. info() {
  118. let that = this;
  119. util.ajax({
  120. func: "v2/categoryHomePageChallenge/info",
  121. data: {},
  122. load: false
  123. }, function (res) {
  124. if (res.code == 0) {
  125. that.setData({
  126. info: res.data
  127. });
  128. }
  129. });
  130. },
  131. comfun() {
  132. this.setData({
  133. region: app.globalData.city.city || '',
  134. activityStatus: true
  135. });
  136. this.info();
  137. this.getHotActivity(1, 0, false, this.data.days, this.data.sort);
  138. this.reportAnalytics(app.globalData.city.city); //上报定位城市
  139. },
  140. onShow() {
  141. let that = this;
  142. // util.promise().then(function (value) {
  143. that.comfun();
  144. var previous = app.globalData.previous; //选择前城市
  145. console.log(previous, 68686)
  146. var region = '永康';
  147. that.setData({
  148. region,
  149. activityStatus: true
  150. });
  151. if (previous && region && previous != region) {
  152. app.globalData.previous = region;
  153. that.info();
  154. that.getHotActivity(1, 0, false, this.data.days, this.data.sort);
  155. }
  156. // });
  157. },
  158. reportAnalytics(city) {
  159. wx.reportAnalytics('location', {
  160. city
  161. });
  162. },
  163. onReachBottom() {
  164. if (!this.data.bottom) {
  165. wx.showNavigationBarLoading();
  166. this.getHotActivity((this.data.days == 4 || !this.data.activityStatus) ? (this.data.HistorypageIndex + 1) : (this.data.pageIndex + 1), 1, false, this.data.days, this.data.sort)
  167. }
  168. },
  169. onPageScroll(e) {
  170. var showBack = this.data.showBack;
  171. if (e.scrollTop > 800 && !showBack) {
  172. this.setData({
  173. showBack: true
  174. })
  175. } else if (e.scrollTop <= 800 && showBack) {
  176. this.setData({
  177. showBack: false
  178. })
  179. }
  180. // 筛选
  181. let screenHid = this.data.screenHid,
  182. that = this;
  183. var query = wx.createSelectorQuery();
  184. query.select('#screen').boundingClientRect();
  185. query.exec(function (res) {
  186. // if (screenHid && res && res[0].top <= 50) {
  187. // that.setData({
  188. // screenHid: false
  189. // })
  190. // } else if (!screenHid && res && res[0].top > 50) {
  191. // that.setData({
  192. // screenHid: true
  193. // })
  194. // }
  195. })
  196. },
  197. onPullDownRefresh() {
  198. let that = this;
  199. if (!util.isObjEmpty(app.globalData.city)) {
  200. wx.showNavigationBarLoading();
  201. // that.setData({ region: app.globalData.city.city });
  202. setTimeout(function () {
  203. that.info();
  204. that.getHotActivity(1, 2, true, that.data.days, that.data.sort);
  205. }, 1000);
  206. } else {
  207. wx.stopPullDownRefresh();
  208. }
  209. },
  210. // 获取当前活动
  211. getHotActivity(pageIndex, status, PullDown, days, sort) {
  212. let that = this;
  213. if (days != 4 && this.data.activityStatus) {
  214. util.ajax({
  215. func: "v2/article/recom_list",
  216. data: {
  217. "pageIndex": pageIndex,
  218. "pageSize": 10,
  219. 'type': days || 0,
  220. 'sort': sort || 0
  221. },
  222. load: false
  223. }, function (res) {
  224. console.log(res);
  225. if (res.code == 0) {
  226. res.data.list.map(el => {
  227. if (!util.isEmpty(el.discount)) {
  228. let arr = [];
  229. if (el.discount.indexOf('+') == -1) {
  230. arr.push(el.discount);
  231. } else {
  232. arr = el.discount.split('+');
  233. }
  234. el.discount = arr;
  235. }
  236. });
  237. let datas = res.data.list,
  238. activeData = that.data.activeData,
  239. bottom = false,
  240. imgPath = that.data.imgPath;
  241. if (datas.length < 10) {
  242. // bottom = true;
  243. that.data.activityStatus = false;
  244. that.getHistoryActive(1, days, status)
  245. }
  246. activeData = pageIndex == 1 ? datas : [...activeData, ...datas];
  247. that.setData({
  248. activeData,
  249. pageIndex,
  250. bottom,
  251. days,
  252. sort,
  253. activityStatus: that.data.activityStatus
  254. })
  255. wx.hideNavigationBarLoading()
  256. } else {
  257. util.showTips(res.reason);
  258. }
  259. // if (status == '0') {//onshow
  260. // } else if (status == '1') {//onReachBottom
  261. // wx.hideNavigationBarLoading();
  262. // } else if (status == '2') {//onPullDownRefresh
  263. // wx.stopPullDownRefresh();
  264. // wx.hideNavigationBarLoading();
  265. // }
  266. });
  267. } else {
  268. this.getHistoryActive(pageIndex, days, status)
  269. }
  270. },
  271. // 获取往期活动
  272. getHistoryActive(pageIndex, days, status) {
  273. let that = this;
  274. util.ajax({
  275. func: "v2/article/history_list",
  276. data: {
  277. "pageIndex": pageIndex,
  278. "pageSize": 10
  279. },
  280. load: false
  281. }, function (res) {
  282. if (res.code == 0) {
  283. res.data.list.map(el => {
  284. if (!util.isEmpty(el.discount)) {
  285. let arr = [];
  286. if (el.discount.indexOf('+') == -1) {
  287. arr.push(el.discount);
  288. } else {
  289. arr = el.discount.split('+');
  290. }
  291. el.discount = arr;
  292. }
  293. });
  294. let datas = res.data.list,
  295. historyData = that.data.historyData,
  296. bottom = false,
  297. imgPath = that.data.imgPath;
  298. if (datas.length < 10) bottom = true;
  299. historyData = pageIndex == 1 ? datas : [...historyData, ...datas];
  300. that.setData({
  301. historyData,
  302. HistorypageIndex: pageIndex,
  303. bottom,
  304. days
  305. })
  306. } else {
  307. util.showTips(res.reason);
  308. }
  309. if (status == '0') { //onshow
  310. } else if (status == '1') { //onReachBottom
  311. wx.hideNavigationBarLoading();
  312. } else if (status == '2') { //onPullDownRefresh
  313. wx.stopPullDownRefresh();
  314. wx.hideNavigationBarLoading();
  315. }
  316. });
  317. },
  318. navigator(e) {
  319. util.navigator(e.currentTarget.dataset.url);
  320. },
  321. navigatorCols(e) {
  322. let data = e.currentTarget.dataset,
  323. info = this.data.info[data.type][data.index],
  324. url = '';
  325. console.log(data, info)
  326. if (data.type == 'cyclePositions') {
  327. wx.reportAnalytics('swipe', {
  328. aid: data.id,
  329. title: data.title,
  330. });
  331. }
  332. // 类目类型 0 公众号推文 1 活动视频 2 指定活动合集
  333. let canJump = true;
  334. switch (info.categoryType) {
  335. case 2:
  336. url = '/pages/public/swiper/list?id=' + info.id + '&title=' + info.title;
  337. break;
  338. case 1:
  339. url = '/pages/public/video/video';
  340. break;
  341. case 0:
  342. url = '/pages/public/swiper/web?url=' + encodeURIComponent(info.url) + '&title=' + encodeURIComponent(info.title)
  343. break;
  344. }
  345. console.log(url)
  346. if (canJump) {
  347. wx.navigateTo({
  348. url: url
  349. });
  350. }
  351. },
  352. navigatorLive() {
  353. wx.navigateTo({
  354. url: '/pages/public/live/list'
  355. });
  356. },
  357. toTop() {
  358. wx.pageScrollTo({
  359. scrollTop: 0,
  360. duration: 500
  361. })
  362. },
  363. // 选择活动类型
  364. chooseScreen(e) {
  365. wx.showNavigationBarLoading();
  366. let days = e.currentTarget.dataset.id;
  367. if (days == 4) {
  368. this.setData({
  369. activeData: []
  370. })
  371. }
  372. this.setData({
  373. days,
  374. defaultHid: true,
  375. activityStatus: true,
  376. historyData: []
  377. })
  378. this.getHotActivity(1, 1, false, days, this.data.sort)
  379. },
  380. defaultScreen(e) {
  381. wx.showNavigationBarLoading();
  382. let sort = e.currentTarget.dataset.id;
  383. this.getHotActivity(1, 1, false, this.data.days, sort)
  384. this.setData({
  385. sort,
  386. defaultHid: true
  387. })
  388. },
  389. defaultShow() {
  390. this.setData({
  391. defaultHid: !this.data.defaultHid
  392. })
  393. },
  394. onShareAppMessage() {
  395. var inviteCode = '',
  396. channelInfo = util.config.channelInfo;
  397. inviteCode = app.globalData.userInfo ? app.globalData.userInfo.code : '';
  398. return {
  399. title: '挑战家族',
  400. path: '/pages/home/index?' +
  401. ('&invite=' + inviteCode) + ((channelInfo.channel != 0 && !util.isEmpty(channelInfo.channel) && channelInfo.channelTimes == 1) ? ('&channel=' + channelInfo.channel) : '') +
  402. ((channelInfo.channel != 0 && channelInfo.channelTimes == 1) ? ('&channelTimes=' + (parseInt(channelInfo.channelTimes) + 1)) : '')
  403. }
  404. },
  405. // 分享到朋友圈 不支持自定义
  406. onShareTimeline() {
  407. var inviteCode = '',
  408. channelInfo = util.config.channelInfo;
  409. inviteCode = app.globalData.userInfo ? app.globalData.userInfo.code : '';
  410. return {
  411. title: '挑战家族',
  412. path: '/pages/home/index?' +
  413. ('&invite=' + inviteCode) + ((channelInfo.channel != 0 && !util.isEmpty(channelInfo.channel) && channelInfo.channelTimes == 1) ? ('&channel=' + channelInfo.channel) : '') +
  414. ((channelInfo.channel != 0 && channelInfo.channelTimes == 1) ? ('&channelTimes=' + (parseInt(channelInfo.channelTimes) + 1)) : '')
  415. }
  416. },
  417. })