searchCardList.js 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  1. import common from '../../utils/util';
  2. import main from '../../utils/main';
  3. const app = getApp();
  4. var intervalRefresh = 0;
  5. Page({
  6. data: {
  7. HasPage:false,
  8. },
  9. onLoad: function (options) {
  10. wx.hideShareMenu();
  11. var that = this;
  12. var Search = "", IsToday = 0, IsCollect = 0;
  13. if (options.search) {
  14. Search = options.search;
  15. wx.setNavigationBarTitle({
  16. title: "搜索结果"
  17. });
  18. }
  19. else if (options.type == 1) {
  20. IsToday = 1;
  21. wx.setNavigationBarTitle({
  22. title: "剩余任务"
  23. });
  24. }
  25. else if (options.IsCollect == 1) {
  26. wx.setNavigationBarTitle({
  27. title: "幻灯片"
  28. });
  29. IsCollect=1;
  30. }
  31. that.setData({
  32. IsCollect:IsCollect,
  33. Search: Search,
  34. IsToday: IsToday,
  35. Count: options.Count,
  36. Containnerheight: main.getWindowHeight(),
  37. });
  38. },
  39. onShow: function () {
  40. var that = this;
  41. that.getList();
  42. },
  43. onPullDownRefresh: function () {
  44. var that = this;
  45. app.globalData.CardList=[];
  46. that.gotoNextPage({currentTarget:{dataset:{id:0}}});
  47. wx.stopPullDownRefresh();
  48. },
  49. getList: function () {
  50. var that=this;
  51. var list = app.globalData.CardList;
  52. var len = 16;
  53. for (var i = 0; i < list.length; i++) {
  54. var item = list[i];
  55. item.Content[1].ContentStr = replaceString(item.Content[1].Content);
  56. if (item.Content[1].ContentStr.length > len)
  57. item.Content[1].ContentStr = replaceString(item.Content[1].ContentStr.substr(0, len)) + "...";
  58. item.Content[2].ContentStr = replaceString(item.Content[2].Content);
  59. if (item.Content[2].ContentStr.length > len)
  60. item.Content[2].ContentStr = replaceString(item.Content[2].ContentStr.substr(0, len)) + "...";
  61. var imageUrl = getImage(item.Content[1].Content);
  62. if (imageUrl.length == 0 && item.Content[2].Content)
  63. imageUrl = getImage(item.Content[2].Content);
  64. if (imageUrl.length == 0 && item.Content[3].Content)
  65. imageUrl = getImage(item.Content[3].Content);
  66. if (imageUrl.length > 0) {
  67. item.ImageUrlTemp = main.getTempImage(imageUrl);
  68. item.ImageUrlServer = imageUrl;
  69. }
  70. }
  71. // if (that.data.IsToday==1){
  72. // var tempList=[];
  73. // for (var i = 0; i < list.length; i++) {
  74. // var item = list[i];
  75. // var limitTimeStr = common.formatDateCHS(item.LimitTime);
  76. // var today = common.formatDateCHS(common.formatTime(new Date()));
  77. // if (limitTimeStr <= today) {
  78. // tempList.push(list[i]);
  79. // }
  80. // }
  81. // list=tempList;
  82. // app.globalData.CardList=list;
  83. // }
  84. var hasPage=false;
  85. if (list.length<that.data.Count && that.data.IsToday==0)
  86. hasPage=true;
  87. this.setData({
  88. List: list,
  89. HasPage:hasPage,
  90. });
  91. wx.hideLoading();
  92. function getImage(str) {
  93. var result = "";
  94. if (str.indexOf("[图") >= 0) {
  95. result = str.substring(str.indexOf("[图]") + 3, str.indexOf("[/图]"));
  96. result = result.substring(result.indexOf("]") + 1);
  97. }
  98. return result;
  99. }
  100. function replaceString(str) {
  101. str = str.replace(/\[读]/g, "");
  102. str = str.replace(/\[\/读\]/g, "");
  103. str = str.replace(/\[图]/g, "");
  104. str = str.replace(/\[\/图\]/g, "");
  105. var str2 = "";
  106. if (str.indexOf("[读") >= 0) {
  107. str2 = str.substr(str.indexOf("[读"));
  108. str2 = str2.substring(0, str2.indexOf("]") + 1);
  109. }
  110. str = str.replace(str2, "");
  111. if (str.indexOf("[读") >= 0) {
  112. str2 = str.substr(str.indexOf("[读"));
  113. str2 = str2.substring(0, str2.indexOf("]") + 1);
  114. }
  115. str = str.replace(str2, "");
  116. var str3 = "";
  117. if (str.indexOf("[图") >= 0) {
  118. str3 = str.substr(str.indexOf("[图"));
  119. str3 = str3.substring(0, str3.indexOf("]") + 1);
  120. }
  121. str = str.replace(str3, "");
  122. str = str.replace(/\[线]/g, "");
  123. str = str.replace(/\[\/线\]/g, "");
  124. str = main.encryptUrl(str);
  125. return str;
  126. }
  127. },
  128. onPreview: function (e) {
  129. var id = e.currentTarget.dataset.id;
  130. wx.navigateTo({
  131. url: './preview?type=show&id=' + id,
  132. })
  133. },
  134. playPPT:function(){
  135. wx.navigateTo({
  136. url: './preview?type=play',
  137. })
  138. },
  139. onBindError: function (e) {
  140. var that = this;
  141. var id = e.currentTarget.dataset.id;
  142. var serverUrl = e.currentTarget.dataset.serverurl;
  143. wx.downloadFile({
  144. url: serverUrl, // 仅为示例,并非真实的资源
  145. success(res) {
  146. // 只要服务器有响应数据,就会把响应内容写入文件并进入 success 回调,业务需要自行判断是否下载到了想要的内容
  147. if (res.statusCode === 200) {
  148. main.saveTempImage(serverUrl, res.tempFilePath);
  149. }
  150. }
  151. });
  152. clearTimeout(intervalRefresh);
  153. intervalRefresh = setTimeout(function () {
  154. that.getList();
  155. }, 1000);
  156. },
  157. gotoNextPage: function (e) {
  158. wx.showLoading({
  159. title: '请稍候',
  160. });
  161. setTimeout(function () {
  162. wx.hideLoading();
  163. }, 5000);
  164. var that = this;
  165. var id = e.currentTarget.dataset.id;
  166. var url = 'GetMiaoguoCardList?UserID=' + app.globalData.userInfo.UserID + "&IsToday=" + that.data.IsToday;
  167. if (id && id>0)
  168. url+="&PageID=" + id;
  169. if (that.data.Search)
  170. url += "&Key=" + that.data.Search;
  171. main.getData(url, function (data) {
  172. if (data) {
  173. var list = app.globalData.CardList;
  174. for (var i = 0; i < data.List.length; i++) {
  175. list.push(data.List[i]);
  176. }
  177. app.globalData.CardList=list;
  178. that.getList();
  179. }
  180. });
  181. },
  182. addCard: function () {
  183. wx.redirectTo({
  184. url: './add?type=add&id=0',
  185. });
  186. },
  187. onSearch:function(){
  188. wx.navigateBack({
  189. delta: 1,
  190. });
  191. },
  192. onShareAppMessage: function () {
  193. return {
  194. title: app.globalData.ShareTitle,
  195. path: app.globalData.SharePath + '?UserID=' + app.globalData.userInfo.UserID,
  196. imageUrl: app.globalData.ShareImage,
  197. }
  198. },
  199. })