searchCardList.js 10 KB

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