search-prod-show.js 3.2 KB

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