prod-classify.js 6.4 KB

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