report.js 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307
  1. import common from '../../utils/util';
  2. import main from '../../utils/main';
  3. const app = getApp();
  4. Page({
  5. data: {
  6. WordList:[],
  7. TestTypeNumber:1,
  8. FolderID:0,
  9. MenuList:[{Name:"不分配(默认)",IsSelected:1},{Name:"分配到新卡单",IsSelected:0},{Name:"选择卡单",IsSelected:0,HasArrow:1}],
  10. },
  11. onLoad: function (options) {
  12. var that = this;
  13. that.setData({
  14. Containnerheight: main.getWindowHeight(),
  15. ImagePath: app.globalData.uploadImageUrl,
  16. List:[
  17. {Name:"答错的",List:[],BColor:"#F26D5F",IsShow:1},
  18. {Name:"不会的",List:[],BColor:"#787878",IsShow:1},
  19. {Name:"答对的",List:[],BColor:"#51BE3D",IsShow:1},
  20. ]
  21. });
  22. if (options.ID){
  23. that.getReportID(options.ID,function(data){
  24. app.globalData.TestTask=data;
  25. that.init();
  26. });
  27. }
  28. else{
  29. that.init();
  30. }
  31. },
  32. init: function () {
  33. var that = this;
  34. var TestTask = app.globalData.TestTask;
  35. var date=common.formatDateCHS(common.formatTime(new Date()),1);
  36. if (TestTask.ID)
  37. date=TestTask.TestTime;
  38. that.setData({
  39. LibraryName1:TestTask.LibraryName1,
  40. LibraryName2:TestTask.LibraryName2,
  41. BookID:TestTask.BookID,
  42. BookName:TestTask.BookName,
  43. UnitID:TestTask.UnitID,
  44. UnitName:TestTask.UnitName,
  45. TestType:TestTask.TestType,
  46. TestTypeName:TestTask.TestTypeName,
  47. ReportType:TestTask.ReportType,
  48. TestTime:date,
  49. });
  50. if (!TestTask)
  51. TestTask={};
  52. var TestTypeNumber=1;
  53. if (TestTask.TestType=="read")
  54. TestTypeNumber=2;
  55. var list = TestTask.List;
  56. if (list) {
  57. if (!TestTask.ID && TestTask.ReportType!="build"){
  58. that.data.WordList=[];
  59. for (var i = 0; i < list.length; i++) {
  60. var item={};
  61. item.Word=list[i].Word;
  62. if (list[i].Result == -1) {
  63. item.IsSelected=1;
  64. that.data.List[0].List.push(item);
  65. that.data.WordList.push(item.Word);
  66. } else if (list[i].Result == 0) {
  67. item.IsSelected=1;
  68. that.data.List[1].List.push(item);
  69. that.data.WordList.push(item.Word);
  70. } else if (list[i].Result == 1) {
  71. item.IsSelected=0;
  72. that.data.List[2].List.push(item);
  73. }
  74. }
  75. that.setData({
  76. WordList: that.data.WordList,
  77. });
  78. }
  79. else if (TestTask.ReportType=="build"){
  80. for(var i=0;i<that.data.List.length;i++){
  81. that.data.List[i].List=list[i];
  82. if (i==0 || i==2)
  83. that.data.List[i].IsShow=0;
  84. else
  85. that.data.List[i].Name="知识点";
  86. }
  87. that.setData({
  88. WordList:list[1],
  89. });
  90. }
  91. else
  92. that.data.List=list;
  93. that.setData({
  94. List:that.data.List,
  95. TestTypeNumber:TestTypeNumber,
  96. });
  97. if (TestTask.ReportType == "new")
  98. that.saveInfo();
  99. }
  100. },
  101. getReportID:function(id,callback){
  102. var that=this;
  103. main.getData('GetMiaoguoTestReportByID?ID='+id+'&UserID='+app.globalData.userInfo.UserID, function (data) {
  104. for(var i=0;i<that.data.List.length;i++){
  105. var arr=[];
  106. for(var j=0;j<data.List[i].length;j++){
  107. var obj={};
  108. obj.IsSelected=0;
  109. obj.Word=data.List[i][j];
  110. arr.push(obj);
  111. }
  112. that.data.List[i].List=arr;
  113. }
  114. data.List=that.data.List;
  115. callback(data);
  116. });
  117. },
  118. saveInfo:function(){
  119. var that=this;
  120. var userid=app.globalData.userInfo.UserID;
  121. var param1={};
  122. param1.BookID=that.data.BookID;
  123. param1.UnitID=that.data.UnitID;
  124. param1.UnitName=that.data.UnitName;
  125. param1.TestTypeName=that.data.TestTypeName;
  126. if (that.data.ReportType=="build"){
  127. if (that.data.TestType=="read")
  128. param1.IsBuildRead=1;
  129. else
  130. param1.IsBuildWrite=1;
  131. }
  132. else{
  133. if (that.data.TestType=="read")
  134. param1.IsTestRead=1;
  135. else
  136. param1.IsTestWrite=1;
  137. var arrAll=[];
  138. for(var i=0;i<that.data.List.length;i++){
  139. var arr=[];
  140. for(var j=0;j<that.data.List[i].List.length;j++){
  141. arr.push(that.data.List[i].List[j].Word);
  142. }
  143. arrAll.push(arr);
  144. }
  145. param1.JSONData=JSON.stringify(arrAll);
  146. }
  147. //debugger;
  148. main.postData('InsertTestReport2?UserID=' + userid, param1, function (data) {});
  149. },
  150. selectItem:function(e){
  151. var that=this;
  152. var index=e.currentTarget.dataset.index;
  153. var index2=e.currentTarget.dataset.index2;
  154. var list=that.data.List;
  155. that.data.WordList=[];
  156. for(var i=0;i<list.length;i++){
  157. if (index==i){
  158. for(var j=0;j<list[i].List.length;j++){
  159. if (index2==j){
  160. list[i].List[j].IsSelected=!list[i].List[j].IsSelected?1:0;
  161. }
  162. else if (index2=="all"){
  163. list[i].List[j].IsSelected=1;
  164. }
  165. else if (index2=="none"){
  166. list[i].List[j].IsSelected=0;
  167. }
  168. }
  169. }
  170. for(var j=0;j<list[i].List.length;j++){
  171. if (list[i].List[j].IsSelected==1)
  172. that.data.WordList.push(list[i].List[j]);
  173. }
  174. }
  175. that.setData({
  176. List:that.data.List,
  177. WordList:that.data.WordList,
  178. });
  179. },
  180. setMenu:function(e){
  181. var that=this;
  182. var index=e.currentTarget.dataset.index;
  183. if (index==1 && that.data.WordList.length==0){
  184. wx.showToast({
  185. title: '请选择题卡',
  186. });
  187. }
  188. else{
  189. that.setData({
  190. Menu:index,
  191. });
  192. }
  193. },
  194. setMenu2:function(e){
  195. var that=this;
  196. var index=e.currentTarget.dataset.index;
  197. var list=that.data.MenuList;
  198. for(var i=0;i<list.length;i++){
  199. list[i].IsSelected=0;
  200. if (index==i)
  201. list[i].IsSelected=1;
  202. }
  203. if (index==0){
  204. list[2].Name="选择卡单";
  205. that.data.FolderID=0;
  206. }
  207. else if (index==1){
  208. list[2].Name="选择卡单";
  209. that.data.FolderID=-1;//-1表示要生成一个新卡单
  210. }
  211. that.setData({
  212. MenuList:that.data.MenuList,
  213. FolderID:that.data.FolderID,
  214. });
  215. if (index==2){
  216. that.getFolder();
  217. }
  218. },
  219. getFolder:function(){
  220. var that=this;
  221. main.getData('GetUserFolderList?UserID='+app.globalData.userInfo.UserID, function (data) {
  222. that.setData({
  223. FolderList:data,
  224. Menu:2,
  225. });
  226. });
  227. },
  228. selectFolder:function(e){
  229. var that=this;
  230. var index=e.currentTarget.dataset.index;
  231. var list=that.data.MenuList;
  232. if (index==-1){
  233. list[0].IsSelected=1;
  234. list[2].IsSelected=0;
  235. list[2].Name="选择卡单";
  236. that.setData({
  237. FolderID:0,
  238. });
  239. }
  240. else{
  241. list[2].IsSelected=1;
  242. list[2].Name=that.data.FolderList[index].Name;
  243. that.setData({
  244. FolderID:that.data.FolderList[index].ID,
  245. });
  246. }
  247. that.setData({
  248. MenuList:that.data.MenuList,
  249. Menu:1,
  250. });
  251. },
  252. buildCard:function(e){
  253. var that=this;
  254. that.setData({
  255. Menu:0,
  256. });
  257. var param={};
  258. param.BookID=app.globalData.TestTask.BookID;
  259. param.UnitName=app.globalData.TestTask.UnitName;
  260. param.UnitID=app.globalData.TestTask.UnitID;
  261. param.TestType=app.globalData.TestTask.TestType;
  262. if(that.data.ReportType=="build"){
  263. param.WordList=[];
  264. for(var i=0;i<that.data.WordList.length;i++)
  265. param.WordList.push(that.data.WordList[i].Word);
  266. }
  267. else
  268. param.WordList=that.data.WordList;
  269. param.FolderID=that.data.FolderID;
  270. main.postData('BuildMiaoguoTestCard?UserID=' + app.globalData.userInfo.UserID, param, function (data) {
  271. });
  272. wx.navigateTo({
  273. url: "./build?Count="+that.data.WordList.length,
  274. });
  275. if(that.data.ReportType=="build")
  276. that.saveInfo();
  277. },
  278. closePanel:function(){
  279. wx.navigateBack({
  280. delta: 1,
  281. });
  282. },
  283. onShareAppMessage: function () {
  284. return {
  285. title: app.globalData.ShareTitle,
  286. path: app.globalData.SharePath + '?UserID=' + app.globalData.userInfo.UserID,
  287. imageUrl: app.globalData.ShareImage,
  288. }
  289. },
  290. })