searchCard.js 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. import common from '../../utils/util';
  2. import main from '../../utils/main';
  3. const app = getApp();
  4. Page({
  5. data: {
  6. IsNull:false,
  7. Searching:true,
  8. SearchList:[],
  9. InfoArr:["拼音","默写","书写","组词","诗词","译文","发音","释义","反义词","近义词","部首","作者","翻译","例句"],
  10. },
  11. onLoad: function () {
  12. var that = this;
  13. that.setData({
  14. Containnerheight: main.getWindowHeight(),
  15. IsShowNull: false,
  16. Searching:true,
  17. });
  18. common.getStorageValue(that, "SearchTextList", [], function () {});
  19. },
  20. onShow:function(){
  21. this.setData({
  22. Focus: true,
  23. });
  24. },
  25. onKeyInput: function (e) {
  26. console.log("onKeyInput");
  27. var search = e.detail.value;
  28. var that = this;
  29. that.setData({
  30. SearchInfo: search,
  31. });
  32. },
  33. onFocus: function (e) {
  34. console.log("onFocus");
  35. var that = this;
  36. that.setData({
  37. Searching:true,
  38. IsNull:false,
  39. });
  40. },
  41. onBindblur: function (e) {
  42. console.log("onBindblur");
  43. },
  44. onSearch: function (e) {
  45. if (e.currentTarget.dataset.search){
  46. this.data.SearchInfo = e.currentTarget.dataset.search;
  47. this.setData({
  48. SearchInfo:this.data.SearchInfo,
  49. });
  50. }
  51. if (this.data.SearchInfo && this.data.SearchInfo.length > 0) {
  52. var search = this.data.SearchInfo;
  53. var that = this;
  54. var url = 'GetMiaoguoCardList2?UserID=' + app.globalData.userInfo.UserID;
  55. if (search)
  56. url += "&Key=" + search;
  57. var timeoutGetData=0;
  58. wx.showLoading({
  59. title: '请稍后...',
  60. });
  61. main.getData(url, function (data) {
  62. wx.hideLoading();
  63. clearTimeout(timeoutGetData);
  64. if (data) {
  65. if (data.List.length==0){
  66. that.setData({
  67. IsNull:true,
  68. });
  69. that.getSearchData();
  70. }
  71. else{
  72. app.globalData.CardList= data.List;
  73. var url='./mainlist?search=' + search+'&Count='+data.Count;
  74. wx.navigateTo({
  75. url: url,
  76. });
  77. }
  78. }
  79. });
  80. timeoutGetData=setTimeout(function(){
  81. wx.hideLoading();
  82. },10000);
  83. setTimeout(function () {
  84. var arr = that.data.SearchTextList;
  85. for (var i = 0; i < arr.length; i++) {
  86. if (arr[i] == search) {
  87. arr.splice(i, 1);
  88. break;
  89. }
  90. }
  91. arr.unshift(search);
  92. while (arr.length > 10) {
  93. arr.pop();
  94. }
  95. wx.setStorageSync("SearchTextList", arr);
  96. that.setData({
  97. SearchTextList: arr,
  98. });
  99. }, 2000);
  100. }
  101. else {
  102. wx.showToast({
  103. title: '请输搜索内容',
  104. })
  105. }
  106. },
  107. getSearchData:function(){
  108. var that=this;
  109. main.searchInfomation(that.data.SearchInfo,null,null,null,function(list,obj){
  110. if ((!list || list.length==0) && obj){
  111. list=[];
  112. list.push(obj);
  113. }
  114. that.setData({
  115. SearchList:list,
  116. Searching:false,
  117. });
  118. });
  119. },
  120. goto: function (e) {
  121. var url = e.currentTarget.dataset.url;
  122. var search=e.currentTarget.dataset.word;
  123. if (search){
  124. app.globalData.TempStr=e.currentTarget.dataset.url2;
  125. var search=e.currentTarget.dataset.word;
  126. var author=e.currentTarget.dataset.author;
  127. var searchtype=e.currentTarget.dataset.searchtype;
  128. url+="&Word="+search;
  129. if (author)
  130. url+="&Author="+author;
  131. if (searchtype)
  132. url+="&SearchType="+searchtype;
  133. wx.navigateTo({
  134. url: url,
  135. });
  136. }
  137. else{
  138. wx.navigateTo({
  139. url: url,
  140. });
  141. }
  142. },
  143. clearInput:function(){
  144. console.log("clearInput");
  145. this.setData({
  146. SearchInfo:"",
  147. IsNull:false,
  148. SearchList:[],
  149. Focus:true,
  150. });
  151. },
  152. close: function (e) {
  153. wx.navigateBack({
  154. delta: 1,
  155. });
  156. },
  157. deleteItem: function (e) {
  158. var that = this;
  159. that.setData({
  160. SearchTextList: [],
  161. });
  162. wx.removeStorageSync("SearchTextList");
  163. },
  164. onShareAppMessage: function () {
  165. return {
  166. title: app.globalData.ShareTitle,
  167. path: app.globalData.SharePath + '?UserID=' + app.globalData.userInfo.UserID,
  168. imageUrl: app.globalData.ShareImage,
  169. }
  170. },
  171. })