searchCardList.js 10 KB

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