list.js 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  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 > 24){
  72. fieldName="词";
  73. }
  74. }
  75. that.setData({
  76. ListType: listType,
  77. FieldName:fieldName,
  78. FieldName2:fieldName2,
  79. });
  80. if (that.data.BookID < 43 ||that.data.BookID > 44){
  81. arr = JSON.parse(arr);
  82. }
  83. var id = that.data.BookID;
  84. var testReportList = wx.getStorageSync("UserTestReport");
  85. for (var i = 0; i < arr.length; i++) {
  86. if (arr[i].ID == id) {
  87. var list = arr[i].Units;
  88. for (var j = 0; j < list.length; j++) {
  89. var str = "";
  90. for (var k = 0; k < list[j].Words.length; k++) {
  91. if (k < 27 && k < list[j].Words.length - 1)
  92. str += list[j].Words[k] + "、";
  93. else if (k == list[j].Words.length - 1)
  94. str += list[j].Words[k];
  95. else {
  96. str += list[j].Words[k] + "…";
  97. break;
  98. }
  99. }
  100. list[j].WordList = str;
  101. list[j].TestTypeReadFinished = true;
  102. list[j].TestTypeWriteFinished = true;
  103. for (var k = 0; k < testReportList.length; k++) {
  104. if (testReportList[k].Name[0] == that.data.Name1 &&
  105. testReportList[k].Name[1] == list[j].Name) {
  106. var testRightCount = 0;
  107. if (testReportList[k].TestRightStr)
  108. testRightCount = testReportList[k].TestRightStr.length;
  109. var testWrongCount = 0;
  110. if (testReportList[k].testWrongStr)
  111. testWrongCount = testReportList[k].testWrongStr.length;
  112. var testSkipCount = 0;
  113. if (testReportList[k].TestSkipStr)
  114. testSkipCount = testReportList[k].TestSkipStr.length;
  115. if (testReportList[k].TestType == "read") {
  116. if (testReportList[k].IsFinished == 1)
  117. list[j].TestTypeRead = 1;
  118. if ((testRightCount + testWrongCount + testSkipCount) < testReportList[k].TestTotal) {
  119. list[j].TestTypeReadFinished = false;
  120. }
  121. list[j].ReadReportID = testReportList[k].ID;
  122. }
  123. if (testReportList[k].TestType == "write") {
  124. if (testReportList[k].IsFinished == 1)
  125. list[j].TestTypeWrite = 1;
  126. if ((testRightCount + testWrongCount + testSkipCount) < testReportList[k].TestTotal) {
  127. list[j].TestTypeWriteFinished = false;
  128. }
  129. list[j].WriteReportID = testReportList[k].ID;
  130. }
  131. }
  132. }
  133. }
  134. console.log("List:"+list.length);
  135. that.setData({
  136. List: list,
  137. UnitsID: id,
  138. });
  139. }
  140. }
  141. },
  142. onShowFrame: function (e) {
  143. var selectItem;
  144. var id = e.currentTarget.dataset.id;
  145. for (var i = 0; i < this.data.List.length; i++) {
  146. if (id == this.data.List[i].ID) {
  147. selectItem = this.data.List[i];
  148. }
  149. }
  150. this.setData({
  151. IsSelect: true,
  152. SelectItem: selectItem,
  153. });
  154. },
  155. onClose: function () {
  156. this.setData({
  157. IsSelect: false,
  158. });
  159. },
  160. goto: function (e) {
  161. var url = e.currentTarget.dataset.url;
  162. wx.navigateTo({
  163. url: url,
  164. });
  165. this.onClose();
  166. },
  167. gotoTestReportInfo: function (e) {
  168. var that = this;
  169. if (isClick) {
  170. isClick = false;
  171. setTimeout(function () {
  172. isClick = true;
  173. }, 2000);
  174. var id = e.currentTarget.dataset.id;
  175. var userid = app.globalData.userInfo.UserID;
  176. if (id) {
  177. var reporttype = e.currentTarget.dataset.type;
  178. if (reporttype=="restart"){
  179. //main.getData('RestartTestReport?ID='+id+'&UserID=' + app.globalData.userInfo.UserID, function (data) {});
  180. var testReportList = wx.getStorageSync("UserTestReport");
  181. for(var i=0;i<testReportList.length;i++){
  182. if (id==testReportList[i].ID){
  183. testReportList[i].TestRightStr="";
  184. testReportList[i].TestWrongStr="";
  185. testReportList[i].TestSkipStr="";
  186. testReportList[i].TestExistStr="";
  187. break;
  188. }
  189. }
  190. wx.setStorageSync("UserTestReport", testReportList);
  191. }
  192. main.GetTestReportInfo(id, function (data) {
  193. data.BookID=that.data.BookID;
  194. wx.setStorageSync("TestTask2", data);
  195. that.onClose();
  196. var url="./item?type=" + reporttype+"&bookid="+that.data.BookID;
  197. var testtype=e.currentTarget.dataset.testtype;
  198. if (testtype)
  199. url+="&testtype="+testtype;
  200. wx.navigateTo({
  201. url: url,
  202. });
  203. });
  204. } else {
  205. that.onClose();
  206. var url = e.currentTarget.dataset.url+"&bookid="+that.data.BookID;
  207. wx.navigateTo({
  208. url: url,
  209. });
  210. }
  211. }
  212. },
  213. onShareAppMessage: function () {
  214. return {
  215. title: app.globalData.ShareTitle,
  216. path: app.globalData.SharePath + '?UserID=' + app.globalData.userInfo.UserID,
  217. imageUrl: app.globalData.ShareImage,
  218. }
  219. },
  220. })