search.js 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. // pages/search/search.js
  2. const apiServer = require('../../api/request');
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. list: [],
  9. inputValue: null,
  10. resultList:[
  11. // {
  12. // title:'AppL',
  13. // subtitle:"APPL INC",
  14. // Increase:"1.22",
  15. // digital:"33",
  16. // data:[52,56,355,444]
  17. // },
  18. // {
  19. // title:'AppL',
  20. // subtitle:"APPL INC",
  21. // Increase:"1.22",
  22. // digital:"33",
  23. // data:[52,56,355,44554]
  24. // },
  25. ]
  26. },
  27. /**
  28. * 生命周期函数--监听页面加载
  29. */
  30. onLoad: function (options) {
  31. this.hotSearch();
  32. var _this = this;
  33. wx.getStorage({
  34. key: 'historySearch',
  35. success(res) {
  36. _this.setData({
  37. list: res.data
  38. })
  39. }
  40. })
  41. },
  42. blur: function (e) {
  43. this.setData({
  44. inputValue: e.detail.value
  45. })
  46. this.search();
  47. },
  48. search:function(){
  49. let data ={
  50. searchParam:this.data.inputValue
  51. };
  52. apiServer.getSearch(data).then((res) =>{
  53. if(res.statusCode == 200){
  54. this.setData({
  55. resultList:res.data.data
  56. }
  57. )
  58. }else{
  59. wx.showToast({
  60. title: '搜索失败',
  61. icon: 'none'
  62. })
  63. }
  64. })
  65. },
  66. hotSearch: function(){
  67. apiServer.hotSearch().then((res)=>{
  68. if(res.statusCode == 200){
  69. this.setData({
  70. hotList:res.data.data
  71. })
  72. }
  73. })
  74. },
  75. save: function () {
  76. var list = this.data.list;
  77. if (list.indexOf(this.data.inputValue) == -1 & this.data.inputValue != '') {
  78. list.push(this.data.inputValue);
  79. }
  80. this.setData({
  81. list: list
  82. })
  83. wx.setStorage({
  84. key: 'historySearch',
  85. data: list
  86. })
  87. },
  88. searchName: function (e) {
  89. this.setData({
  90. inputValue: e.currentTarget.dataset.value
  91. })
  92. this.search();
  93. },
  94. hotName:function(e){
  95. console.log(e);
  96. this.setData({
  97. inputValue: e.currentTarget.dataset.value.plateName
  98. })
  99. this.search();
  100. },
  101. remove: function () {
  102. var _this = this;
  103. wx.showModal({
  104. title: '提示',
  105. content: '确认清空所有记录?',
  106. success(res) {
  107. if (res.confirm) {
  108. wx.removeStorage({
  109. key: 'historySearch',
  110. success() {
  111. _this.setData({
  112. list: []
  113. })
  114. }
  115. })
  116. } else if (res.cancel) {
  117. console.log('用户点击取消')
  118. }
  119. }
  120. })
  121. },
  122. clean:function(){
  123. var _this=this
  124. setTimeout(function () {
  125. _this.setData({
  126. inputValue: '',
  127. })
  128. },100)
  129. },
  130. detail:function(e){
  131. console.log(e);
  132. this.save();
  133. wx.navigateTo({
  134. url: '../item/item?row='+JSON.stringify(e.currentTarget.dataset.row)
  135. });
  136. },
  137. /**
  138. * 生命周期函数--监听页面初次渲染完成
  139. */
  140. onReady: function () {
  141. },
  142. /**
  143. * 生命周期函数--监听页面显示
  144. */
  145. onShow: function () {
  146. },
  147. /**
  148. * 生命周期函数--监听页面隐藏
  149. */
  150. onHide: function () {
  151. },
  152. /**
  153. * 生命周期函数--监听页面卸载
  154. */
  155. onUnload: function () {
  156. },
  157. /**
  158. * 页面相关事件处理函数--监听用户下拉动作
  159. */
  160. onPullDownRefresh: function () {
  161. },
  162. /**
  163. * 页面上拉触底事件的处理函数
  164. */
  165. onReachBottom: function () {
  166. },
  167. /**
  168. * 用户点击右上角分享
  169. */
  170. onShareAppMessage: function () {
  171. },
  172. })