index.js 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. // pages/welfareMall/index/index.js
  2. import WelfareMall from '../../../api/welfareMall';
  3. const util = require('../../../utils/util.js');
  4. import {getColor} from '../../../utils/user'
  5. const app = getApp();
  6. Page({
  7. /**
  8. * 页面的初始数据
  9. */
  10. data: {
  11. activityList:[],
  12. bannerList:[],
  13. navigationList:[],
  14. adList:[],
  15. autoplay: true,
  16. interval: 5000,
  17. duration: 500,
  18. currentSwiper:0,
  19. // indicatorDots:true,
  20. grayTheme:false,
  21. config: {},
  22. },
  23. /**
  24. * 生命周期函数--监听页面加载
  25. */
  26. onLoad: function (options) {
  27. },
  28. /**
  29. * 生命周期函数--监听页面初次渲染完成
  30. */
  31. onReady: function () {
  32. },
  33. /**
  34. * 生命周期函数--监听页面显示
  35. */
  36. onShow: function () {
  37. this.getIndexList()
  38. },
  39. /**
  40. * 生命周期函数--监听页面隐藏
  41. */
  42. onHide: function () {
  43. },
  44. /**
  45. * 生命周期函数--监听页面卸载
  46. */
  47. onUnload: function () {
  48. },
  49. /**
  50. * 页面相关事件处理函数--监听用户下拉动作
  51. */
  52. onPullDownRefresh: function () {
  53. },
  54. /**
  55. * 页面上拉触底事件的处理函数
  56. */
  57. onReachBottom: function () {
  58. },
  59. /**
  60. * 用户点击右上角分享
  61. */
  62. onShareAppMessage: function () {
  63. return {
  64. title: "沪上阿姨福利GO",
  65. path: "/pages/welfareMall/index/index",
  66. imageUrl: this.data.bannerList[0]?.figure
  67. }
  68. },
  69. swiperChange: function(e) {
  70. // console.log(e.detail.source)
  71. if (e.detail.source == 'autoplay' || e.detail.source == 'touch') {
  72. this.setData({
  73. currentSwiper: e.detail.current
  74. })
  75. }
  76. },
  77. //跳转超值券包
  78. goToCouponBag:function () {
  79. wx.navigateTo({
  80. url: "/pages/welfareMall/activityList/activityList",
  81. })
  82. },
  83. goToCoupon:function(e){
  84. var appId = e.currentTarget.dataset.appid;
  85. var path = e.currentTarget.dataset.path;
  86. if(appId && path){
  87. wx.navigateToMiniProgram({
  88. appId: appId,
  89. path: path,
  90. success(res) {
  91. // 打开成功
  92. }
  93. })
  94. }
  95. if(!appId && path){
  96. wx.navigateTo({
  97. url: path,
  98. })
  99. }
  100. },
  101. goCouponDetail:function(e){
  102. let activityId = e.currentTarget.dataset.id
  103. wx.navigateTo({
  104. url: '/pages/welfareMall/activityInfo/activityInfo?activityId='+ activityId,
  105. })
  106. },
  107. async getIndexList(){
  108. let res = await WelfareMall.getIndexList();
  109. this.setData({
  110. activityList:res.data.activityList,
  111. bannerList:res.data.bannerList,
  112. navigationList:res.data.navigationList,
  113. adList:res.data.adList,
  114. grayTheme:res.data.config.grayTheme,
  115. // config:res.data.config
  116. })
  117. let info = await getColor();
  118. this.setData({
  119. config:info
  120. })
  121. this.setThrem(res.data.config.grayTheme)
  122. },
  123. //设置滤镜
  124. setThrem(grayTheme){
  125. app.globalData.grayTheme = grayTheme;
  126. let index0 = "images/welfareMall/home-active.png"
  127. let index1 = "images/welfareMall/user-active.png"
  128. if(grayTheme){
  129. index0 = "images/welfareMall/home_black.png"
  130. index1 = "images/welfareMall/user_black.png"
  131. }
  132. wx.setTabBarItem({
  133. index: 0,
  134. selectedIconPath: index0
  135. })
  136. wx.setTabBarItem({
  137. index: 1,
  138. selectedIconPath: index1
  139. })
  140. },
  141. goToBanner(e){
  142. var appId = e.currentTarget.dataset.appid;
  143. var path = e.currentTarget.dataset.path;
  144. if(appId && path){
  145. wx.navigateToMiniProgram({
  146. appId: appId,
  147. path: path,
  148. success(res) {
  149. // 打开成功
  150. }
  151. })
  152. }
  153. if(!appId && path){
  154. wx.navigateTo({
  155. url: path,
  156. })
  157. }
  158. },
  159. goToAd(e){
  160. var appId = e.currentTarget.dataset.appid;
  161. var path = e.currentTarget.dataset.path;
  162. if(appId && path){
  163. wx.navigateToMiniProgram({
  164. appId: appId,
  165. path: path,
  166. success(res) {
  167. // 打开成功
  168. }
  169. })
  170. }
  171. if(!appId && path){
  172. wx.navigateTo({
  173. url: path,
  174. })
  175. }
  176. }
  177. })