prod-classify.js 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281
  1. // pages/prod-classify/prod-classify.js
  2. var http = require('../../utils/http.js');
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. sts: 0,
  9. prodList: [],
  10. title: "",
  11. current: 1,
  12. size: 10,
  13. pages: 0,
  14. tagid: 0
  15. },
  16. /**
  17. * 生命周期函数--监听页面加载
  18. */
  19. onLoad: function(options) {
  20. this.setData({
  21. current: 1,
  22. pages: 0,
  23. sts: options.sts,
  24. title: options.title ? options.title : ""
  25. });
  26. if (options.tagid) {
  27. this.setData({
  28. tagid: options.tagid
  29. });
  30. }
  31. if (this.data.sts == 0) {
  32. if (options.tagid == 1) {
  33. wx.setNavigationBarTitle({
  34. title: '每日上新'
  35. })
  36. } else if (options.tagid == 2) {
  37. wx.setNavigationBarTitle({
  38. title: '商城热卖'
  39. })
  40. } else if (options.tagid == 3) {
  41. wx.setNavigationBarTitle({
  42. title: '更多宝贝'
  43. })
  44. }
  45. } else if (this.data.sts == 1) {
  46. wx.setNavigationBarTitle({
  47. title: '新品推荐',
  48. })
  49. } else if (this.data.sts == 2) {
  50. wx.setNavigationBarTitle({
  51. title: '限时特惠',
  52. })
  53. } else if (this.data.sts == 3) {
  54. wx.setNavigationBarTitle({
  55. title: '每日疯抢',
  56. })
  57. } else if (this.data.sts == 4) {
  58. wx.setNavigationBarTitle({
  59. title: '优惠券活动商品',
  60. })
  61. } else if (this.data.sts == 5) {
  62. wx.setNavigationBarTitle({
  63. title: '我的收藏商品',
  64. })
  65. } else {
  66. wx.setNavigationBarTitle({
  67. title: this.data.title
  68. })
  69. }
  70. this.loadProdData(options);
  71. },
  72. /**
  73. * 加载商品数据
  74. */
  75. loadProdData: function(options) {
  76. let sts = this.data.sts
  77. if (sts == 0) {
  78. // 分组标签商品列表
  79. this.getTagProd();
  80. } else if (sts == 1) {
  81. // 新品推荐
  82. let url = "/prod/lastedProdPage"
  83. this.getActProd(url)
  84. } else if (sts == 2) {
  85. // 限时特惠
  86. let url = "/prod/discountProdList"
  87. this.getActProd(url)
  88. } else if (sts == 3) {
  89. // 每日疯抢
  90. let url = "/prod/moreBuyProdList"
  91. this.getActProd(url)
  92. } else if (sts == 4) {
  93. // 优惠券商品列表
  94. this.getProdByCouponId(options.tagid)
  95. } else if (sts == 5) {
  96. // 收藏商品列表
  97. this.getCollectionProd()
  98. }
  99. },
  100. getActProd: function(url) {
  101. var ths = this;
  102. wx.showLoading();
  103. var params = {
  104. url: url,
  105. method: "GET",
  106. data: {
  107. current: ths.data.current,
  108. size: ths.data.size,
  109. },
  110. callBack: function(res) {
  111. let list = []
  112. if (res.current == 1) {
  113. list = res.records
  114. } else {
  115. list = ths.data.prodList
  116. list = list.concat(res.records)
  117. }
  118. ths.setData({
  119. prodList: list,
  120. pages: res.pages
  121. });
  122. wx.hideLoading();
  123. }
  124. };
  125. http.request(params);
  126. },
  127. /**
  128. * 获取我的收藏商品
  129. */
  130. getCollectionProd: function() {
  131. var ths = this;
  132. wx.showLoading();
  133. var params = {
  134. url: "/p/user/collection/prods",
  135. method: "GET",
  136. data: {
  137. current: ths.data.current,
  138. size: ths.data.size,
  139. },
  140. callBack: function(res) {
  141. let list = []
  142. if (res.current == 1) {
  143. list = res.records
  144. } else {
  145. list = ths.data.prodList
  146. list = list.concat(res.records)
  147. }
  148. ths.setData({
  149. prodList: list,
  150. pages: res.pages
  151. });
  152. wx.hideLoading();
  153. }
  154. };
  155. http.request(params);
  156. },
  157. /**
  158. * 获取标签列表
  159. */
  160. getTagProd: function(id) {
  161. var ths = this;
  162. wx.showLoading();
  163. var param = {
  164. url: "/prod/prodListByTagId",
  165. method: "GET",
  166. data: {
  167. tagId: ths.data.tagid,
  168. current: ths.data.current,
  169. size: ths.data.size
  170. },
  171. callBack: (res) => {
  172. let list = []
  173. if (res.current == 1) {
  174. list = res.records
  175. } else {
  176. list = ths.data.prodList.concat(res.records)
  177. }
  178. ths.setData({
  179. prodList: list,
  180. pages: res.pages
  181. });
  182. wx.hideLoading();
  183. }
  184. };
  185. http.request(param);
  186. },
  187. /**
  188. * 获取优惠券商品列表
  189. */
  190. getProdByCouponId(id) {
  191. var ths = this;
  192. wx.showLoading();
  193. var param = {
  194. url: "/coupon/prodListByCouponId",
  195. method: "GET",
  196. data: {
  197. couponId: id,
  198. current: this.data.current,
  199. size: this.data.size
  200. },
  201. callBack: (res) => {
  202. let list = []
  203. if (res.current == 1) {
  204. list = res.records
  205. } else {
  206. list = ths.data.prodList.concat(res.records)
  207. }
  208. ths.setData({
  209. prodList: list,
  210. pages: res.pages
  211. });
  212. wx.hideLoading();
  213. }
  214. };
  215. http.request(param);
  216. },
  217. /**
  218. * 生命周期函数--监听页面初次渲染完成
  219. */
  220. onReady: function() {
  221. },
  222. /**
  223. * 生命周期函数--监听页面显示
  224. */
  225. onShow: function() {
  226. },
  227. /**
  228. * 生命周期函数--监听页面隐藏
  229. */
  230. onHide: function() {
  231. },
  232. /**
  233. * 生命周期函数--监听页面卸载
  234. */
  235. onUnload: function() {
  236. },
  237. /**
  238. * 页面相关事件处理函数--监听用户下拉动作
  239. */
  240. onPullDownRefresh: function() {
  241. },
  242. /**
  243. * 页面上拉触底事件的处理函数
  244. */
  245. onReachBottom: function() {
  246. if (this.data.current < this.data.pages) {
  247. this.setData({
  248. current: this.data.current + 1
  249. })
  250. this.loadProdData()
  251. }
  252. },
  253. /**
  254. * 用户点击右上角分享
  255. */
  256. onShareAppMessage: function() {
  257. }
  258. })