index.js 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  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. console.log(e)
  79. let item = e.currentTarget.dataset.items
  80. if (item.activity && item.activity.type === "1") {
  81. wx.navigateTo({
  82. url: `/pages/activity/goods_seckill_details/index?id=' ${item.activity.id} + '&time=' + ${item.activity.time} + '&status=1'`
  83. });
  84. } else if (item.activity && item.activity.type === "2") {
  85. wx.navigateTo({ url: `/pages/activity/goods_bargain_details/index?id=${item.activity.id}`});
  86. } else if (item.activity && item.activity.type === "3") {
  87. wx.navigateTo({
  88. url: `/pages/activity/goods_combination_details/index?id=${item.id}`
  89. });
  90. } else {
  91. wx.navigateTo({ url: "/detail/" + item.id });
  92. }
  93. },
  94. getTemlIds(){
  95. let messageTmplIds = wx.getStorageSync(CACHE_SUBSCRIBE_MESSAGE);
  96. if (!messageTmplIds){
  97. getTemlIds().then(res=>{
  98. if (res.data)
  99. wx.setStorageSync(CACHE_SUBSCRIBE_MESSAGE, JSON.stringify(res.data));
  100. })
  101. }
  102. },
  103. catchTouchMove: function (res) {
  104. return false
  105. },
  106. onColse:function(){
  107. this.setData({ window: false});
  108. },
  109. /**
  110. * 生命周期函数--监听页面初次渲染完成
  111. */
  112. onReady: function () {
  113. },
  114. /**
  115. * 生命周期函数--监听页面显示
  116. */
  117. onShow: function () {
  118. this.getIndexConfig();
  119. if(app.globalData.isLog && app.globalData.token) this.get_issue_coupon_list();
  120. },
  121. get_issue_coupon_list:function(){
  122. var that = this;
  123. getCoupons({page:1,limit:3}).then(res=>{
  124. that.setData({ couponList: res.data });
  125. if (!res.data.length) that.setData({ window: false });
  126. });
  127. },
  128. getIndexConfig:function(){
  129. var that = this;
  130. getIndexData().then(res=>{
  131. that.setData({
  132. imgUrls: res.data.banner,
  133. menus: res.data.menus,
  134. itemNew: res.data.roll,
  135. activityList: res.data.activity,
  136. bastBanner: res.data.info.bastBanner,
  137. bastInfo: res.data.info.bastInfo,
  138. bastList: res.data.info.bastList,
  139. fastInfo: res.data.info.fastInfo,
  140. fastList: res.data.info.fastList,
  141. firstInfo: res.data.info.firstInfo,
  142. firstList: res.data.info.firstList,
  143. salesInfo: res.data.info.salesInfo,
  144. likeInfo: res.data.likeInfo,
  145. lovelyBanner: res.data.lovely.length ? res.data.lovely[0] : {},
  146. benefit: res.data.benefit,
  147. logoUrl: res.data.logoUrl,
  148. couponList: res.data.couponList,
  149. newGoodsBananr: res.data.newGoodsBananr
  150. });
  151. wx.getSetting({
  152. success(res) {
  153. if (!res.authSetting['scope.userInfo']) {
  154. that.setData({ window: that.data.couponList.length ? true : false });
  155. } else {
  156. that.setData({ window: false, iShidden: true});
  157. }
  158. }
  159. });
  160. })
  161. },
  162. /**
  163. * 生命周期函数--监听页面隐藏
  164. */
  165. onHide: function () {
  166. this.setData({ window:false});
  167. },
  168. /**
  169. * 生命周期函数--监听页面卸载
  170. */
  171. onUnload: function () {
  172. },
  173. /**
  174. * 页面相关事件处理函数--监听用户下拉动作
  175. */
  176. onPullDownRefresh: function () {
  177. this.getIndexConfig();
  178. if (app.globalData.isLog && app.globalData.token) this.get_issue_coupon_list();
  179. wx.stopPullDownRefresh();
  180. },
  181. /**
  182. * 页面上拉触底事件的处理函数
  183. */
  184. onReachBottom: function () {
  185. },
  186. /**
  187. * 用户点击右上角分享
  188. */
  189. onShareAppMessage: function () {
  190. }
  191. })