category.js 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. // pages/category/category.js
  2. var http = require("../../utils/http.js");
  3. var config = require("../../utils/config.js");
  4. Page({
  5. /**
  6. * 页面的初始数据
  7. */
  8. data: {
  9. selIndex: 0,
  10. categoryList:[],
  11. productList: [],
  12. categoryImg: '',
  13. prodid:''
  14. },
  15. /**
  16. * 生命周期函数--监听页面加载
  17. */
  18. onLoad: function (options) {
  19. var ths = this;
  20. //加载分类列表
  21. var params = {
  22. url: "/category/categoryInfo",
  23. method: "GET",
  24. data: {
  25. parentId: ''
  26. },
  27. callBack: function (res) {
  28. // console.log(res);
  29. ths.setData({
  30. categoryImg: res[0].pic,
  31. categoryList: res,
  32. });
  33. ths.getProdList(res[0].categoryId)
  34. }
  35. };
  36. http.request(params);
  37. },
  38. /**
  39. * 生命周期函数--监听页面初次渲染完成
  40. */
  41. onReady: function () {
  42. },
  43. /**
  44. * 生命周期函数--监听页面显示
  45. */
  46. onShow: function () {
  47. },
  48. /**
  49. * 生命周期函数--监听页面隐藏
  50. */
  51. onHide: function () {
  52. },
  53. /**
  54. * 生命周期函数--监听页面卸载
  55. */
  56. onUnload: function () {
  57. },
  58. /**
  59. * 页面相关事件处理函数--监听用户下拉动作
  60. */
  61. onPullDownRefresh: function () {
  62. },
  63. /**
  64. * 页面上拉触底事件的处理函数
  65. */
  66. onReachBottom: function () {
  67. },
  68. /**
  69. * 用户点击右上角分享
  70. */
  71. onShareAppMessage: function () {
  72. },
  73. /**
  74. * 分类点击事件
  75. */
  76. onMenuTab: function (e) {
  77. console.log(e);
  78. var id = e.currentTarget.dataset.id;
  79. var index = e.currentTarget.dataset.index;
  80. // this.getProdList(id);
  81. this.getProdList(this.data.categoryList[index].categoryId);
  82. this.setData({
  83. categoryImg: this.data.categoryList[index].pic,
  84. selIndex: index
  85. });
  86. },
  87. // 跳转搜索页
  88. toSearchPage: function () {
  89. wx.navigateTo({
  90. url: '/pages/search-page/search-page',
  91. })
  92. },
  93. getProdList(categoryId) {
  94. //加载分类列表
  95. var params = {
  96. url: "/prod/pageProd",
  97. method: "GET",
  98. data: {
  99. categoryId: categoryId
  100. },
  101. callBack: (res) => {
  102. // console.log(res);
  103. this.setData({
  104. productList: res.records,
  105. });
  106. }
  107. };
  108. http.request(params);
  109. },
  110. //跳转商品详情页
  111. toProdPage: function (e) {
  112. var prodid = e.currentTarget.dataset.prodid;
  113. wx.navigateTo({
  114. url: '/pages/prod/prod?prodid=' + prodid,
  115. })
  116. },
  117. })