search-prod-show.js 3.3 KB

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