list.js 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322
  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 > 177){
  45. arr = wx.getStorageSync("CET6EngList");
  46. listType="english";
  47. }
  48. else if (that.data.BookID > 172){
  49. arr = wx.getStorageSync("CET4EngList");
  50. listType="english";
  51. }
  52. else if (that.data.BookID > 168){
  53. arr = wx.getStorageSync("NCEEEngList");
  54. listType="english";
  55. }
  56. else if (that.data.BookID > 164){
  57. arr = wx.getStorageSync("CEWEngList");
  58. listType="english";
  59. }
  60. else if (that.data.BookID > 160){
  61. arr = wx.getStorageSync("BEWEngList");
  62. listType="english";
  63. }
  64. else if (that.data.BookID > 150){
  65. arr = wx.getStorageSync("MiddleSchoolTestWords");
  66. listType="english";
  67. }
  68. else if (that.data.BookID > 140){
  69. arr = wx.getStorageSync("EEWEngList");
  70. listType="english";
  71. }
  72. else if (that.data.BookID > 130){
  73. arr = wx.getStorageSync("CambridgeEngList");
  74. listType="english";
  75. if (that.data.BookID==135)
  76. fieldName="词组";
  77. }
  78. else if (that.data.BookID > 120){
  79. arr = wx.getStorageSync("NewConceptEngList");
  80. listType="english";
  81. }
  82. else if (that.data.BookID > 110){
  83. arr = wx.getStorageSync("EnglishAll");
  84. listType="english";
  85. }
  86. else if (that.data.BookID > 100){
  87. arr = wx.getStorageSync("PhoneticEngList");
  88. fieldName="音标";
  89. fieldName2="";
  90. listType="english";
  91. }
  92. else if (that.data.BookID >= 43 && that.data.BookID <= 44){
  93. arr = constant.arrPinyinList;
  94. fieldName="拼音";
  95. fieldName2="";
  96. listType="音";
  97. }
  98. else{
  99. arr = wx.getStorageSync("HanziAll");
  100. fieldName="汉字";
  101. fieldName2="";
  102. if (that.data.BookID == 73){
  103. fieldName="含义";
  104. listType="Wenyanwen";
  105. }
  106. else if (that.data.BookID == 86){
  107. fieldName="句子";
  108. listType="Guwen";
  109. }
  110. else if (that.data.BookID >= 45 && that.data.BookID <= 60){
  111. fieldName="词语";
  112. }
  113. }
  114. that.setData({
  115. ListType: listType,
  116. FieldName:fieldName,
  117. FieldName2:fieldName2,
  118. });
  119. if (that.data.BookID < 43 ||that.data.BookID > 44){
  120. arr = JSON.parse(arr);
  121. }
  122. var id = that.data.BookID;
  123. var testReportList = wx.getStorageSync("UserTestReport");
  124. for (var i = 0; i < arr.length; i++) {
  125. if (arr[i].ID == id) {
  126. var list = arr[i].Units;
  127. for (var j = 0; j < list.length; j++) {
  128. var str = "";
  129. for (var k = 0; k < list[j].Words.length; k++) {
  130. if (k < 27 && k < list[j].Words.length - 1){
  131. if (that.data.BookID==73)
  132. str += list[j].Words[k] + " ";
  133. else
  134. str += list[j].Words[k] + "、";
  135. }
  136. else if (k == list[j].Words.length - 1)
  137. str += list[j].Words[k];
  138. else {
  139. str += list[j].Words[k] + "…";
  140. break;
  141. }
  142. }
  143. list[j].WordList = str;
  144. list[j].TestTypeReadFinished = true;
  145. list[j].TestTypeWriteFinished = true;
  146. for (var k = 0; k < testReportList.length; k++) {
  147. if (testReportList[k].Name[0] == that.data.Name1 &&
  148. testReportList[k].Name[1] == list[j].Name) {
  149. var testRightCount = 0;
  150. if (testReportList[k].TestRightStr){
  151. testRightCount = testReportList[k].TestRightStr.length;
  152. if (id==73 && testReportList[k].TestRightStr.length>0){
  153. testRightCount=testReportList[k].TestRightStr.toString().split(",").length;
  154. }
  155. }
  156. var testWrongCount = 0;
  157. if (testReportList[k].TestWrongStr){
  158. testWrongCount = testReportList[k].TestWrongStr.length;
  159. if (id==73 && testReportList[k].TestWrongStr.length>0){
  160. var arrTemp=testReportList[k].TestWrongStr.toString().split(",");
  161. testWrongCount=arrTemp.length;
  162. }
  163. }
  164. var testSkipCount = 0;
  165. if (testReportList[k].TestSkipStr){
  166. testSkipCount = testReportList[k].TestSkipStr.length;
  167. if (id==73 && testReportList[k].TestSkipStr.length>0){
  168. testSkipCount=testReportList[k].TestSkipStr.toString().split(",").length;
  169. }
  170. }
  171. if (testReportList[k].TestType == "read") {
  172. if (testReportList[k].IsFinished == 1)
  173. list[j].TestTypeRead = 1;
  174. if ((testRightCount + testWrongCount + testSkipCount) < testReportList[k].TestTotal) {
  175. list[j].TestTypeReadFinished = false;
  176. }
  177. list[j].ReadReportID = testReportList[k].ID;
  178. }
  179. if (testReportList[k].TestType == "write") {
  180. if (testReportList[k].IsFinished == 1)
  181. list[j].TestTypeWrite = 1;
  182. if ((testRightCount + testWrongCount + testSkipCount) < testReportList[k].TestTotal) {
  183. list[j].TestTypeWriteFinished = false;
  184. }
  185. list[j].WriteReportID = testReportList[k].ID;
  186. }
  187. }
  188. }
  189. }
  190. //console.log("List:"+list.length);
  191. that.setData({
  192. List: list,
  193. UnitsID: id,
  194. });
  195. }
  196. }
  197. },
  198. onShowFrame: function (e) {
  199. var selectItem;
  200. var id = e.currentTarget.dataset.id;
  201. for (var i = 0; i < this.data.List.length; i++) {
  202. if (id == this.data.List[i].ID) {
  203. selectItem = this.data.List[i];
  204. }
  205. }
  206. this.setData({
  207. IsSelect: true,
  208. SelectItem: selectItem,
  209. });
  210. },
  211. onClose: function () {
  212. this.setData({
  213. IsSelect: false,
  214. });
  215. },
  216. goto: function (e) {
  217. var url = e.currentTarget.dataset.url;
  218. wx.navigateTo({
  219. url: url,
  220. });
  221. this.onClose();
  222. },
  223. gotoTestReportInfo: function (e) {
  224. var that = this;
  225. if (isClick) {
  226. isClick = false;
  227. setTimeout(function () {
  228. isClick = true;
  229. }, 2000);
  230. var id = e.currentTarget.dataset.id;
  231. var userid = app.globalData.userInfo.UserID;
  232. if (id) {
  233. var reporttype = e.currentTarget.dataset.type;
  234. var testtype=e.currentTarget.dataset.testtype;
  235. if (reporttype=="restart"){
  236. var testReportList = wx.getStorageSync("UserTestReport");
  237. for(var i=0;i<testReportList.length;i++){
  238. if (id==testReportList[i].ID){
  239. testReportList[i].TestRightStr="";
  240. testReportList[i].TestWrongStr="";
  241. testReportList[i].TestSkipStr="";
  242. testReportList[i].TestExistStr="";
  243. testReportList[i].IsFinished=0;
  244. wx.setStorageSync("UserTestReport", testReportList);
  245. var param1 ={};
  246. param1.ID=id;
  247. param1.UserID=app.globalData.userInfo.UserID;
  248. param1.IsFinished=0;
  249. param1.TestRightStr="";
  250. param1.TestWrongStr="";
  251. param1.TestSkipStr="";
  252. param1.TestExistStr="";
  253. main.postData('InsertTestReport?UserID=' + param1.UserID, param1, function () {
  254. main.GetTestReportInfo(id, function (data) {
  255. data.BookID=that.data.BookID;
  256. wx.setStorageSync("TestTask2", data);
  257. that.onClose();
  258. var url="./item?type=" + reporttype+"&bookid="+that.data.BookID;
  259. if (testtype)
  260. url+="&testtype="+testtype;
  261. wx.navigateTo({
  262. url: url,
  263. });
  264. });
  265. });
  266. break;
  267. }
  268. }
  269. }
  270. else{
  271. main.GetTestReportInfo(id, function (data) {
  272. data.BookID=that.data.BookID;
  273. wx.setStorageSync("TestTask2", data);
  274. that.onClose();
  275. var url="./item?type=" + reporttype+"&bookid="+that.data.BookID;
  276. if (testtype)
  277. url+="&testtype="+testtype;
  278. wx.navigateTo({
  279. url: url,
  280. });
  281. });
  282. }
  283. } else {
  284. that.onClose();
  285. var url = e.currentTarget.dataset.url+"&bookid="+that.data.BookID;
  286. wx.navigateTo({
  287. url: url,
  288. });
  289. }
  290. }
  291. },
  292. onShareAppMessage: function () {
  293. return {
  294. title: app.globalData.ShareTitle,
  295. path: app.globalData.SharePath + '?UserID=' + app.globalData.userInfo.UserID,
  296. imageUrl: app.globalData.ShareImage,
  297. }
  298. },
  299. })