prod-classify.vue 6.4 KB

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