search.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. import common from '../../utils/util';
  2. import main from '../../utils/main';
  3. import constant from '../../utils/constant';
  4. const app = getApp();
  5. Page({
  6. data: {
  7. ImagePath: app.globalData.uploadImageUrl,
  8. SchoolSearch:constant.arrSchoolSearch,
  9. SearchList:[],
  10. IsFocus:true,
  11. },
  12. onLoad: function (options) {
  13. var that = this;
  14. that.setData({
  15. Containnerheight: main.getWindowHeight(),
  16. IsSearchFinish:false,
  17. IsSample:true,
  18. });
  19. that.getKey();
  20. },
  21. bindKeyInput:function(e){
  22. var that=this;
  23. var isExist=true;
  24. if (!e.detail.value)
  25. isExist=false;
  26. that.setData({
  27. InputValue:e.detail.value,
  28. IsSearchFinish:isExist,
  29. });
  30. if (e.detail.value)
  31. that.searchData();
  32. },
  33. searchKey:function(e){
  34. var that=this;
  35. that.setData({
  36. InputValue:e.currentTarget.dataset.key,
  37. });
  38. that.searchData({currentTarget:{dataset:{rowcount:-1}}});
  39. },
  40. clearInput:function(){
  41. var that=this;
  42. that.setData({
  43. InputValue:"",
  44. IsSearchFinish:false,
  45. IsFocus:true,
  46. List:[],
  47. });
  48. },
  49. bindConfirm:function(){
  50. this.searchData({currentTarget:{dataset:{rowcount:-1}}});
  51. },
  52. onBlur:function(){
  53. var that=this;
  54. that.setData({
  55. IsFocus:false,
  56. });
  57. },
  58. removeSearchData:function(){
  59. wx.removeStorageSync('SearchKey');
  60. this.getKey();
  61. },
  62. searchData:function(e){
  63. var that=this;
  64. var rowcount=4;
  65. if (e && e.currentTarget.dataset.rowcount){
  66. that.getKey();
  67. rowcount=e.currentTarget.dataset.rowcount;
  68. }
  69. var key=that.data.InputValue;
  70. wx.showLoading({title:"加载中"});
  71. main.getData("GetMPSSchool?Key="+key+"&RowCount="+rowcount, function (data) {
  72. if (data) {
  73. var isSample=true;
  74. if (rowcount==-1)
  75. isSample=false;
  76. that.setData({
  77. List:data,
  78. IsSearchFinish:true,
  79. IsSample:isSample,
  80. });
  81. }
  82. switch(key){
  83. case "上":
  84. case "学":
  85. case "中":
  86. case "初":
  87. case "上海":
  88. case "上海市":
  89. case "学校":
  90. case "中学":
  91. case "初级":
  92. setTimeout(function(){
  93. wx.hideLoading();
  94. },3000);
  95. break;
  96. default:
  97. wx.hideLoading();
  98. break;
  99. }
  100. });
  101. },
  102. goto: function (e) {
  103. this.getKey();
  104. main.goto(e);
  105. },
  106. close: function (e) {
  107. wx.navigateBack({
  108. delta: 1,
  109. });
  110. },
  111. getKey:function(e){
  112. var that=this;
  113. var arr=wx.getStorageSync('SearchKey');
  114. if (!arr)
  115. arr=[];
  116. //去重
  117. for(var i=0;i<arr.length;i++){
  118. if (arr[i]==that.data.InputValue){
  119. arr.splice(i,1);
  120. break;
  121. }
  122. }
  123. if (that.data.InputValue)
  124. arr.unshift(that.data.InputValue);
  125. if (arr.length>10)
  126. arr.pop();
  127. that.setData({
  128. SearchList:arr,
  129. });
  130. wx.setStorageSync('SearchKey', arr);
  131. },
  132. onShareTimeline: function () {
  133. return this.onShareAppMessage();
  134. },
  135. onShareAppMessage: function () {
  136. return {
  137. title: app.globalData.ShareTitle,
  138. path: app.globalData.SharePath + '?UserID=' + app.globalData.userInfo.UserID,
  139. imageUrl: app.globalData.ShareImage,
  140. }
  141. },
  142. })