searchWeb1.js 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. import common from '../../utils/util';
  2. import main from '../../utils/main';
  3. const app = getApp();
  4. Page({
  5. data: {
  6. },
  7. onLoad: function () {
  8. var that = this;
  9. that.setData({
  10. Containnerheight: main.getWindowHeight(),
  11. IsShowNull: false,
  12. });
  13. },
  14. onShow:function(){
  15. if (wx.getStorageSync("SearchNull")){
  16. this.setData({
  17. IsShowNull:true,
  18. })
  19. wx.removeStorageSync("SearchNull");
  20. }
  21. },
  22. onKeyInput: function (e) {
  23. var search = e.detail.value;
  24. var that = this;
  25. that.setData({
  26. SearchInfo: search,
  27. });
  28. },
  29. onSearch: function (e) {
  30. if (this.data.SearchInfo && this.data.SearchInfo.length>0){
  31. var search = this.data.SearchInfo;
  32. var arr=wx.getStorageSync("SearchWord");
  33. if (!arr)
  34. arr=[];
  35. var obj = {};
  36. obj.Key = search;
  37. for(var i=0;i<arr.length;i++){
  38. if (arr[i].Key == search){
  39. obj.Key = arr[i].Key;
  40. obj.Value = arr[i].Value;
  41. arr.splice(i,1);
  42. break;
  43. }
  44. }
  45. arr.unshift(obj);
  46. wx.setStorageSync("SearchWord", arr);
  47. wx.navigateTo({
  48. url: './searchWeb2?back=3&search=' + search+'&type=0',
  49. })
  50. }
  51. else{
  52. wx.showToast({
  53. title: '请输搜索内容',
  54. })
  55. }
  56. },
  57. onSearchHistory: function (e) {
  58. var search = e.currentTarget.dataset.search;
  59. var arr = wx.getStorageSync("SearchWord");
  60. if (!arr)
  61. arr = [];
  62. var obj = {};
  63. obj.Key = search;
  64. var b=false,type=0;
  65. for (var i = 0; i < arr.length; i++) {
  66. if (arr[i].Key == search) {
  67. obj.Key = arr[i].Key;
  68. obj.Value = arr[i].Value;
  69. arr.splice(i, 1);
  70. b=true;
  71. type=1
  72. break;
  73. }
  74. }
  75. if (b){
  76. arr.unshift(obj);
  77. wx.setStorageSync("SearchWord", arr);
  78. }
  79. wx.navigateTo({
  80. url: './searchWeb2?back=2&search=' + search + '&type='+type,
  81. });
  82. },
  83. close: function (e) {
  84. wx.navigateBack({
  85. delta: 1,
  86. });
  87. }
  88. })