search-prod-show.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  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. lat: wx.getStorageSync('LATITUDE'),
  66. lon: wx.getStorageSync('LONGITUDE'),
  67. distance: wx.getStorageSync('DISTANCE') || 0
  68. }
  69. if(ths.data.shopId !=0){
  70. data.shopId = this.data.shopId
  71. }
  72. //热门搜索
  73. var params = {
  74. url: "/search/searchProdPage",
  75. method: "GET",
  76. data ,
  77. callBack: function(res) {
  78. wx.hideLoading()
  79. let img=''
  80. res.records.forEach(item=>{
  81. img=item.pic.split(',')
  82. item.pic=img[0]
  83. })
  84. let list = []
  85. if (res.current == 1) {
  86. list = res.records
  87. } else {
  88. list = ths.data.searchProdList
  89. list = list.concat(res.records)
  90. }
  91. ths.setData({
  92. searchProdList: list,
  93. pages: res.pages
  94. });
  95. },
  96. };
  97. http.request(params);
  98. },
  99. //当前搜索页二次搜索商品
  100. toSearchConfirm: function() {
  101. this.toLoadData();
  102. },
  103. /**
  104. * 生命周期函数--监听页面隐藏
  105. */
  106. onHide: function() {
  107. },
  108. /**
  109. * 生命周期函数--监听页面卸载
  110. */
  111. onUnload: function() {
  112. },
  113. /**
  114. * 页面相关事件处理函数--监听用户下拉动作
  115. */
  116. onPullDownRefresh: function() {
  117. },
  118. /**
  119. * 页面上拉触底事件的处理函数
  120. */
  121. onReachBottom: function() {
  122. if (this.data.current < this.data.pages) {
  123. this.setData({
  124. current: this.data.current + 1
  125. })
  126. this.toLoadData()
  127. }
  128. },
  129. /**
  130. * 用户点击右上角分享
  131. */
  132. onShareAppMessage: function() {
  133. },
  134. /**
  135. * 状态点击事件
  136. */
  137. onStsTap: function(e) {
  138. wx.pageScrollTo({
  139. scrollTop: 0,
  140. duration: 300,
  141. })
  142. var sts = e.currentTarget.dataset.sts;
  143. this.setData({
  144. sts: sts,
  145. current: 1,
  146. pages: 1
  147. });
  148. this.toLoadData();
  149. },
  150. toProdPage: function(e) {
  151. var prodid = e.currentTarget.dataset.prodid;
  152. var shopid = e.currentTarget.dataset.shopid;
  153. wx.navigateTo({
  154. url: `/pages/prod/prod?prodid=${prodid}&shopid=${shopid}`,
  155. })
  156. },
  157. })