search.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  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. search:this.data.inputValue
  51. };
  52. apiServer.getSearch(data).then((res) =>{
  53. if(res.statusCode == 200){
  54. this.setData({
  55. resultList:res.data.value
  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. remove: function () {
  95. var _this = this;
  96. wx.showModal({
  97. title: '提示',
  98. content: '确认清空所有记录?',
  99. success(res) {
  100. if (res.confirm) {
  101. wx.removeStorage({
  102. key: 'historySearch',
  103. success() {
  104. _this.setData({
  105. list: []
  106. })
  107. }
  108. })
  109. } else if (res.cancel) {
  110. console.log('用户点击取消')
  111. }
  112. }
  113. })
  114. },
  115. clean:function(){
  116. var _this=this
  117. setTimeout(function () {
  118. _this.setData({
  119. inputValue: '',
  120. })
  121. },100)
  122. },
  123. detail:function(e){
  124. console.log(e);
  125. this.save();
  126. wx.navigateTo({
  127. url: '../item/item?row='+JSON.stringify(e.currentTarget.dataset.row)
  128. });
  129. },
  130. /**
  131. * 生命周期函数--监听页面初次渲染完成
  132. */
  133. onReady: function () {
  134. },
  135. /**
  136. * 生命周期函数--监听页面显示
  137. */
  138. onShow: function () {
  139. },
  140. /**
  141. * 生命周期函数--监听页面隐藏
  142. */
  143. onHide: function () {
  144. },
  145. /**
  146. * 生命周期函数--监听页面卸载
  147. */
  148. onUnload: function () {
  149. },
  150. /**
  151. * 页面相关事件处理函数--监听用户下拉动作
  152. */
  153. onPullDownRefresh: function () {
  154. },
  155. /**
  156. * 页面上拉触底事件的处理函数
  157. */
  158. onReachBottom: function () {
  159. },
  160. /**
  161. * 用户点击右上角分享
  162. */
  163. onShareAppMessage: function () {
  164. },
  165. })