searchCardList.js 12 KB

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