index.js 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. const app = getApp()
  2. var common = require('../../utils/common');
  3. Page({
  4. data: {
  5. loading:true,
  6. page: 0,
  7. index: 0,
  8. swiper_height:0,
  9. imgheights: [],
  10. adwords:[],
  11. notice: {id: 0,title:''},
  12. tabs:[],
  13. item: [],
  14. sale:[]
  15. },
  16. //页面创建时执行
  17. onLoad: function (options) {
  18. app.setUcode(options);
  19. this.getApi();
  20. this.getItem(0);
  21. },
  22. //页面出现在前台时执行
  23. onShow: function () {
  24. app.setTabBarCartNumber();
  25. },
  26. //获取首页接口
  27. getApi: function () {
  28. let that = this;
  29. //获取广告
  30. var param = {
  31. apis: JSON.stringify([2,3,4])
  32. }
  33. app.api().Get('api/v3/fastshop/adwords/all', param, function (result) {
  34. if (200 == result.code) {
  35. that.setData({
  36. adwords: result.data,
  37. });
  38. }
  39. })
  40. //获取公告
  41. app.api().Get('api/v3/fastshop/index/notice',{'signkey':'notice'},function (result) {
  42. if (200 == result.code) {
  43. that.setData({
  44. notice: result.data,
  45. });
  46. }
  47. })
  48. //获取导航
  49. app.api().Get('api/v3/fastshop/shop/tabs', function (result) {
  50. if (result.code == 200) {
  51. that.setData({
  52. catetab: result.data
  53. });
  54. }
  55. })
  56. //获取套装
  57. app.api().Get('api/v3/fastshop/sale/index', {'signkey':'index'}, function (result) {
  58. if (200 == result.code) {
  59. that.setData({
  60. sale: result.data,
  61. });
  62. setTimeout(() => {
  63. that.autoHeight();
  64. },1000)
  65. }
  66. })
  67. },
  68. /**
  69. * 点击Tab栏目切换
  70. */
  71. onClickTab: function (event) {
  72. let id = parseInt(event.detail.name);
  73. this.setData({
  74. index: id,
  75. loading: true,
  76. page: 0,
  77. item: [],
  78. });
  79. this.getItem(id);
  80. },
  81. /**
  82. * 活动指定分类商品(所有子类)
  83. */
  84. getItem: function (id) {
  85. let that = this;
  86. if (that.data.loading) {
  87. var parms = {
  88. cate_id: id,
  89. types: 1,
  90. page: that.data.page + 1
  91. }
  92. app.api().Get('api/v3/fastshop/shop/cateitem', parms, function (result) {
  93. if (result.code == 200) {
  94. var item = that.data.item;
  95. for (let i in result.data) {
  96. item.push(result.data[i]);
  97. }
  98. that.setData({
  99. item: item,
  100. page: parms.page,
  101. });
  102. }
  103. that.setData({
  104. loading: false,
  105. });
  106. })
  107. }
  108. },
  109. //图片高度
  110. imageLoad: function (event) {
  111. this.setData({
  112. imgheights: common.autoimg(event)
  113. })
  114. },
  115. //点击公告栏
  116. onNotice: function (event) {
  117. let id = event.currentTarget.dataset.id, config = app.globalData.wechat_config;
  118. wx.navigateTo({
  119. url: '/pages/helper/webview?src=' + app.api_root + '/api-' + config.app_id + '/v3/fastshop/webview/index/' + id
  120. })
  121. },
  122. //点击访问某个商品
  123. onItem: function (event) {
  124. wx.navigateTo({
  125. url: '../shop/item?id=' + event.currentTarget.dataset.id,
  126. })
  127. },
  128. /**
  129. * 分享按钮
  130. */
  131. onShareAppMessage: function () {
  132. return {
  133. path: '/pages/index/index?ucode=' + app.globalData.loginuser.ucode
  134. }
  135. },
  136. //推荐二维码
  137. qrcode: function () {
  138. wx.navigateTo({
  139. url: '../user/qrcode',
  140. })
  141. },
  142. //搜索
  143. onSearch: function (event) {
  144. wx.navigateTo({
  145. url: '../shop/search?keyword=',
  146. })
  147. },
  148. //判断活动的高度
  149. autoHeight() {
  150. wx.createSelectorQuery().select('.card').boundingClientRect().exec(rect => {
  151. if (!app.util().isNull(rect[0])) {
  152. this.setData({
  153. swiper_height: rect[0].height
  154. });
  155. }
  156. })
  157. },
  158. //滚动
  159. onPageScroll(res) {
  160. let scrollTop = res.scrollTop;
  161. if (scrollTop <= 10 && scrollTop <= 15) {
  162. this.autoHeight();
  163. }
  164. }
  165. })