index.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419
  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. // 不使用接口返回,展示默认
  74. // getInfo.data = res.data;
  75. getInfo.entryPage = 'homePage';
  76. getInfo.showPopup = true;
  77. that.safeTip = that.selectComponent('#safeTip');
  78. that.safeTip.getSafeTips(getInfo);
  79. }
  80. })
  81. this.setData({
  82. isShow: safeTips.show
  83. });
  84. },
  85. onLoad(options) {
  86. console.log(options)
  87. app.editTabbar();
  88. let that = this;
  89. // this.safetyTip();
  90. this.setData({
  91. imgPath: util.config.imgPath
  92. });
  93. if (!util.isEmpty(options.scene)) {
  94. // 调用渠道访问记录接口
  95. let channelParam = options.scene.replace("channel%3D", "").replace("channel=", ""),
  96. that = this;
  97. // wx.setStorageSync("channelCode",{channel:channelParam,channelTimes:1});
  98. util.config.channelInfo = {
  99. channel: channelParam,
  100. channelTimes: 1
  101. }
  102. util.getChannelMsg(channelParam).then((res) => {
  103. console.log('是否创建渠道记录', res)
  104. });
  105. }
  106. this.safetyTip();
  107. if (options.invite) {
  108. wx.setStorageSync("WX-invite", options.invite);
  109. }
  110. if (options.channel) {
  111. util.config.channelInfo = {
  112. channel: options.channel,
  113. channelTimes: 1
  114. }
  115. util.getChannelMsg(options.channel)
  116. }
  117. },
  118. info() {
  119. let that = this;
  120. util.ajax({
  121. func: "v2/categoryHomePageChallenge/info",
  122. data: {},
  123. load: false
  124. }, function (res) {
  125. if (res.code == 0) {
  126. that.setData({
  127. info: res.data
  128. });
  129. }
  130. });
  131. },
  132. comfun() {
  133. this.setData({
  134. region: app.globalData.city.city || '',
  135. activityStatus: true
  136. });
  137. this.info();
  138. this.getHotActivity(1, 0, false, this.data.days, this.data.sort);
  139. this.reportAnalytics(app.globalData.city.city); //上报定位城市
  140. },
  141. onShow() {
  142. let that = this;
  143. // util.promise().then(function (value) {
  144. that.comfun();
  145. var previous = app.globalData.previous; //选择前城市
  146. console.log(previous, 68686)
  147. var region = '永康';
  148. that.setData({
  149. region,
  150. activityStatus: true
  151. });
  152. if (previous && region && previous != region) {
  153. app.globalData.previous = region;
  154. that.info();
  155. that.getHotActivity(1, 0, false, this.data.days, this.data.sort);
  156. }
  157. // });
  158. },
  159. reportAnalytics(city) {
  160. wx.reportAnalytics('location', {
  161. city
  162. });
  163. },
  164. onReachBottom() {
  165. if (!this.data.bottom) {
  166. wx.showNavigationBarLoading();
  167. 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)
  168. }
  169. },
  170. onPageScroll(e) {
  171. var showBack = this.data.showBack;
  172. if (e.scrollTop > 800 && !showBack) {
  173. this.setData({
  174. showBack: true
  175. })
  176. } else if (e.scrollTop <= 800 && showBack) {
  177. this.setData({
  178. showBack: false
  179. })
  180. }
  181. // 筛选
  182. let screenHid = this.data.screenHid,
  183. that = this;
  184. var query = wx.createSelectorQuery();
  185. query.select('#screen').boundingClientRect();
  186. query.exec(function (res) {
  187. // if (screenHid && res && res[0].top <= 50) {
  188. // that.setData({
  189. // screenHid: false
  190. // })
  191. // } else if (!screenHid && res && res[0].top > 50) {
  192. // that.setData({
  193. // screenHid: true
  194. // })
  195. // }
  196. })
  197. },
  198. onPullDownRefresh() {
  199. let that = this;
  200. if (!util.isObjEmpty(app.globalData.city)) {
  201. wx.showNavigationBarLoading();
  202. // that.setData({ region: app.globalData.city.city });
  203. setTimeout(function () {
  204. that.info();
  205. that.getHotActivity(1, 2, true, that.data.days, that.data.sort);
  206. }, 1000);
  207. } else {
  208. wx.stopPullDownRefresh();
  209. }
  210. },
  211. // 获取当前活动
  212. getHotActivity(pageIndex, status, PullDown, days, sort) {
  213. let that = this;
  214. if (days != 4 && this.data.activityStatus) {
  215. util.ajax({
  216. func: "v2/article/recom_list",
  217. data: {
  218. "pageIndex": pageIndex,
  219. "pageSize": 10,
  220. 'type': days || 0,
  221. 'sort': sort || 0
  222. },
  223. load: false
  224. }, function (res) {
  225. console.log(res);
  226. if (res.code == 0) {
  227. res.data.list.map(el => {
  228. if (!util.isEmpty(el.discount)) {
  229. let arr = [];
  230. if (el.discount.indexOf('+') == -1) {
  231. arr.push(el.discount);
  232. } else {
  233. arr = el.discount.split('+');
  234. }
  235. el.discount = arr;
  236. }
  237. });
  238. let datas = res.data.list,
  239. activeData = that.data.activeData,
  240. bottom = false,
  241. imgPath = that.data.imgPath;
  242. if (datas.length < 10) {
  243. // bottom = true;
  244. that.data.activityStatus = false;
  245. that.getHistoryActive(1, days, status)
  246. }
  247. activeData = pageIndex == 1 ? datas : [...activeData, ...datas];
  248. that.setData({
  249. activeData,
  250. pageIndex,
  251. bottom,
  252. days,
  253. sort,
  254. activityStatus: that.data.activityStatus
  255. })
  256. wx.hideNavigationBarLoading()
  257. } else {
  258. util.showTips(res.reason);
  259. }
  260. // if (status == '0') {//onshow
  261. // } else if (status == '1') {//onReachBottom
  262. // wx.hideNavigationBarLoading();
  263. // } else if (status == '2') {//onPullDownRefresh
  264. // wx.stopPullDownRefresh();
  265. // wx.hideNavigationBarLoading();
  266. // }
  267. });
  268. } else {
  269. this.getHistoryActive(pageIndex, days, status)
  270. }
  271. },
  272. // 获取往期活动
  273. getHistoryActive(pageIndex, days, status) {
  274. let that = this;
  275. util.ajax({
  276. func: "v2/article/history_list",
  277. data: {
  278. "pageIndex": pageIndex,
  279. "pageSize": 10
  280. },
  281. load: false
  282. }, function (res) {
  283. if (res.code == 0) {
  284. res.data.list.map(el => {
  285. if (!util.isEmpty(el.discount)) {
  286. let arr = [];
  287. if (el.discount.indexOf('+') == -1) {
  288. arr.push(el.discount);
  289. } else {
  290. arr = el.discount.split('+');
  291. }
  292. el.discount = arr;
  293. }
  294. });
  295. let datas = res.data.list,
  296. historyData = that.data.historyData,
  297. bottom = false,
  298. imgPath = that.data.imgPath;
  299. if (datas.length < 10) bottom = true;
  300. historyData = pageIndex == 1 ? datas : [...historyData, ...datas];
  301. that.setData({
  302. historyData,
  303. HistorypageIndex: pageIndex,
  304. bottom,
  305. days
  306. })
  307. } else {
  308. util.showTips(res.reason);
  309. }
  310. if (status == '0') { //onshow
  311. } else if (status == '1') { //onReachBottom
  312. wx.hideNavigationBarLoading();
  313. } else if (status == '2') { //onPullDownRefresh
  314. wx.stopPullDownRefresh();
  315. wx.hideNavigationBarLoading();
  316. }
  317. });
  318. },
  319. navigator(e) {
  320. util.navigator(e.currentTarget.dataset.url);
  321. },
  322. navigatorCols(e) {
  323. let data = e.currentTarget.dataset,
  324. info = this.data.info[data.type][data.index],
  325. url = '';
  326. console.log(data, info)
  327. if (data.type == 'cyclePositions') {
  328. wx.reportAnalytics('swipe', {
  329. aid: data.id,
  330. title: data.title,
  331. });
  332. }
  333. // 类目类型 0 公众号推文 1 活动视频 2 指定活动合集
  334. let canJump = true;
  335. switch (info.categoryType) {
  336. case 2:
  337. url = '/pages/public/swiper/list?id=' + info.id + '&title=' + info.title;
  338. break;
  339. case 1:
  340. url = '/pages/public/video/video';
  341. break;
  342. case 0:
  343. url = '/pages/public/swiper/web?url=' + encodeURIComponent(info.url) + '&title=' + encodeURIComponent(info.title)
  344. break;
  345. }
  346. console.log(url)
  347. if (canJump) {
  348. wx.navigateTo({
  349. url: url
  350. });
  351. }
  352. },
  353. navigatorLive() {
  354. wx.navigateTo({
  355. url: '/pages/public/live/list'
  356. });
  357. },
  358. toTop() {
  359. wx.pageScrollTo({
  360. scrollTop: 0,
  361. duration: 500
  362. })
  363. },
  364. // 选择活动类型
  365. chooseScreen(e) {
  366. wx.showNavigationBarLoading();
  367. let days = e.currentTarget.dataset.id;
  368. if (days == 4) {
  369. this.setData({
  370. activeData: []
  371. })
  372. }
  373. this.setData({
  374. days,
  375. defaultHid: true,
  376. activityStatus: true,
  377. historyData: []
  378. })
  379. this.getHotActivity(1, 1, false, days, this.data.sort)
  380. },
  381. defaultScreen(e) {
  382. wx.showNavigationBarLoading();
  383. let sort = e.currentTarget.dataset.id;
  384. this.getHotActivity(1, 1, false, this.data.days, sort)
  385. this.setData({
  386. sort,
  387. defaultHid: true
  388. })
  389. },
  390. defaultShow() {
  391. this.setData({
  392. defaultHid: !this.data.defaultHid
  393. })
  394. },
  395. onShareAppMessage() {
  396. var inviteCode = '',
  397. channelInfo = util.config.channelInfo;
  398. inviteCode = app.globalData.userInfo ? app.globalData.userInfo.code : '';
  399. return {
  400. title: '挑战家族',
  401. path: '/pages/home/index?' +
  402. ('&invite=' + inviteCode) + ((channelInfo.channel != 0 && !util.isEmpty(channelInfo.channel) && channelInfo.channelTimes == 1) ? ('&channel=' + channelInfo.channel) : '') +
  403. ((channelInfo.channel != 0 && channelInfo.channelTimes == 1) ? ('&channelTimes=' + (parseInt(channelInfo.channelTimes) + 1)) : '')
  404. }
  405. },
  406. // 分享到朋友圈 不支持自定义
  407. onShareTimeline() {
  408. var inviteCode = '',
  409. channelInfo = util.config.channelInfo;
  410. inviteCode = app.globalData.userInfo ? app.globalData.userInfo.code : '';
  411. return {
  412. title: '挑战家族',
  413. path: '/pages/home/index?' +
  414. ('&invite=' + inviteCode) + ((channelInfo.channel != 0 && !util.isEmpty(channelInfo.channel) && channelInfo.channelTimes == 1) ? ('&channel=' + channelInfo.channel) : '') +
  415. ((channelInfo.channel != 0 && channelInfo.channelTimes == 1) ? ('&channelTimes=' + (parseInt(channelInfo.channelTimes) + 1)) : '')
  416. }
  417. },
  418. })