shopSearchResult.js 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. // pages/search-prod-show/search-prod-show.js
  2. var http = require('../../utils/http.js');
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. sts: 0,
  9. showType: 2,
  10. searchProdList: [],
  11. prodName: "",
  12. shopId: undefined,
  13. current: 1,
  14. pages: 1
  15. },
  16. changeShowType: function () {
  17. var showType = this.data.showType;
  18. if (showType == 1) {
  19. showType = 2;
  20. } else {
  21. showType = 1;
  22. }
  23. this.setData({
  24. showType: showType
  25. });
  26. },
  27. /**
  28. * 生命周期函数--监听页面加载
  29. */
  30. onLoad: function (options) {
  31. if (options.shopId) {
  32. this.setData({
  33. shopId: options.shopId
  34. })
  35. } else {
  36. this.setData({
  37. shopId: wx.getStorageSync("currShopId")
  38. })
  39. }
  40. this.setData({
  41. prodName: options.prodName
  42. });
  43. },
  44. /**
  45. * 生命周期函数--监听页面初次渲染完成
  46. */
  47. onReady: function () {
  48. },
  49. //输入商品获取数据
  50. getSearchContent: function (e) {
  51. this.setData({
  52. prodName: e.detail.value,
  53. });
  54. },
  55. /**
  56. * 生命周期函数--监听页面显示
  57. */
  58. onShow: function () {
  59. this.toLoadData();
  60. },
  61. //请求商品接口
  62. toLoadData: function () {
  63. var ths = this;
  64. //热门搜索
  65. var params = {
  66. url: "/search/searchProdPage",
  67. method: "GET",
  68. data: {
  69. current: this.data.current,
  70. prodName: this.data.prodName,
  71. size: 10,
  72. sort: this.data.sts,
  73. shopId: this.data.shopId,
  74. isAllProdType: true,
  75. },
  76. callBack: function (res) {
  77. ths.setData({
  78. searchProdList: res.current == 1 ? res.records : ths.data.searchProdList.concat(res.records),
  79. current: res.current,
  80. pages: res.pages
  81. });
  82. },
  83. };
  84. http.request(params);
  85. },
  86. //当前搜索页二次搜索商品
  87. toSearchConfirm: function () {
  88. this.setData({
  89. current: 1
  90. })
  91. this.toLoadData();
  92. },
  93. /**
  94. * 生命周期函数--监听页面隐藏
  95. */
  96. onHide: function () {
  97. },
  98. /**
  99. * 生命周期函数--监听页面卸载
  100. */
  101. onUnload: function () {
  102. },
  103. /**
  104. * 页面相关事件处理函数--监听用户下拉动作
  105. */
  106. onPullDownRefresh: function () {
  107. },
  108. /**
  109. * 页面上拉触底事件的处理函数
  110. */
  111. onReachBottom: function () {
  112. if (this.data.current < this.data.pages) {
  113. this.setData({
  114. current: this.data.current + 1
  115. })
  116. this.toLoadData()
  117. }
  118. },
  119. /**
  120. * 用户点击右上角分享
  121. */
  122. onShareAppMessage: function () {
  123. },
  124. /**
  125. * 状态点击事件
  126. */
  127. onStsTap: function (e) {
  128. var sts = e.currentTarget.dataset.sts;
  129. this.setData({
  130. sts: sts
  131. });
  132. this.toLoadData();
  133. },
  134. toProdPage: function (e) {
  135. var prodid = e.currentTarget.dataset.prodid;
  136. wx.navigateTo({
  137. url: '/pages/prod/prod?prodid=' + prodid,
  138. })
  139. },
  140. })