list.js 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273
  1. import common from '../../utils/util';
  2. import main from '../../utils/main';
  3. import constant from '../../utils/constant';
  4. const app = getApp();
  5. var isClick = true;
  6. var isStart = true;
  7. Page({
  8. data: {
  9. IsSelect: false,
  10. ImagePath: app.globalData.uploadImageUrl,
  11. },
  12. onLoad: function (options) {
  13. var that = this;
  14. that.setData({
  15. BookID: options.id,
  16. Containnerheight: main.getWindowHeight(),
  17. Name1: options.name1,
  18. });
  19. isClick = true;
  20. main.getHanzi(function () {
  21. main.getEnglish(function () {
  22. that.init();
  23. isStart=false;
  24. });
  25. });
  26. },
  27. onUnload:function(){
  28. isStart = true;
  29. },
  30. onShow:function(){
  31. if (!isStart)
  32. this.init();
  33. },
  34. init: function () {
  35. var that = this;
  36. var name = that.data.Name1;
  37. if (name.indexOf(" ") > 0)
  38. name = name.substr(name.indexOf(" ") + 1);
  39. if (that.data.BookID>="140" && that.data.BookID<="149"){
  40. name=name.replace("ESSENTIAL ENGLISH WORDS","4000 EEW");
  41. wx.setNavigationBarTitle({
  42. title: name
  43. });
  44. }
  45. else{
  46. wx.setNavigationBarTitle({
  47. title: name
  48. });
  49. }
  50. var arr = [];
  51. var listType="hanzi",fieldName="单词",fieldName2="说含义";
  52. if (that.data.BookID > 140){
  53. arr = wx.getStorageSync("EEWEngList");
  54. listType="english";
  55. }
  56. else if (that.data.BookID > 130){
  57. arr = wx.getStorageSync("CambridgeEngList");
  58. listType="english";
  59. }
  60. else if (that.data.BookID > 120){
  61. arr = wx.getStorageSync("NewConceptEngList");
  62. listType="english";
  63. }
  64. else if (that.data.BookID > 110){
  65. arr = wx.getStorageSync("EnglishAll");
  66. listType="english";
  67. }
  68. else if (that.data.BookID > 100){
  69. arr = wx.getStorageSync("PhoneticEngList");
  70. fieldName="音标";
  71. fieldName2="";
  72. listType="english";
  73. }
  74. else if (that.data.BookID >= 43 && that.data.BookID <= 44){
  75. arr = constant.arrPinyinList;
  76. fieldName="拼音";
  77. fieldName2="";
  78. listType="音";
  79. }
  80. else{
  81. arr = wx.getStorageSync("HanziAll");
  82. fieldName="字";
  83. if (that.data.BookID == 73){
  84. fieldName="释义";
  85. listType="wenyanwen";
  86. }
  87. else if (that.data.BookID > 24){
  88. fieldName="词";
  89. }
  90. }
  91. that.setData({
  92. ListType: listType,
  93. FieldName:fieldName,
  94. FieldName2:fieldName2,
  95. });
  96. if (that.data.BookID < 43 ||that.data.BookID > 44){
  97. arr = JSON.parse(arr);
  98. }
  99. var id = that.data.BookID;
  100. var testReportList = wx.getStorageSync("UserTestReport");
  101. for (var i = 0; i < arr.length; i++) {
  102. if (arr[i].ID == id) {
  103. var list = arr[i].Units;
  104. for (var j = 0; j < list.length; j++) {
  105. var str = "";
  106. for (var k = 0; k < list[j].Words.length; k++) {
  107. if (k < 27 && k < list[j].Words.length - 1){
  108. if (that.data.BookID==73)
  109. str += list[j].Words[k] + " ";
  110. else
  111. str += list[j].Words[k] + "、";
  112. }
  113. else if (k == list[j].Words.length - 1)
  114. str += list[j].Words[k];
  115. else {
  116. str += list[j].Words[k] + "…";
  117. break;
  118. }
  119. }
  120. list[j].WordList = str;
  121. list[j].TestTypeReadFinished = true;
  122. list[j].TestTypeWriteFinished = true;
  123. for (var k = 0; k < testReportList.length; k++) {
  124. if (testReportList[k].Name[0] == that.data.Name1 &&
  125. testReportList[k].Name[1] == list[j].Name) {
  126. var testRightCount = 0;
  127. if (testReportList[k].TestRightStr){
  128. testRightCount = testReportList[k].TestRightStr.length;
  129. if (id==73 && testReportList[k].TestRightStr.length>0){
  130. testRightCount=testReportList[k].TestRightStr.toString().split(",").length;
  131. }
  132. }
  133. var testWrongCount = 0;
  134. if (testReportList[k].TestWrongStr){
  135. testWrongCount = testReportList[k].TestWrongStr.length;
  136. if (id==73 && testReportList[k].TestWrongStr.length>0){
  137. var arrTemp=testReportList[k].TestWrongStr.toString().split(",");
  138. testWrongCount=arrTemp.length;
  139. }
  140. }
  141. var testSkipCount = 0;
  142. if (testReportList[k].TestSkipStr){
  143. testSkipCount = testReportList[k].TestSkipStr.length;
  144. if (id==73 && testReportList[k].TestSkipStr.length>0){
  145. testSkipCount=testReportList[k].TestSkipStr.toString().split(",").length;
  146. }
  147. }
  148. if (testReportList[k].TestType == "read") {
  149. if (testReportList[k].IsFinished == 1)
  150. list[j].TestTypeRead = 1;
  151. if ((testRightCount + testWrongCount + testSkipCount) < testReportList[k].TestTotal) {
  152. list[j].TestTypeReadFinished = false;
  153. }
  154. list[j].ReadReportID = testReportList[k].ID;
  155. }
  156. if (testReportList[k].TestType == "write") {
  157. if (testReportList[k].IsFinished == 1)
  158. list[j].TestTypeWrite = 1;
  159. if ((testRightCount + testWrongCount + testSkipCount) < testReportList[k].TestTotal) {
  160. list[j].TestTypeWriteFinished = false;
  161. }
  162. list[j].WriteReportID = testReportList[k].ID;
  163. }
  164. }
  165. }
  166. }
  167. console.log("List:"+list.length);
  168. that.setData({
  169. List: list,
  170. UnitsID: id,
  171. });
  172. }
  173. }
  174. },
  175. onShowFrame: function (e) {
  176. var selectItem;
  177. var id = e.currentTarget.dataset.id;
  178. for (var i = 0; i < this.data.List.length; i++) {
  179. if (id == this.data.List[i].ID) {
  180. selectItem = this.data.List[i];
  181. }
  182. }
  183. this.setData({
  184. IsSelect: true,
  185. SelectItem: selectItem,
  186. });
  187. },
  188. onClose: function () {
  189. this.setData({
  190. IsSelect: false,
  191. });
  192. },
  193. goto: function (e) {
  194. var url = e.currentTarget.dataset.url;
  195. wx.navigateTo({
  196. url: url,
  197. });
  198. this.onClose();
  199. },
  200. gotoTestReportInfo: function (e) {
  201. var that = this;
  202. if (isClick) {
  203. isClick = false;
  204. setTimeout(function () {
  205. isClick = true;
  206. }, 2000);
  207. var id = e.currentTarget.dataset.id;
  208. var userid = app.globalData.userInfo.UserID;
  209. if (id) {
  210. var reporttype = e.currentTarget.dataset.type;
  211. if (reporttype=="restart"){
  212. var testReportList = wx.getStorageSync("UserTestReport");
  213. for(var i=0;i<testReportList.length;i++){
  214. if (id==testReportList[i].ID){
  215. testReportList[i].TestRightStr="";
  216. testReportList[i].TestWrongStr="";
  217. testReportList[i].TestSkipStr="";
  218. testReportList[i].TestExistStr="";
  219. break;
  220. }
  221. }
  222. wx.setStorageSync("UserTestReport", testReportList);
  223. }
  224. main.GetTestReportInfo(id, function (data) {
  225. data.BookID=that.data.BookID;
  226. wx.setStorageSync("TestTask2", data);
  227. that.onClose();
  228. var url="./item?type=" + reporttype+"&bookid="+that.data.BookID;
  229. var testtype=e.currentTarget.dataset.testtype;
  230. if (testtype)
  231. url+="&testtype="+testtype;
  232. wx.navigateTo({
  233. url: url,
  234. });
  235. });
  236. } else {
  237. that.onClose();
  238. var url = e.currentTarget.dataset.url+"&bookid="+that.data.BookID;
  239. wx.navigateTo({
  240. url: url,
  241. });
  242. }
  243. }
  244. },
  245. onShareAppMessage: function () {
  246. return {
  247. title: app.globalData.ShareTitle,
  248. path: app.globalData.SharePath + '?UserID=' + app.globalData.userInfo.UserID,
  249. imageUrl: app.globalData.ShareImage,
  250. }
  251. },
  252. })