unit.js 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. import common from '../../utils/util';
  2. import main from '../../utils/main';
  3. const app = getApp();
  4. var bookID=0;
  5. Page({
  6. data: {
  7. Menu:0,
  8. TestArr:[],
  9. },
  10. onLoad: function (options) {
  11. var that = this;
  12. bookID=options.BookID;
  13. that.setData({
  14. Containnerheight: main.getWindowHeight(),
  15. ImagePath: app.globalData.uploadImageUrl,
  16. BookID:bookID,
  17. });
  18. //that.init();
  19. },
  20. onShow:function(){
  21. var that = this;
  22. that.init();
  23. },
  24. init:function(){
  25. var that = this;
  26. main.getData('GetMiaoguoTestUnit?BookID='+bookID+'&UserID='+app.globalData.userInfo.UserID, function (data) {
  27. if (data) {
  28. that.setData({
  29. Category:data.BookInfo.Category,
  30. LibraryName1:data.BookInfo.LibraryName1,
  31. LibraryName2:data.BookInfo.LibraryName2,
  32. WordType:data.BookInfo.WordType,
  33. WordNum:data.BookInfo.WordNum,
  34. BookName:data.BookInfo.BookName,
  35. KnowledgeImageName:data.BookInfo.KnowledgeImageName,
  36. });
  37. var readNum=0,writeNum=0,readRate=0,writeRate=0;
  38. var list1=data.List1;
  39. for(var i=0;i<list1.length;i++){
  40. if (list1[i].IsTestRead || list1[i].IsBuildRead)
  41. readNum++;
  42. if (list1[i].IsTestWrite || list1[i].IsBuildWrite)
  43. writeNum++;
  44. if (!list1[i].List)
  45. list1[i].List=list1[i].ListStr.split("、");
  46. }
  47. that.setData({
  48. List:list1,
  49. TestArr:data.List2,
  50. ReadNum:readNum,
  51. ReadRate:Math.round(100*readNum/list1.length),
  52. WriteNum:writeNum,
  53. WriteRate:Math.round(100*writeNum/list1.length),
  54. });
  55. }
  56. });
  57. if (options.Name1=="写字" || options.Name1=="识字" || options.Name1=="词语"){
  58. var date=new Date();
  59. var today=common.formatDateCHS(common.formatTime(date,"-",true));
  60. var date0=(date.getFullYear()-1).toString()+"年09月";
  61. var date1=date.getFullYear()+"年03月";
  62. var date2=date.getFullYear()+"年09月";
  63. var updateTime=date0;
  64. if (today>=date1)
  65. updateTime=date1;
  66. if (today>=date2)
  67. updateTime=date2;
  68. that.setData({
  69. UpdateTime:updateTime,
  70. });
  71. }
  72. },
  73. setMenu:function(e){
  74. var that=this;
  75. var menu=e.currentTarget.dataset.menu;
  76. that.setData({
  77. Menu:menu,
  78. });
  79. },
  80. setMenu2:function(e){
  81. var that=this;
  82. var menu=e.currentTarget.dataset.menu;
  83. var index=e.currentTarget.dataset.index;
  84. var item=that.data.List[index];
  85. if (item && (!item.List || item.ListStr=="")){
  86. main.getData('GetMiaoguoTestExamine?UserID='+app.globalData.userInfo.UserID+'&Category1='+that.data.Category1+'&BookID='+that.data.BookID+'&Name='+that.data.Name2+'&UnitID='+item.ID+'&TestType=read', function (data) {
  87. if (data) {
  88. item.List=[];
  89. for(var i=0;i<data.length;i++){
  90. item.List.push(data[i].Word);
  91. }
  92. that.setData({
  93. Menu2:menu,
  94. SelectedItem:item,
  95. });
  96. }
  97. });
  98. }
  99. else{
  100. if (item){
  101. var TestItemArr=[{
  102. ID:0,
  103. Icon:"sysIcon_d01",
  104. TestTime:"未检验",
  105. RightNum:0,
  106. WrongNum:0,
  107. }, {
  108. ID:0,
  109. Icon:"sysIcon_d02",
  110. TestTime:"未检验",
  111. RightNum:0,
  112. WrongNum:0,
  113. }];
  114. var list=that.data.TestArr;
  115. for(var i=0;i<list.length;i++){
  116. if (list[i].UnitName==item.UnitName){
  117. var id=0;
  118. if (list[i].IsTestWrite){
  119. id=1;
  120. }
  121. TestItemArr[id].ID=list[i].ID;
  122. TestItemArr[id].RightNum=list[i].RightNum;
  123. TestItemArr[id].WrongNum=list[i].WrongNum;
  124. TestItemArr[id].TestTime=list[i].TestTime;
  125. }
  126. }
  127. item.TestItemArr=TestItemArr;
  128. }
  129. that.setData({
  130. Menu2:menu,
  131. SelectedItem:item,
  132. });
  133. }
  134. },
  135. goto: function (e) {
  136. var url = e.currentTarget.dataset.url;
  137. wx.navigateTo({
  138. url: url,
  139. });
  140. this.setData({
  141. Menu2:0,
  142. });
  143. },
  144. onShareAppMessage: function () {
  145. return {
  146. title: app.globalData.ShareTitle,
  147. path: app.globalData.SharePath + '?UserID=' + app.globalData.userInfo.UserID,
  148. imageUrl: app.globalData.ShareImage,
  149. }
  150. },
  151. })