list.js 9.4 KB

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