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. wx.navigateTo({
  74. url: './mainlist?search=' + search+'&Count='+data.Count,
  75. });
  76. }
  77. }
  78. });
  79. timeoutGetData=setTimeout(function(){
  80. wx.hideLoading();
  81. },10000);
  82. setTimeout(function () {
  83. var arr = that.data.SearchTextList;
  84. for (var i = 0; i < arr.length; i++) {
  85. if (arr[i] == search) {
  86. arr.splice(i, 1);
  87. break;
  88. }
  89. }
  90. arr.unshift(search);
  91. while (arr.length > 10) {
  92. arr.pop();
  93. }
  94. wx.setStorageSync("SearchTextList", arr);
  95. that.setData({
  96. SearchTextList: arr,
  97. });
  98. }, 2000);
  99. }
  100. else {
  101. wx.showToast({
  102. title: '请输搜索内容',
  103. })
  104. }
  105. },
  106. getSearchData:function(){
  107. var that=this;
  108. main.searchInfomation(that.data.SearchInfo,null,null,null,function(list,obj){
  109. if ((!list || list.length==0) && obj){
  110. list=[];
  111. list.push(obj);
  112. }
  113. that.setData({
  114. SearchList:list,
  115. Searching:false,
  116. });
  117. });
  118. },
  119. goto: function (e) {
  120. var url = e.currentTarget.dataset.url;
  121. var search=e.currentTarget.dataset.word;
  122. if (search){
  123. app.globalData.TempStr=e.currentTarget.dataset.url2;
  124. var search=e.currentTarget.dataset.word;
  125. var author=e.currentTarget.dataset.author;
  126. var searchtype=e.currentTarget.dataset.searchtype;
  127. url+="&Word="+search;
  128. if (author)
  129. url+="&Author="+author;
  130. if (searchtype)
  131. url+="&SearchType="+searchtype;
  132. wx.navigateTo({
  133. url: url,
  134. });
  135. }
  136. else{
  137. wx.navigateTo({
  138. url: url,
  139. });
  140. }
  141. },
  142. clearInput:function(){
  143. console.log("clearInput");
  144. this.setData({
  145. SearchInfo:"",
  146. IsNull:false,
  147. SearchList:[],
  148. Focus:true,
  149. });
  150. },
  151. close: function (e) {
  152. wx.navigateBack({
  153. delta: 1,
  154. });
  155. },
  156. deleteItem: function (e) {
  157. var that = this;
  158. that.setData({
  159. SearchTextList: [],
  160. });
  161. wx.removeStorageSync("SearchTextList");
  162. },
  163. onShareAppMessage: function () {
  164. return {
  165. title: app.globalData.ShareTitle,
  166. path: app.globalData.SharePath + '?UserID=' + app.globalData.userInfo.UserID,
  167. imageUrl: app.globalData.ShareImage,
  168. }
  169. },
  170. })