index.js 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. const app = getApp();
  2. import { getIndexData, getCoupons, getTemlIds, getLiveList} from '../../api/api.js';
  3. import { CACHE_SUBSCRIBE_MESSAGE } from '../../config.js';
  4. import Util from '../../utils/util.js';
  5. import wxh from '../../utils/wxh.js';
  6. Page({
  7. /**
  8. * 页面的初始数据
  9. */
  10. data: {
  11. imgUrls: [],
  12. itemNew:[],
  13. activityList:[],
  14. menus: [],
  15. bastBanner: [],
  16. bastInfo: '',
  17. bastList: [],
  18. fastInfo: '',
  19. fastList: [],
  20. firstInfo: '',
  21. firstList: [],
  22. salesInfo: '',
  23. likeInfo: [],
  24. lovelyBanner: {},
  25. benefit:[],
  26. indicatorDots: false,
  27. circular: true,
  28. autoplay: true,
  29. interval: 3000,
  30. duration: 500,
  31. parameter:{
  32. 'navbar':'0',
  33. 'return':'0'
  34. },
  35. window: false,
  36. iShidden:false,
  37. navH: "",
  38. newGoodsBananr:'',
  39. selfLongitude: '',
  40. selfLatitude: '',
  41. liveList: [],
  42. liveInfo:{},
  43. },
  44. closeTip:function(){
  45. wx.setStorageSync('msg_key',true);
  46. this.setData({
  47. iShidden:true
  48. })
  49. },
  50. /**
  51. * 生命周期函数--监听页面加载
  52. */
  53. onLoad: function (options) {
  54. wxh.selfLocation(1);
  55. this.setData({
  56. navH: app.globalData.navHeight
  57. });
  58. if (options.spid) app.globalData.spid = options.spid;
  59. if (options.scene) app.globalData.code = decodeURIComponent(options.scene);
  60. if (wx.getStorageSync('msg_key')) this.setData({ iShidden:true});
  61. this.getTemlIds();
  62. this.getLiveList();
  63. },
  64. getLiveList:function(){
  65. getLiveList(1,20).then(res=>{
  66. if(res.data.length == 1){
  67. this.setData({liveInfo:res.data[0]});
  68. }else{
  69. this.setData({liveList:res.data});
  70. }
  71. }).catch(res=>{
  72. })
  73. },
  74. /**
  75. * 商品详情跳转
  76. */
  77. goDetail: function (e) {
  78. let item = e.currentTarget.dataset.items
  79. if (item.activity && item.activity.type === "1") {
  80. wx.navigateTo({
  81. url: `/pages/activity/goods_seckill_details/index?id=${item.activity.id}&time=${item.activity.time}&status=1`
  82. });
  83. } else if (item.activity && item.activity.type === "2") {
  84. wx.navigateTo({ url: `/pages/activity/goods_bargain_details/index?id=${item.activity.id}` });
  85. } else if (item.activity && item.activity.type === "3") {
  86. wx.navigateTo({
  87. url: `/pages/activity/goods_combination_details/index?id=${item.activity.id}`
  88. });
  89. } else {
  90. wx.navigateTo({ url: `/pages/goods_details/index?id=${item.id}` });
  91. }
  92. },
  93. getTemlIds(){
  94. let messageTmplIds = wx.getStorageSync(CACHE_SUBSCRIBE_MESSAGE);
  95. if (!messageTmplIds){
  96. getTemlIds().then(res=>{
  97. if (res.data)
  98. wx.setStorageSync(CACHE_SUBSCRIBE_MESSAGE, JSON.stringify(res.data));
  99. })
  100. }
  101. },
  102. catchTouchMove: function (res) {
  103. return false
  104. },
  105. onColse:function(){
  106. this.setData({ window: false});
  107. },
  108. /**
  109. * 生命周期函数--监听页面初次渲染完成
  110. */
  111. onReady: function () {
  112. },
  113. /**
  114. * 生命周期函数--监听页面显示
  115. */
  116. onShow: function () {
  117. this.getIndexConfig();
  118. if(app.globalData.isLog && app.globalData.token) this.get_issue_coupon_list();
  119. },
  120. get_issue_coupon_list:function(){
  121. var that = this;
  122. getCoupons({page:1,limit:3}).then(res=>{
  123. that.setData({ couponList: res.data });
  124. if (!res.data.length) that.setData({ window: false });
  125. });
  126. },
  127. getIndexConfig:function(){
  128. var that = this;
  129. getIndexData().then(res=>{
  130. that.setData({
  131. imgUrls: res.data.banner,
  132. menus: res.data.menus,
  133. itemNew: res.data.roll,
  134. activityList: res.data.activity,
  135. bastBanner: res.data.info.bastBanner,
  136. bastInfo: res.data.info.bastInfo,
  137. bastList: res.data.info.bastList,
  138. fastInfo: res.data.info.fastInfo,
  139. fastList: res.data.info.fastList,
  140. firstInfo: res.data.info.firstInfo,
  141. firstList: res.data.info.firstList,
  142. salesInfo: res.data.info.salesInfo,
  143. likeInfo: res.data.likeInfo,
  144. lovelyBanner: res.data.lovely.length ? res.data.lovely[0] : {},
  145. benefit: res.data.benefit,
  146. logoUrl: res.data.logoUrl,
  147. couponList: res.data.couponList,
  148. newGoodsBananr: res.data.newGoodsBananr
  149. });
  150. wx.getSetting({
  151. success(res) {
  152. if (!res.authSetting['scope.userInfo']) {
  153. that.setData({ window: that.data.couponList.length ? true : false });
  154. } else {
  155. that.setData({ window: false, iShidden: true});
  156. }
  157. }
  158. });
  159. })
  160. },
  161. /**
  162. * 生命周期函数--监听页面隐藏
  163. */
  164. onHide: function () {
  165. this.setData({ window:false});
  166. },
  167. /**
  168. * 生命周期函数--监听页面卸载
  169. */
  170. onUnload: function () {
  171. },
  172. /**
  173. * 页面相关事件处理函数--监听用户下拉动作
  174. */
  175. onPullDownRefresh: function () {
  176. this.getIndexConfig();
  177. if (app.globalData.isLog && app.globalData.token) this.get_issue_coupon_list();
  178. wx.stopPullDownRefresh();
  179. },
  180. /**
  181. * 页面上拉触底事件的处理函数
  182. */
  183. onReachBottom: function () {
  184. },
  185. /**
  186. * 用户点击右上角分享
  187. */
  188. onShareAppMessage: function () {
  189. }
  190. })