search_user.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. import common from '../../utils/util';
  2. import main from '../../utils/main';
  3. const app = getApp();
  4. Page({
  5. data: {
  6. IsNull:false,
  7. IsList:false,
  8. Searching:true,
  9. SearchList:[],
  10. },
  11. onLoad: function (options) {
  12. var that = this;
  13. that.setData({
  14. Containnerheight: main.getWindowHeight(),
  15. });
  16. common.getStorageValue(that, "SearchTextList2", [], function () {});
  17. },
  18. onShow:function(){
  19. this.setData({
  20. Focus: true,
  21. });
  22. },
  23. onPullDownRefresh: function () {
  24. wx.stopPullDownRefresh();
  25. },
  26. onKeyInput: function (e) {
  27. console.log("onKeyInput");
  28. var search = e.detail.value;
  29. var that = this;
  30. that.setData({
  31. SearchInfo: search,
  32. });
  33. },
  34. onFocus: function (e) {
  35. console.log("onFocus");
  36. var that = this;
  37. that.setData({
  38. Searching:true,
  39. IsNull:false,
  40. });
  41. },
  42. onBindblur: function (e) {
  43. console.log("onBindblur");
  44. },
  45. onSearch: function (e) {
  46. if (e.currentTarget.dataset.search){
  47. this.data.SearchInfo = e.currentTarget.dataset.search;
  48. this.setData({
  49. SearchInfo:this.data.SearchInfo,
  50. });
  51. }
  52. if (this.data.SearchInfo && this.data.SearchInfo.length > 0) {
  53. var search = this.data.SearchInfo;
  54. var that = this;
  55. var url = 'GetMiaoguoIntroducerSearchUser?UserID=' + app.globalData.userInfo.UserID;
  56. if (search)
  57. url += "&Key=" + search;
  58. updateData(that,search);
  59. wx.showLoading({
  60. title: '请稍后...',
  61. });
  62. main.getData(url, function (data) {
  63. wx.hideLoading();
  64. if (data) {
  65. if (data.length==0){
  66. that.setData({
  67. IsNull:true,
  68. });
  69. }
  70. else{
  71. that.setData({
  72. IsList:true,
  73. List:data,
  74. });
  75. }
  76. }
  77. });
  78. }
  79. else {
  80. wx.showToast({
  81. title: '请输搜索内容',
  82. })
  83. }
  84. function updateData(obj,search) {
  85. setTimeout(function () {
  86. var arr = obj.data.SearchTextList2;
  87. for (var i = 0; i < arr.length; i++) {
  88. if (arr[i] == search) {
  89. arr.splice(i, 1);
  90. break;
  91. }
  92. }
  93. arr.unshift(search);
  94. while (arr.length > 10) {
  95. arr.pop();
  96. }
  97. wx.setStorageSync("SearchTextList2", arr);
  98. obj.setData({
  99. SearchTextList2: arr,
  100. });
  101. }, 2000);
  102. }
  103. },
  104. clearInput:function(){
  105. this.setData({
  106. SearchInfo:"",
  107. IsNull:false,
  108. SearchList:[],
  109. Focus:true,
  110. IsList:false,
  111. });
  112. },
  113. goto: function (e) {
  114. var url = e.currentTarget.dataset.url;
  115. wx.navigateTo({
  116. url: url,
  117. });
  118. },
  119. onClose: function () {
  120. wx.navigateBack({
  121. delta: 1,
  122. });
  123. },
  124. onShareAppMessage: function () {
  125. return {
  126. title: app.globalData.ShareTitle,
  127. path: app.globalData.SharePath + '?UserID=' + app.globalData.userInfo.UserID,
  128. imageUrl: app.globalData.ShareImage,
  129. }
  130. },
  131. })