searchCardList.js 5.4 KB

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