searchCardList.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455
  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.PrintID){
  106. that.getPrintList();
  107. }
  108. else{
  109. if (!that.data.IsCollect && !that.data.IsToday) {
  110. app.globalData.CardList = [];
  111. that.gotoNextPage({ currentTarget: { dataset: { id: 0 } } });
  112. }
  113. }
  114. wx.stopPullDownRefresh();
  115. },
  116. getList: function () {
  117. var that = this;
  118. var list = app.globalData.CardList;
  119. var len = 16;
  120. for (var i = 0; i < list.length; i++) {
  121. var item = list[i];
  122. item.ScrollLeft = 0;
  123. item.DeleteStr = "删除";
  124. item.Content[1].ContentStr = replaceString(item.Content[1].Content);
  125. if (item.Content[1].ContentStr.length > len)
  126. item.Content[1].ContentStr = replaceString(item.Content[1].ContentStr.substr(0, len)) + "...";
  127. item.Content[2].ContentStr = replaceString(item.Content[2].Content);
  128. if (item.Content[2].ContentStr.length > len)
  129. item.Content[2].ContentStr = replaceString(item.Content[2].ContentStr.substr(0, len)) + "...";
  130. var imageUrl = getImage(item.Content[1].Content);
  131. if (imageUrl.length == 0 && item.Content[2].Content)
  132. imageUrl = getImage(item.Content[2].Content);
  133. if (imageUrl.length == 0 && item.Content[3].Content)
  134. imageUrl = getImage(item.Content[3].Content);
  135. if (imageUrl.length > 0) {
  136. item.ImageUrlTemp = main.getTempImage(imageUrl);
  137. item.ImageUrlServer = imageUrl;
  138. }
  139. }
  140. if (!that.data.IsToday && !that.data.PrintID && !that.data.Search) {
  141. main.getData("GetUserCardCount?UserID=" + app.globalData.userInfo.UserID+"&CardType="+that.data.CardType+"&IsCollect="+that.data.IsCollect, function (data) {
  142. if (data) {
  143. that.setData({
  144. Count: data.CardNumber,
  145. });
  146. var hasPage = false;
  147. if (list.length < that.data.Count && list.length>=20 && that.data.IsToday == 0)
  148. hasPage = true;
  149. that.setData({
  150. List: list,
  151. HasPage: hasPage,
  152. });
  153. if (that.data.PageType === "3") {
  154. wx.redirectTo({
  155. url: './preview?type=show&id=' + list[0].MiaoguoCardID,
  156. })
  157. }
  158. }
  159. });
  160. }
  161. else if (that.data.Search) {
  162. that.setData({
  163. List: list,
  164. Count: list.length,
  165. HasPage: true,
  166. });
  167. }
  168. else {
  169. that.setData({
  170. Count: list.length,
  171. });
  172. var hasPage = false;
  173. if (list.length < that.data.Count && that.data.IsToday == 0)
  174. hasPage = true;
  175. that.setData({
  176. List: list,
  177. HasPage: hasPage,
  178. });
  179. }
  180. wx.hideLoading();
  181. function getImage(str) {
  182. var result = "";
  183. if (str.indexOf("[图") >= 0) {
  184. result = str.substring(str.indexOf("[图") + 3, str.indexOf("[/图]"));
  185. result = result.substring(result.indexOf("]") + 1);
  186. }
  187. //console.log(result);
  188. return result;
  189. }
  190. function replaceString(str) {
  191. //str = str.replace(/\[图]/g, "");
  192. //str = str.replace(/\[\/图\]/g, "");
  193. var 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. if (str.indexOf("[读 src=") >= 0) {
  200. str2 = str.substr(str.indexOf("[读 src"));
  201. str2 = str2.substring(0, str2.indexOf("/读]") + 3);
  202. }
  203. str = str.replace(str2, "");
  204. str = str.replace(/\[读]/g, "");
  205. str = str.replace(/\[\/读\]/g, "");
  206. var 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. if (str.indexOf("[图") >= 0) {
  213. str3 = str.substr(str.indexOf("[图"));
  214. str3 = str3.substring(0, str3.indexOf("/图]") + 3);
  215. }
  216. str = str.replace(str3, "");
  217. str = str.replace(/\[线]/g, "");
  218. str = str.replace(/\[\/线\]/g, "");
  219. str = main.encryptUrl(str);
  220. return str;
  221. }
  222. },
  223. onPreview: function (e) {
  224. var id = e.currentTarget.dataset.id;
  225. wx.navigateTo({
  226. url: './preview?type=show&id=' + id,
  227. })
  228. },
  229. playPPT: function () {
  230. wx.navigateTo({
  231. url: './preview?type=play',
  232. })
  233. },
  234. onBindError: function (e) {
  235. var that = this;
  236. var id = e.currentTarget.dataset.id;
  237. var serverUrl = e.currentTarget.dataset.serverurl;
  238. wx.downloadFile({
  239. url: serverUrl, // 仅为示例,并非真实的资源
  240. success(res) {
  241. if (res.statusCode === 200) {
  242. main.saveTempImage(serverUrl, res.tempFilePath);
  243. }
  244. }
  245. });
  246. // clearTimeout(intervalRefresh);
  247. // intervalRefresh = setTimeout(function () {
  248. // that.getList();
  249. // }, 1000);
  250. },
  251. gotoNextPage: function (e) {
  252. wx.showLoading({
  253. title: '请稍候',
  254. });
  255. setTimeout(function () {
  256. wx.hideLoading();
  257. }, 5000);
  258. var that = this;
  259. var url = 'GetMiaoguoCardList2?UserID=' + app.globalData.userInfo.UserID;
  260. var id = e.currentTarget.dataset.id;
  261. if (id && id > 0)
  262. url += "&PageID=" + id;
  263. if (that.data.CardType)
  264. url += "&CardType=" + that.data.CardType;
  265. if (that.data.Search)
  266. url += "&Key=" + that.data.Search;
  267. var orderType = that.data.OrderType;
  268. if (orderType)
  269. url += "&OrderType=" + arrOrder[orderType].Value;
  270. if (e.currentTarget.dataset.iscollect==1)
  271. url += "&IsCollect=1";
  272. main.getData(url, function (data) {
  273. if (data) {
  274. var list = app.globalData.CardList;
  275. for (var i = 0; i < data.List.length; i++) {
  276. data.List[i].LastTimeStr = common.formatDateCHS(data.List[i].LastTime);
  277. list.push(data.List[i]);
  278. }
  279. app.globalData.CardList = list;
  280. that.getList();
  281. if (data.List.length < 20) {
  282. that.setData({
  283. HasPage: false,
  284. });
  285. }
  286. if (orderType > 0) {
  287. wx.setNavigationBarTitle({
  288. title: "全部题卡:" + arrOrder[orderType].Name,
  289. });
  290. }
  291. }
  292. });
  293. },
  294. getPrintList: function (e) {
  295. wx.showLoading({
  296. title: '请稍候',
  297. });
  298. setTimeout(function () {
  299. wx.hideLoading();
  300. }, 5000);
  301. var that = this;
  302. var url = 'GetMiaoguoCardList2?UserID=' + app.globalData.userInfo.UserID+'&PrintID='+that.data.PrintID;
  303. main.getData(url, function (data) {
  304. if (data) {
  305. if (data.List.length>0){
  306. var list=[];
  307. for (var i = 0; i < data.List.length; i++) {
  308. data.List[i].Number = i+1;
  309. list.push(data.List[i]);
  310. }
  311. app.globalData.CardList = list;
  312. that.getList();
  313. wx.setNavigationBarColor({
  314. frontColor: "#000000",
  315. backgroundColor: "#ffffff",
  316. });
  317. }
  318. else{
  319. that.onSearch();
  320. }
  321. }
  322. });
  323. },
  324. addCard: function () {
  325. wx.redirectTo({
  326. url: './add?type=add&id=0',
  327. });
  328. },
  329. onSearch: function () {
  330. wx.navigateBack({
  331. delta: 1,
  332. });
  333. },
  334. onOrder: function (e) {
  335. var that = this;
  336. var value = e.currentTarget.dataset.value;
  337. for (var i = 0; i < this.data.ArrOrder.length; i++) {
  338. if (i == value)
  339. this.data.ArrOrder[i].CSS = "numberContainerFooter1121Select";
  340. else
  341. this.data.ArrOrder[i].CSS = "";
  342. }
  343. this.setData({
  344. IsOrder: false,
  345. ArrOrder: this.data.ArrOrder,
  346. OrderType: value,
  347. });
  348. if (!that.data.IsCollect && !that.data.IsToday) {
  349. app.globalData.CardList = [];
  350. that.gotoNextPage({ currentTarget: { dataset: { id: 0, OrderType: value } } });
  351. }
  352. },
  353. showOrder: function () {
  354. this.setData({
  355. IsOrder: true,
  356. });
  357. },
  358. closeOrder: function () {
  359. this.setData({
  360. IsOrder: false,
  361. });
  362. },
  363. DeleteItem: function (e) {
  364. var that = this;
  365. var id = e.currentTarget.dataset.id;
  366. var list = this.data.List;
  367. var b = true;
  368. for (var i = 0; i < list.length; i++) {
  369. var item = list[i];
  370. if (id == item.MiaoguoCardID) {
  371. if (item.DeleteStr == "删除") {
  372. item.ScrollLeft = 160;
  373. item.DeleteStr = "确认删除";
  374. }
  375. else if (item.DeleteStr == "确认删除") {
  376. b = false;
  377. item.DeleteStr = "删除";
  378. item.ScrollLeft = 0;
  379. var url = 'DeleteMiaoguoCard?UserID=' + app.globalData.userInfo.UserID;
  380. url += "&ID=" + id;
  381. main.getData(url, function (data) {
  382. var list = app.globalData.CardList;
  383. for (var i = 0; i < list.length; i++) {
  384. if (id == list[i].MiaoguoCardID) {
  385. list.splice(i, 1);
  386. break;
  387. }
  388. }
  389. app.globalData.CardList = list;
  390. that.setData({
  391. List: list,
  392. Count: --that.data.Count,
  393. });
  394. });
  395. }
  396. }
  397. else {
  398. item.DeleteStr = "删除";
  399. item.ScrollLeft = 0;
  400. }
  401. }
  402. if (b) {
  403. that.setData({
  404. List: list,
  405. });
  406. }
  407. },
  408. onShareAppMessage: function () {
  409. return {
  410. title: app.globalData.ShareTitle,
  411. path: app.globalData.SharePath + '?UserID=' + app.globalData.userInfo.UserID,
  412. imageUrl: app.globalData.ShareImage,
  413. }
  414. },
  415. })