search-prod-show.js 3.1 KB

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