shopPage.js 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  1. // pages/shopPage/shopPage.js
  2. var http = require('../../utils/http.js')
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. shopId: 0,
  9. shopInfo: {},
  10. indicatorDots: true,
  11. indicatorColor: '#d1e5fb',
  12. indicatorActiveColor: '#1b7dec',
  13. autoplay: true,
  14. interval: 2000,
  15. duration: 1000,
  16. indexImgs: [],
  17. topFlag: false,
  18. isCollection: false,
  19. shopProdList: [],
  20. },
  21. //加载轮播图
  22. getIndexImgs() {
  23. var shopId = this.data.shopId
  24. //加载轮播图
  25. var params = {
  26. url: `/indexImgs/${shopId}`,
  27. method: "GET",
  28. data: {},
  29. callBack: (res) => {
  30. this.setData({
  31. indexImgs: res,
  32. // seq: res
  33. });
  34. wx.hideLoading();
  35. }
  36. };
  37. http.request(params);
  38. },
  39. // 跳转店铺详情页
  40. toShopInfo(e) {
  41. const shopId = e.currentTarget.dataset.shopid
  42. wx.navigateTo({
  43. url: '/pages/shopInfo/shopInfo?shopId=' + shopId,
  44. })
  45. },
  46. // 跳转店内搜索页
  47. toShopSearchPage: function(e) {
  48. wx.navigateTo({
  49. url: '/pages/shopSearch/shopSearch?shopId=' + e.currentTarget.dataset.shopid,
  50. })
  51. },
  52. // 跳转所有商品页
  53. toShopProds(e) {
  54. wx.navigateTo({
  55. url: '/pages/shopProds/shopProds?shopId=' + e.currentTarget.dataset.shopid,
  56. })
  57. },
  58. // 收藏/取消收藏
  59. addOrCannelCollection() {
  60. this.setData({
  61. isCollection: !this.data.isCollection
  62. })
  63. },
  64. // 跳转商品详情页
  65. toProdPage: function(e) {
  66. var prodid = e.currentTarget.dataset.prodid;
  67. if (prodid) {
  68. wx.navigateTo({
  69. url: '/pages/prod/prod?prodid=' + prodid,
  70. })
  71. }
  72. },
  73. // 获取店铺信息
  74. getShopInfo: function() {
  75. var ths = this;
  76. //热门搜索
  77. var params = {
  78. url: "/shop/headInfo",
  79. method: "GET",
  80. data: {
  81. shopId: ths.data.shopId
  82. },
  83. callBack: function(res) {
  84. wx.hideLoading()
  85. ths.setData({
  86. shopInfo: res,
  87. })
  88. wx.setStorageSync("shopInfo", res)
  89. ths.setNavTitle()
  90. ths.getIndexImgs()
  91. ths.getShopProds()
  92. },
  93. };
  94. http.request(params);
  95. },
  96. // 获取店铺商品
  97. getShopProds() {
  98. var params = {
  99. url: '/search/searchProdPage',
  100. method: 'GET',
  101. data: {
  102. shopId: this.data.shopId,
  103. platform:1,
  104. channelId:wx.getStorageSync('channelId'),
  105. isAllProdType: true
  106. },
  107. callBack: (res) => {
  108. wx.hideLoading()
  109. this.setData({
  110. shopProdList: res.records
  111. })
  112. }
  113. }
  114. http.request(params)
  115. },
  116. // 设置页面标题
  117. setNavTitle() {
  118. wx.setNavigationBarTitle({
  119. title: this.data.shopInfo.shopName
  120. })
  121. },
  122. /**
  123. * 生命周期函数--监听页面加载
  124. */
  125. onLoad: function(options) {
  126. wx.showLoading({
  127. title: '',
  128. mask: true,
  129. })
  130. if (options.shopId) {
  131. this.setData({
  132. shopId: options.shopId
  133. })
  134. wx.setStorageSync("currShopId", options.shopId);
  135. } else {
  136. this.setData({
  137. shopId: wx.getStorageSync("currShopId")
  138. })
  139. }
  140. this.getShopInfo()
  141. },
  142. /**
  143. * 跳转店铺详情
  144. */
  145. toShopInfo() {
  146. wx.navigateTo({
  147. url: '/pages/shopInfo/shopInfo?shopId=' + this.data.shopId,
  148. })
  149. },
  150. /**
  151. * 生命周期函数--监听页面初次渲染完成
  152. */
  153. onReady: function() {
  154. },
  155. /**
  156. * 生命周期函数--监听页面显示
  157. */
  158. onShow: function() {
  159. },
  160. /**
  161. * 生命周期函数--监听页面隐藏
  162. */
  163. onHide: function() {
  164. },
  165. /**
  166. * 生命周期函数--监听页面卸载
  167. */
  168. onUnload: function() {
  169. },
  170. /**
  171. * 页面相关事件处理函数--监听用户下拉动作
  172. */
  173. onPullDownRefresh: function() {
  174. },
  175. /**
  176. * 页面上拉触底事件的处理函数
  177. */
  178. onReachBottom: function() {
  179. },
  180. /**
  181. * 用户点击右上角分享
  182. */
  183. onShareAppMessage: function() {
  184. },
  185. // 页面滚动事件
  186. onPageScroll: function(e) {
  187. var _this = this
  188. if (e.scrollTop > 80) {
  189. _this.setData({
  190. topFlag: true
  191. })
  192. } else {
  193. _this.setData({
  194. topFlag: false
  195. })
  196. }
  197. }
  198. })