searchCardList.js 9.9 KB

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