searchCardList.js 5.9 KB

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