searchCardList.js 10 KB

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