addInfomation.js 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272
  1. import common from '../../utils/util';
  2. import main from '../../utils/main';
  3. const app = getApp();
  4. const WORD_LENGTH=18;
  5. Page({
  6. data: {
  7. IsStart: false,
  8. Searching: false,
  9. SearchList: [],
  10. SearchInfo: "",
  11. IsMore:true,
  12. IsShowHelp:false,
  13. },
  14. onLoad: function () {
  15. var that = this;
  16. that.setData({
  17. Containnerheight: main.getWindowHeight(),
  18. });
  19. },
  20. onShow: function () {
  21. var that = this;
  22. common.getStorageValue(that, "SearchTextList", [], function () {});
  23. common.getStorageValue(that, "SearchWord3", [], function () {
  24. var list = that.data.SearchWord3;
  25. for (var i = 0; i < list.length; i++) {
  26. var item = list[i];
  27. if (item.Type == "shici") {
  28. item.TypeName = "S";
  29. item.Remark = item.Author + " " + item.Dynasty;
  30. } else if (item.Type == "eng") {
  31. item.TypeName = "D";
  32. } else if (item.Type == "latex") {
  33. item.TypeName = "G";
  34. } else {
  35. if (item.Key.length == 1)
  36. item.TypeName = "Z";
  37. else
  38. item.TypeName = "C";
  39. }
  40. if (item.Content && item.Content.length > WORD_LENGTH)
  41. item.Content = item.Content.substr(0, WORD_LENGTH) + "...";
  42. }
  43. that.setData({
  44. SearchWord3: list,
  45. IsMore:true,
  46. });
  47. });
  48. if (wx.getStorageSync("IsHelpAddInfomation")==1){
  49. that.setData({
  50. IsShowHelp:true,
  51. });
  52. main.ShowHelp(that,"#input","down","在上方输入需要查找的\n词语。比如输入“厉害”,\n再点键盘右下的“搜索”");
  53. }
  54. else{
  55. that.setData({
  56. IsShowHelp:false,
  57. });
  58. }
  59. },
  60. goto: function (e) {
  61. var url = e.currentTarget.dataset.url;
  62. wx.navigateTo({
  63. url: './' + url,
  64. })
  65. },
  66. onKeyInput: function (e) {
  67. var search = e.detail.value;
  68. var that = this;
  69. that.setData({
  70. SearchInfo: search,
  71. });
  72. },
  73. onSearchHistory: function (e) {
  74. //debugger;
  75. var index = Number(e.currentTarget.dataset.index);
  76. var obj = {};
  77. if (e.currentTarget.dataset.type == "SearchWord3")
  78. obj = this.data.SearchWord3[index];
  79. else
  80. obj = this.data.SearchList[index];
  81. main.updateSearchList(obj);
  82. app.globalData.TempSearchBackNumber = 2;
  83. app.globalData.CardList2=[];
  84. wx.navigateTo({
  85. url: './addInfomationDetail',
  86. });
  87. },
  88. searchResult: function (e) {
  89. var that = this;
  90. var search = that.data.SearchInfo;
  91. app.globalData.TempStr=search;
  92. if (wx.getStorageSync("IsHelpAddInfomation")==1){
  93. if (search!="厉害"){
  94. wx.showToast({
  95. title: '请输入“厉害”搜索',
  96. });
  97. return;
  98. }
  99. }
  100. if (e.currentTarget.dataset.search) {
  101. search = e.currentTarget.dataset.search;
  102. that.setData({
  103. SearchInfo:search,
  104. });
  105. }
  106. var searchtype=e.currentTarget.dataset.searchtype;
  107. var author=e.currentTarget.dataset.author;
  108. var shiciurl=e.currentTarget.dataset.shiciurl;
  109. main.searchInfomation(search,searchtype,author,shiciurl,function(list,obj){
  110. if (obj){
  111. main.updateSearchList(obj,function(){
  112. updateData(that,search);
  113. wx.navigateTo({
  114. url: './addInfomationDetail',
  115. });
  116. });
  117. }
  118. else{
  119. wx.setNavigationBarTitle({
  120. title: "搜索结果"
  121. });
  122. //debugger;
  123. that.setData({
  124. SearchList: list,
  125. IsStart: true,
  126. IsMore:true,
  127. });
  128. that.getCardList();
  129. updateData(that,search);
  130. }
  131. });
  132. function updateData(obj,search) {
  133. setTimeout(function () {
  134. var arr = obj.data.SearchTextList;
  135. for (var i = 0; i < arr.length; i++) {
  136. if (arr[i] == search) {
  137. arr.splice(i, 1);
  138. break;
  139. }
  140. }
  141. arr.unshift(search);
  142. while (arr.length > 10) {
  143. arr.pop();
  144. }
  145. wx.setStorageSync("SearchTextList", arr);
  146. obj.setData({
  147. SearchTextList: arr,
  148. });
  149. }, 2000);
  150. }
  151. },
  152. getCardList: function () {
  153. var that = this;
  154. var url = 'GetMiaoguoCardList2?UserID=' + app.globalData.userInfo.UserID;
  155. url += "&Key=" + that.data.SearchInfo;
  156. that.setData({
  157. Searching: true,
  158. });
  159. main.getData(url, function (data) {
  160. that.setData({
  161. Searching: false,
  162. });
  163. if (data) {
  164. if (data.List.length > 0) {
  165. var list=data.List;
  166. for (var i = 0; i < list.length; i++) {
  167. var item = list[i];
  168. item.Content[1].ContentStr = main.replaceCardInfoString(item.Content[1].Content);
  169. if (item.Content[1].ContentStr.length > WORD_LENGTH)
  170. item.Content[1].ContentStr = main.replaceCardInfoString(item.Content[1].ContentStr.substr(0, WORD_LENGTH)) + "...";
  171. item.Content[2].ContentStr = main.replaceCardInfoString(item.Content[2].Content);
  172. if (item.Content[2].ContentStr.length > WORD_LENGTH)
  173. item.Content[2].ContentStr = main.replaceCardInfoString(item.Content[2].ContentStr.substr(0, WORD_LENGTH)) + "...";
  174. var imageUrl = getImage(item.Content[1].Content);
  175. if (imageUrl.length == 0 && item.Content[2].Content)
  176. imageUrl = getImage(item.Content[2].Content);
  177. if (imageUrl.length == 0 && item.Content[3].Content)
  178. imageUrl = getImage(item.Content[3].Content);
  179. if (imageUrl.length > 0) {
  180. item.ImageUrlTemp = main.getTempImage(imageUrl);
  181. item.ImageUrlServer = imageUrl;
  182. }
  183. }
  184. that.setData({
  185. SearchCardList:list,
  186. });
  187. app.globalData.CardList2=list;
  188. }
  189. else{
  190. that.setData({
  191. SearchCardList:[],
  192. });
  193. }
  194. }
  195. });
  196. function getImage(str) {
  197. var result = "";
  198. if (str.indexOf("[图") >= 0) {
  199. result = str.substring(str.indexOf("[图") + 3, str.indexOf("[/图]"));
  200. result = result.substring(result.indexOf("]") + 1);
  201. }
  202. //console.log(result);
  203. return result;
  204. }
  205. },
  206. clearInput: function () {
  207. this.setData({
  208. IsStart: false,
  209. Searching: false,
  210. SearchInfo: "",
  211. Focus:true,
  212. });
  213. },
  214. close: function (e) {
  215. wx.navigateBack({
  216. delta: 1,
  217. });
  218. },
  219. deleteItem: function (e) {
  220. var that = this;
  221. that.setData({
  222. SearchTextList: [],
  223. });
  224. wx.removeStorageSync("SearchTextList");
  225. },
  226. deleteItem2: function (e) {
  227. var that = this;
  228. var index = e.currentTarget.dataset.index;
  229. that.data.SearchWord3.splice(index, 1);
  230. that.setData({
  231. SearchWord3: that.data.SearchWord3,
  232. });
  233. wx.setStorageSync("SearchWord3", that.data.SearchWord3);
  234. },
  235. setMoreHide:function(){
  236. this.setData({
  237. IsMore:false,
  238. });
  239. },
  240. closeHelp:function(){
  241. this.setData({
  242. IsShowHelp:false,
  243. });
  244. wx.setStorageSync('IsHelpAddInfomation', 0);
  245. },
  246. onShareAppMessage: function () {
  247. return {
  248. title: app.globalData.ShareTitle,
  249. path: app.globalData.SharePath + '?UserID=' + app.globalData.userInfo.UserID,
  250. imageUrl: app.globalData.ShareImage,
  251. }
  252. },
  253. });