shopSearchResult.js 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  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. platform:1
  76. },
  77. callBack: function (res) {
  78. ths.setData({
  79. searchProdList: res.current == 1 ? res.records : ths.data.searchProdList.concat(res.records),
  80. current: res.current,
  81. pages: res.pages
  82. });
  83. },
  84. };
  85. http.request(params);
  86. },
  87. //当前搜索页二次搜索商品
  88. toSearchConfirm: function () {
  89. this.setData({
  90. current: 1
  91. })
  92. this.toLoadData();
  93. },
  94. /**
  95. * 生命周期函数--监听页面隐藏
  96. */
  97. onHide: function () {
  98. },
  99. /**
  100. * 生命周期函数--监听页面卸载
  101. */
  102. onUnload: function () {
  103. },
  104. /**
  105. * 页面相关事件处理函数--监听用户下拉动作
  106. */
  107. onPullDownRefresh: function () {
  108. },
  109. /**
  110. * 页面上拉触底事件的处理函数
  111. */
  112. onReachBottom: function () {
  113. if (this.data.current < this.data.pages) {
  114. this.setData({
  115. current: this.data.current + 1
  116. })
  117. this.toLoadData()
  118. }
  119. },
  120. /**
  121. * 用户点击右上角分享
  122. */
  123. onShareAppMessage: function () {
  124. },
  125. /**
  126. * 状态点击事件
  127. */
  128. onStsTap: function (e) {
  129. var sts = e.currentTarget.dataset.sts;
  130. this.setData({
  131. sts: sts
  132. });
  133. this.toLoadData();
  134. },
  135. toProdPage: function (e) {
  136. var prodid = e.currentTarget.dataset.prodid;
  137. wx.navigateTo({
  138. url: '/pages/prod/prod?prodid=' + prodid,
  139. })
  140. },
  141. })