searchCard.js 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  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. var search = e.detail.value;
  27. var that = this;
  28. that.setData({
  29. SearchInfo: search,
  30. });
  31. },
  32. onFocus: function (e) {
  33. var that = this;
  34. that.setData({
  35. Searching:true,
  36. IsNull:false,
  37. });
  38. },
  39. onSearch: function (e) {
  40. if (e.currentTarget.dataset.search){
  41. this.data.SearchInfo = e.currentTarget.dataset.search;
  42. this.setData({
  43. SearchInfo:this.data.SearchInfo,
  44. });
  45. }
  46. if (this.data.SearchInfo && this.data.SearchInfo.length > 0) {
  47. var search = this.data.SearchInfo;
  48. var that = this;
  49. var url = 'GetMiaoguoCardList2?UserID=' + app.globalData.userInfo.UserID;
  50. if (search)
  51. url += "&Key=" + search;
  52. var timeoutGetData=0;
  53. wx.showLoading({
  54. title: '请稍后...',
  55. });
  56. main.getData(url, function (data) {
  57. wx.hideLoading();
  58. clearTimeout(timeoutGetData);
  59. if (data) {
  60. if (data.List.length==0){
  61. that.setData({
  62. IsNull:true,
  63. });
  64. that.getSearchData();
  65. }
  66. else{
  67. app.globalData.CardList= data.List;
  68. wx.navigateTo({
  69. url: './mainlist?search=' + search+'&Count='+data.Count,
  70. });
  71. }
  72. }
  73. });
  74. timeoutGetData=setTimeout(function(){
  75. wx.hideLoading();
  76. },10000);
  77. setTimeout(function () {
  78. var arr = that.data.SearchTextList;
  79. for (var i = 0; i < arr.length; i++) {
  80. if (arr[i] == search) {
  81. arr.splice(i, 1);
  82. break;
  83. }
  84. }
  85. arr.unshift(search);
  86. while (arr.length > 10) {
  87. arr.pop();
  88. }
  89. wx.setStorageSync("SearchTextList", arr);
  90. that.setData({
  91. SearchTextList: arr,
  92. });
  93. }, 2000);
  94. }
  95. else {
  96. wx.showToast({
  97. title: '请输搜索内容',
  98. })
  99. }
  100. },
  101. getSearchData:function(){
  102. var that=this;
  103. main.searchInfomation(that.data.SearchInfo,null,null,null,function(list,isList){
  104. that.setData({
  105. SearchList:list,
  106. Searching:false,
  107. });
  108. });
  109. },
  110. goto: function (e) {
  111. var url = e.currentTarget.dataset.url;
  112. var search=e.currentTarget.dataset.word;
  113. if (search){
  114. app.globalData.TempStr=e.currentTarget.dataset.url2;
  115. var search=e.currentTarget.dataset.word;
  116. var author=e.currentTarget.dataset.author;
  117. var searchtype=e.currentTarget.dataset.searchtype;
  118. url+="&Word="+search;
  119. if (author)
  120. url+="&Author="+author;
  121. if (searchtype)
  122. url+="&SearchType="+searchtype;
  123. wx.navigateTo({
  124. url: url,
  125. });
  126. }
  127. else{
  128. wx.navigateTo({
  129. url: url,
  130. });
  131. }
  132. },
  133. clearInput:function(){
  134. this.setData({
  135. SearchInfo:"",
  136. IsNull:false,
  137. SearchList:[],
  138. Focus:true,
  139. });
  140. },
  141. close: function (e) {
  142. wx.navigateBack({
  143. delta: 1,
  144. });
  145. },
  146. deleteItem: function (e) {
  147. var that = this;
  148. that.setData({
  149. SearchTextList: [],
  150. });
  151. wx.removeStorageSync("SearchTextList");
  152. },
  153. onShareAppMessage: function () {
  154. return {
  155. title: app.globalData.ShareTitle,
  156. path: app.globalData.SharePath + '?UserID=' + app.globalData.userInfo.UserID,
  157. imageUrl: app.globalData.ShareImage,
  158. }
  159. },
  160. })