search.js 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  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.get
  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. console.log(res.data);
  55. }else{
  56. wx.showToast({
  57. title: '搜索失败',
  58. icon: 'none'
  59. })
  60. }
  61. })
  62. },
  63. save: function () {
  64. var list = this.data.list;
  65. if (list.indexOf(this.data.inputValue) == -1 & this.data.inputValue != '') {
  66. list.push(this.data.inputValue);
  67. }
  68. this.setData({
  69. list: list
  70. })
  71. wx.setStorage({
  72. key: 'historySearch',
  73. data: list
  74. })
  75. },
  76. searchName: function (e) {
  77. this.setData({
  78. inputValue: e.currentTarget.dataset.value
  79. })
  80. this.search();
  81. },
  82. remove: function () {
  83. var _this = this;
  84. wx.showModal({
  85. title: '提示',
  86. content: '确认清空所有记录?',
  87. success(res) {
  88. if (res.confirm) {
  89. wx.removeStorage({
  90. key: 'historySearch',
  91. success() {
  92. _this.setData({
  93. list: []
  94. })
  95. }
  96. })
  97. } else if (res.cancel) {
  98. console.log('用户点击取消')
  99. }
  100. }
  101. })
  102. },
  103. clean:function(){
  104. var _this=this
  105. setTimeout(function () {
  106. _this.setData({
  107. inputValue: '',
  108. })
  109. },100)
  110. },
  111. detail:function(e){
  112. this.save();
  113. wx.navigateTo({
  114. url: '../item/item'
  115. });
  116. },
  117. /**
  118. * 生命周期函数--监听页面初次渲染完成
  119. */
  120. onReady: function () {
  121. },
  122. /**
  123. * 生命周期函数--监听页面显示
  124. */
  125. onShow: function () {
  126. },
  127. /**
  128. * 生命周期函数--监听页面隐藏
  129. */
  130. onHide: function () {
  131. },
  132. /**
  133. * 生命周期函数--监听页面卸载
  134. */
  135. onUnload: function () {
  136. },
  137. /**
  138. * 页面相关事件处理函数--监听用户下拉动作
  139. */
  140. onPullDownRefresh: function () {
  141. },
  142. /**
  143. * 页面上拉触底事件的处理函数
  144. */
  145. onReachBottom: function () {
  146. },
  147. /**
  148. * 用户点击右上角分享
  149. */
  150. onShareAppMessage: function () {
  151. },
  152. })