list.js 7.5 KB

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