searchCardList.js 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363
  1. import common from '../../utils/util';
  2. import main from '../../utils/main';
  3. const app = getApp();
  4. var intervalRefresh = 0;
  5. var arrOrder = [
  6. { Name: "最近添加", Value: "ac.MiaoguoCardID desc", CSS: "numberContainerFooter1121Select" },
  7. { Name: "较早添加", Value: "ac.MiaoguoCardID asc" },
  8. { Name: "练习次数", Value: "ac.LearnNumber desc,ac.MiaoguoCardID desc" }
  9. ];
  10. Page({
  11. data: {
  12. HasPage: false,
  13. ArrOrder: arrOrder,
  14. OrderType: arrOrder[0].Value,
  15. },
  16. onLoad: function (options) {
  17. var that = this;
  18. var Search = "", IsToday = 0, IsCollect = 0;
  19. if (options.search) {
  20. Search = options.search;
  21. wx.setNavigationBarTitle({
  22. title: "搜索结果"
  23. });
  24. }
  25. else if (options.type == 1) {
  26. IsToday = 1;
  27. wx.setNavigationBarTitle({
  28. title: "任务清单"
  29. });
  30. }
  31. else if (options.IsCollect == 1) {
  32. wx.setNavigationBarTitle({
  33. title: "收藏夹"
  34. });
  35. IsCollect = 1;
  36. }
  37. var count = 0;
  38. if (options.count)
  39. count = options.count;
  40. that.setData({
  41. IsCollect: IsCollect,
  42. Search: Search,
  43. IsToday: IsToday,
  44. Count: count,
  45. Containnerheight: main.getWindowHeight(),
  46. });
  47. },
  48. onShow: function () {
  49. var that = this;
  50. that.getList();
  51. //题卡主题色
  52. var arrColorIndex = wx.getStorageSync("ColorIndexArr");
  53. if (!arrColorIndex) {
  54. app.globalData.ColorIndex = common.random(1, 4);
  55. }
  56. else {
  57. app.globalData.ColorIndex = arrColorIndex[common.random(0, arrColorIndex.length - 1)];
  58. }
  59. },
  60. onPullDownRefresh: function () {
  61. var that = this;
  62. if (!that.data.IsCollect && !that.data.IsToday) {
  63. app.globalData.CardList = [];
  64. that.gotoNextPage({ currentTarget: { dataset: { id: 0 } } });
  65. }
  66. wx.stopPullDownRefresh();
  67. },
  68. getList: function () {
  69. var that = this;
  70. var list = app.globalData.CardList;
  71. var len = 16;
  72. for (var i = 0; i < list.length; i++) {
  73. var item = list[i];
  74. item.ScrollLeft = 0;
  75. item.DeleteStr = "删除";
  76. item.Content[1].ContentStr = replaceString(item.Content[1].Content);
  77. if (item.Content[1].ContentStr.length > len)
  78. item.Content[1].ContentStr = replaceString(item.Content[1].ContentStr.substr(0, len)) + "...";
  79. item.Content[2].ContentStr = replaceString(item.Content[2].Content);
  80. if (item.Content[2].ContentStr.length > len)
  81. item.Content[2].ContentStr = replaceString(item.Content[2].ContentStr.substr(0, len)) + "...";
  82. var imageUrl = getImage(item.Content[1].Content);
  83. if (imageUrl.length == 0 && item.Content[2].Content)
  84. imageUrl = getImage(item.Content[2].Content);
  85. if (imageUrl.length == 0 && item.Content[3].Content)
  86. imageUrl = getImage(item.Content[3].Content);
  87. if (imageUrl.length > 0) {
  88. item.ImageUrlTemp = main.getTempImage(imageUrl);
  89. item.ImageUrlServer = imageUrl;
  90. }
  91. }
  92. // if (that.data.IsToday==1){
  93. // var tempList=[];
  94. // for (var i = 0; i < list.length; i++) {
  95. // var item = list[i];
  96. // var limitTimeStr = common.formatDateCHS(item.LimitTime);
  97. // var today = common.formatDateCHS(common.formatTime(new Date()));
  98. // if (limitTimeStr <= today) {
  99. // tempList.push(list[i]);
  100. // }
  101. // }
  102. // list=tempList;
  103. // app.globalData.CardList=list;
  104. // }
  105. if (!that.data.IsCollect && !that.data.IsToday && !that.data.Search) {
  106. main.getData("GetUserCardCount?UserID=" + app.globalData.userInfo.UserID, function (data) {
  107. if (data) {
  108. that.setData({
  109. Count: data.CardNumber,
  110. });
  111. var hasPage = false;
  112. if (list.length < that.data.Count && that.data.IsToday == 0 && !that.data.IsCollect)
  113. hasPage = true;
  114. that.setData({
  115. List: list,
  116. HasPage: hasPage,
  117. });
  118. }
  119. });
  120. }
  121. else if (that.data.Search) {
  122. that.setData({
  123. List: list,
  124. Count: list.length,
  125. HasPage: true,
  126. });
  127. }
  128. else {
  129. that.setData({
  130. Count: list.length,
  131. });
  132. var hasPage = false;
  133. if (list.length < that.data.Count && that.data.IsToday == 0 && !that.data.IsCollect)
  134. hasPage = true;
  135. that.setData({
  136. List: list,
  137. HasPage: hasPage,
  138. });
  139. }
  140. wx.hideLoading();
  141. function getImage(str) {
  142. var result = "";
  143. if (str.indexOf("[图") >= 0) {
  144. result = str.substring(str.indexOf("[图") + 3, str.indexOf("[/图]"));
  145. result = result.substring(result.indexOf("]") + 1);
  146. }
  147. //console.log(result);
  148. return result;
  149. }
  150. function replaceString(str) {
  151. str = str.replace(/\[读]/g, "");
  152. str = str.replace(/\[\/读\]/g, "");
  153. str = str.replace(/\[图]/g, "");
  154. str = str.replace(/\[\/图\]/g, "");
  155. var str2 = "";
  156. if (str.indexOf("[读") >= 0) {
  157. str2 = str.substr(str.indexOf("[读"));
  158. str2 = str2.substring(0, str2.indexOf("]") + 1);
  159. }
  160. str = str.replace(str2, "");
  161. if (str.indexOf("[读") >= 0) {
  162. str2 = str.substr(str.indexOf("[读"));
  163. str2 = str2.substring(0, str2.indexOf("]") + 1);
  164. }
  165. str = str.replace(str2, "");
  166. var str3 = "";
  167. if (str.indexOf("[图") >= 0) {
  168. str3 = str.substr(str.indexOf("[图"));
  169. str3 = str3.substring(0, str3.indexOf("]") + 1);
  170. }
  171. str = str.replace(str3, "");
  172. str = str.replace(/\[线]/g, "");
  173. str = str.replace(/\[\/线\]/g, "");
  174. str = main.encryptUrl(str);
  175. return str;
  176. }
  177. },
  178. onPreview: function (e) {
  179. var id = e.currentTarget.dataset.id;
  180. wx.navigateTo({
  181. url: './preview?type=show&id=' + id,
  182. })
  183. },
  184. playPPT: function () {
  185. wx.navigateTo({
  186. url: './preview?type=play',
  187. })
  188. },
  189. onBindError: function (e) {
  190. var that = this;
  191. var id = e.currentTarget.dataset.id;
  192. var serverUrl = e.currentTarget.dataset.serverurl;
  193. wx.downloadFile({
  194. url: serverUrl, // 仅为示例,并非真实的资源
  195. success(res) {
  196. if (res.statusCode === 200) {
  197. main.saveTempImage(serverUrl, res.tempFilePath);
  198. }
  199. }
  200. });
  201. // clearTimeout(intervalRefresh);
  202. // intervalRefresh = setTimeout(function () {
  203. // that.getList();
  204. // }, 1000);
  205. },
  206. gotoNextPage: function (e) {
  207. wx.showLoading({
  208. title: '请稍候',
  209. });
  210. setTimeout(function () {
  211. wx.hideLoading();
  212. }, 5000);
  213. var that = this;
  214. var url = 'GetMiaoguoCardList?UserID=' + app.globalData.userInfo.UserID + "&IsToday=" + that.data.IsToday;
  215. var id = e.currentTarget.dataset.id;
  216. if (id && id > 0)
  217. url += "&PageID=" + id;
  218. if (that.data.Search)
  219. url += "&Key=" + that.data.Search;
  220. var orderType = that.data.OrderType;
  221. if (orderType)
  222. url += "&OrderType=" + orderType;
  223. main.getData(url, function (data) {
  224. if (data) {
  225. var list = app.globalData.CardList;
  226. for (var i = 0; i < data.List.length; i++) {
  227. list.push(data.List[i]);
  228. }
  229. app.globalData.CardList = list;
  230. that.getList();
  231. if (data.List.length < 20) {
  232. that.setData({
  233. HasPage: false,
  234. });
  235. }
  236. }
  237. });
  238. },
  239. addCard: function () {
  240. wx.redirectTo({
  241. url: './add?type=add&id=0',
  242. });
  243. },
  244. onSearch: function () {
  245. wx.navigateBack({
  246. delta: 1,
  247. });
  248. },
  249. onOrder: function (e) {
  250. var that = this;
  251. var value = e.currentTarget.dataset.value;
  252. for (var i = 0; i < this.data.ArrOrder.length; i++) {
  253. if (this.data.ArrOrder[i].Value == value)
  254. this.data.ArrOrder[i].CSS = "numberContainerFooter1121Select";
  255. else
  256. this.data.ArrOrder[i].CSS = "";
  257. }
  258. this.setData({
  259. IsOrder: false,
  260. ArrOrder: this.data.ArrOrder,
  261. OrderType: value,
  262. });
  263. if (!that.data.IsCollect && !that.data.IsToday) {
  264. app.globalData.CardList = [];
  265. that.gotoNextPage({ currentTarget: { dataset: { id: 0, OrderType: value } } });
  266. }
  267. },
  268. showOrder: function () {
  269. this.setData({
  270. IsOrder: true,
  271. });
  272. },
  273. closeOrder: function () {
  274. this.setData({
  275. IsOrder: false,
  276. });
  277. },
  278. DeleteItem: function (e) {
  279. var that = this;
  280. var id = e.currentTarget.dataset.id;
  281. var list = this.data.List;
  282. var b = true;
  283. for (var i = 0; i < list.length; i++) {
  284. var item = list[i];
  285. if (id == item.MiaoguoCardID) {
  286. if (item.DeleteStr == "删除") {
  287. item.ScrollLeft = 160;
  288. item.DeleteStr = "确认删除";
  289. }
  290. else if (item.DeleteStr == "确认删除") {
  291. b = false;
  292. item.DeleteStr = "删除";
  293. item.ScrollLeft = 0;
  294. var url = 'DeleteMiaoguoCard?UserID=' + app.globalData.userInfo.UserID;
  295. url += "&ID=" + id;
  296. main.getData(url, function (data) {
  297. var list = app.globalData.CardList;
  298. for (var i = 0; i < list.length; i++) {
  299. if (id == list[i].MiaoguoCardID) {
  300. list.splice(i, 1);
  301. break;
  302. }
  303. }
  304. app.globalData.CardList = list;
  305. that.setData({
  306. List: list,
  307. Count: --that.data.Count,
  308. });
  309. });
  310. }
  311. }
  312. else {
  313. item.DeleteStr = "删除";
  314. item.ScrollLeft = 0;
  315. }
  316. }
  317. if (b) {
  318. that.setData({
  319. List: list,
  320. });
  321. }
  322. },
  323. onShareAppMessage: function () {
  324. return {
  325. title: app.globalData.ShareTitle,
  326. path: app.globalData.SharePath + '?UserID=' + app.globalData.userInfo.UserID,
  327. imageUrl: app.globalData.ShareImage,
  328. }
  329. },
  330. })