shopSearchResult.js 2.9 KB

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