searchCardList.js 10 KB

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