list.js 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. import common from '../../utils/util';
  2. import main from '../../utils/main';
  3. const app = getApp();
  4. var isClick = true;
  5. Page({
  6. data: {
  7. IsSelect: false,
  8. ImagePath: app.globalData.uploadImageUrl,
  9. },
  10. onLoad: function(options) {
  11. var that = this;
  12. that.setData({
  13. BookID:options.id,
  14. Containnerheight: main.getWindowHeight(),
  15. Name1: options.name1,
  16. });
  17. isClick = true;
  18. main.getHanzi(function(arr) {
  19. if (!arr) {
  20. wx.removeStorageSync("HanziUpdateTime");
  21. wx.removeStorageSync("HanziAll");
  22. main.getHanzi(function(arr) {
  23. that.init(options);
  24. });
  25. } else {
  26. that.init(options);
  27. }
  28. });
  29. },
  30. init: function(options) {
  31. var that = this;
  32. var name = options.name1;
  33. if (name.indexOf(" ") > 0)
  34. name = name.substr(name.indexOf(" ") + 1);
  35. wx.setNavigationBarTitle({
  36. title: name
  37. });
  38. var arr = [];
  39. if (that.data.BookID==13 || that.data.BookID==14 || that.data.BookID==15)
  40. arr = wx.getStorageSync("EnglishAll");
  41. else if (that.data.BookID<=12)
  42. arr = wx.getStorageSync("HanziAll");
  43. var testReportList = wx.getStorageSync("UserTestReport");
  44. arr = JSON.parse(arr);
  45. var id = Number(options.id);
  46. for (var i = 0; i < arr.length; i++) {
  47. if (arr[i].ID == id) {
  48. var list = arr[i].Units;
  49. for (var j = 0; j < list.length; j++) {
  50. var str = "";
  51. for (var k = 0; k < list[j].Words.length; k++) {
  52. if (k < 27 && k < list[j].Words.length - 1)
  53. str += list[j].Words[k].Name + "、";
  54. else if (k == list[j].Words.length - 1)
  55. str += list[j].Words[k].Name;
  56. else {
  57. str += list[j].Words[k].Name + "…";
  58. break;
  59. }
  60. }
  61. list[j].WordList = str;
  62. list[j].TestTypeReadFinished = true;
  63. list[j].TestTypeWriteFinished = true;
  64. for (var k = 0; k < testReportList.length; k++) {
  65. if (testReportList[k].Name[0] == options.name1 &&
  66. testReportList[k].Name[1] == list[j].Name) {
  67. if (testReportList[k].TestType == "read") {
  68. if (testReportList[k].IsFinished == 1)
  69. list[j].TestTypeRead = 1;
  70. if ((testReportList[k].TestRight + testReportList[k].TestWrong + testReportList[k].TestSkip) < testReportList[k].TestTotal) {
  71. list[j].TestTypeReadFinished = false;
  72. }
  73. list[j].ReadReportID = testReportList[k].ID;
  74. }
  75. if (testReportList[k].TestType == "write") {
  76. if (testReportList[k].IsFinished == 1)
  77. list[j].TestTypeWrite = 1;
  78. if ((testReportList[k].TestRight + testReportList[k].TestWrong + testReportList[k].TestSkip) < testReportList[k].TestTotal) {
  79. list[j].TestTypeWriteFinished = false;
  80. }
  81. list[j].WriteReportID = testReportList[k].ID;
  82. }
  83. }
  84. }
  85. }
  86. that.setData({
  87. List: list,
  88. UnitsID: id,
  89. });
  90. }
  91. }
  92. },
  93. onShowFrame: function(e) {
  94. var selectItem;
  95. var id = e.currentTarget.dataset.id;
  96. for (var i = 0; i < this.data.List.length; i++) {
  97. if (id == this.data.List[i].ID) {
  98. selectItem = this.data.List[i];
  99. }
  100. }
  101. this.setData({
  102. IsSelect: true,
  103. SelectItem: selectItem,
  104. });
  105. },
  106. onClose: function() {
  107. this.setData({
  108. IsSelect: false,
  109. });
  110. },
  111. goto: function(e) {
  112. var url = e.currentTarget.dataset.url;
  113. wx.navigateTo({
  114. url: url,
  115. });
  116. this.onClose();
  117. },
  118. gotoTestReportInfo: function(e) {
  119. var that=this;
  120. if (isClick) {
  121. isClick=false;
  122. setTimeout(function(){
  123. isClick=true;
  124. },2000);
  125. var id = e.currentTarget.dataset.id;
  126. var userid = app.globalData.userInfo.UserID;
  127. if (id) {
  128. var reporttype = e.currentTarget.dataset.type;
  129. main.getData('GetTestReportInfo?UserID=' + userid + '&ID=' + id, function(data) {
  130. if (data) {
  131. wx.setStorageSync("TestTask2", data);
  132. that.onClose();
  133. wx.navigateTo({
  134. url: "./item?type=" + reporttype,
  135. });
  136. }
  137. });
  138. } else {
  139. that.onClose();
  140. var url = e.currentTarget.dataset.url;
  141. wx.navigateTo({
  142. url: url,
  143. });
  144. }
  145. }
  146. },
  147. onShareAppMessage: function() {
  148. return {
  149. title: app.globalData.ShareTitle,
  150. path: app.globalData.SharePath + '?UserID=' + app.globalData.userInfo.UserID,
  151. imageUrl: app.globalData.ShareImage,
  152. }
  153. },
  154. })