addInfomation.js 7.0 KB

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