addInfomation.js 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  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. var index = Number(e.currentTarget.dataset.index);
  75. var obj = {};
  76. if (e.currentTarget.dataset.type == "SearchWord3")
  77. obj = this.data.SearchWord3[index];
  78. else
  79. obj = this.data.SearchList[index];
  80. main.updateSearchList(obj);
  81. app.globalData.TempSearchBackNumber = 2;
  82. app.globalData.CardList2=[];
  83. wx.navigateTo({
  84. url: './addInfomationDetail',
  85. });
  86. },
  87. searchResult: function (e) {
  88. var that = this;
  89. var search = that.data.SearchInfo;
  90. app.globalData.TempStr=search;
  91. if (wx.getStorageSync("IsHelpAddInfomation")==1){
  92. if (search!="厉害"){
  93. wx.showToast({
  94. title: '请输入“厉害”搜索',
  95. });
  96. return;
  97. }
  98. }
  99. if (e.currentTarget.dataset.search) {
  100. search = e.currentTarget.dataset.search;
  101. that.setData({
  102. SearchInfo:search,
  103. });
  104. }
  105. var searchtype=e.currentTarget.dataset.searchtype;
  106. var author=e.currentTarget.dataset.author;
  107. var shiciurl=e.currentTarget.dataset.shiciurl;
  108. main.searchInfomation(search,searchtype,author,shiciurl,function(list,obj){
  109. if (obj){
  110. main.updateSearchList(obj,function(){
  111. updateData(that,search);
  112. wx.navigateTo({
  113. url: './addInfomationDetail',
  114. });
  115. });
  116. }
  117. else{
  118. wx.setNavigationBarTitle({
  119. title: "搜索结果"
  120. });
  121. //debugger;
  122. that.setData({
  123. SearchList: list,
  124. IsStart: true,
  125. IsMore:true,
  126. });
  127. that.getCardList();
  128. updateData(that,search);
  129. }
  130. });
  131. function updateData(obj,search) {
  132. setTimeout(function () {
  133. var arr = obj.data.SearchTextList;
  134. for (var i = 0; i < arr.length; i++) {
  135. if (arr[i] == search) {
  136. arr.splice(i, 1);
  137. break;
  138. }
  139. }
  140. arr.unshift(search);
  141. while (arr.length > 10) {
  142. arr.pop();
  143. }
  144. wx.setStorageSync("SearchTextList", arr);
  145. obj.setData({
  146. SearchTextList: arr,
  147. });
  148. }, 2000);
  149. }
  150. },
  151. getCardList: function () {
  152. var that = this;
  153. var url = 'GetMiaoguoCardList2?UserID=' + app.globalData.userInfo.UserID;
  154. url += "&Key=" + that.data.SearchInfo;
  155. that.setData({
  156. Searching: true,
  157. });
  158. main.getData(url, function (data) {
  159. that.setData({
  160. Searching: false,
  161. });
  162. if (data) {
  163. if (data.List.length > 0) {
  164. var list=data.List;
  165. for (var i = 0; i < list.length; i++) {
  166. var item = list[i];
  167. item.Content[1].ContentStr = main.replaceCardInfoString(item.Content[1].Content);
  168. if (item.Content[1].ContentStr.length > WORD_LENGTH)
  169. item.Content[1].ContentStr = main.replaceCardInfoString(item.Content[1].ContentStr.substr(0, WORD_LENGTH)) + "...";
  170. item.Content[2].ContentStr = main.replaceCardInfoString(item.Content[2].Content);
  171. if (item.Content[2].ContentStr.length > WORD_LENGTH)
  172. item.Content[2].ContentStr = main.replaceCardInfoString(item.Content[2].ContentStr.substr(0, WORD_LENGTH)) + "...";
  173. var imageUrl = getImage(item.Content[1].Content);
  174. if (imageUrl.length == 0 && item.Content[2].Content)
  175. imageUrl = getImage(item.Content[2].Content);
  176. if (imageUrl.length == 0 && item.Content[3].Content)
  177. imageUrl = getImage(item.Content[3].Content);
  178. if (imageUrl.length > 0) {
  179. item.ImageUrlTemp = main.getTempImage(imageUrl);
  180. item.ImageUrlServer = imageUrl;
  181. }
  182. }
  183. that.setData({
  184. SearchCardList:list,
  185. });
  186. app.globalData.CardList2=list;
  187. }
  188. else{
  189. that.setData({
  190. SearchCardList:[],
  191. });
  192. }
  193. }
  194. });
  195. function getImage(str) {
  196. var result = "";
  197. if (str.indexOf("[图") >= 0) {
  198. result = str.substring(str.indexOf("[图") + 3, str.indexOf("[/图]"));
  199. result = result.substring(result.indexOf("]") + 1);
  200. }
  201. //console.log(result);
  202. return result;
  203. }
  204. },
  205. clearInput: function () {
  206. this.setData({
  207. IsStart: false,
  208. Searching: false,
  209. SearchInfo: "",
  210. Focus:true,
  211. });
  212. },
  213. close: function (e) {
  214. wx.navigateBack({
  215. delta: 1,
  216. });
  217. },
  218. deleteItem: function (e) {
  219. var that = this;
  220. that.setData({
  221. SearchTextList: [],
  222. });
  223. wx.removeStorageSync("SearchTextList");
  224. },
  225. deleteItem2: function (e) {
  226. var that = this;
  227. var index = e.currentTarget.dataset.index;
  228. that.data.SearchWord3.splice(index, 1);
  229. that.setData({
  230. SearchWord3: that.data.SearchWord3,
  231. });
  232. wx.setStorageSync("SearchWord3", that.data.SearchWord3);
  233. },
  234. setMoreHide:function(){
  235. this.setData({
  236. IsMore:false,
  237. });
  238. },
  239. closeHelp:function(){
  240. this.setData({
  241. IsShowHelp:false,
  242. });
  243. wx.setStorageSync('IsHelpAddInfomation', 0);
  244. },
  245. onShareAppMessage: function () {
  246. return {
  247. title: app.globalData.ShareTitle,
  248. path: app.globalData.SharePath + '?UserID=' + app.globalData.userInfo.UserID,
  249. imageUrl: app.globalData.ShareImage,
  250. }
  251. },
  252. });