search_user.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  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. IsList:true,
  69. });
  70. }
  71. else{
  72. that.setData({
  73. IsList:true,
  74. List:data,
  75. });
  76. }
  77. }
  78. });
  79. }
  80. else {
  81. wx.showToast({
  82. title: '请输搜索内容',
  83. })
  84. }
  85. function updateData(obj,search) {
  86. setTimeout(function () {
  87. var arr = obj.data.SearchTextList2;
  88. for (var i = 0; i < arr.length; i++) {
  89. if (arr[i] == search) {
  90. arr.splice(i, 1);
  91. break;
  92. }
  93. }
  94. arr.unshift(search);
  95. while (arr.length > 10) {
  96. arr.pop();
  97. }
  98. wx.setStorageSync("SearchTextList2", arr);
  99. obj.setData({
  100. SearchTextList2: arr,
  101. });
  102. }, 2000);
  103. }
  104. },
  105. clearInput:function(){
  106. this.setData({
  107. SearchInfo:"",
  108. IsNull:false,
  109. SearchList:[],
  110. Focus:true,
  111. IsList:false,
  112. });
  113. },
  114. goto: function (e) {
  115. var url = e.currentTarget.dataset.url;
  116. wx.navigateTo({
  117. url: url,
  118. });
  119. },
  120. onClose: function () {
  121. wx.navigateBack({
  122. delta: 1,
  123. });
  124. },
  125. onShareAppMessage: function () {
  126. return {
  127. title: app.globalData.ShareTitle,
  128. path: app.globalData.SharePath + '?UserID=' + app.globalData.userInfo.UserID,
  129. imageUrl: app.globalData.ShareImage,
  130. }
  131. },
  132. })