report.js 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333
  1. import common from '../../utils/util';
  2. import main from '../../utils/main';
  3. const app = getApp();
  4. var intervalBuild = 0;
  5. var TestReportID = 0;
  6. Page({
  7. data: {
  8. IsSelect: true,
  9. IsBuild: 0,
  10. IsIPhoneX: app.globalData.IsIPhoneX,
  11. },
  12. onLoad: function (options) {
  13. var that = this;
  14. that.setData({
  15. ReportType: options.type,
  16. Containnerheight: main.getWindowHeight(),
  17. });
  18. that.init();
  19. },
  20. init: function () {
  21. var that = this;
  22. TestReportID = 0;
  23. var TestTask = wx.getStorageSync("TestTask");
  24. if (!TestTask)
  25. TestTask={};
  26. var list = TestTask.List;
  27. var listRight = [];
  28. var listSkip = [];
  29. var listWrong = [];
  30. TestTask.TestRightStr = [];
  31. TestTask.TestWrongStr = [];
  32. TestTask.TestSkipStr = [];
  33. if (list) {
  34. for (var i = 0; i < list.length; i++) {
  35. // if (TestTask.BookID > 12) {
  36. // list[i].Field1 = list[i].ContentNew.Field[1][0].Content;
  37. // list[i].Word = list[i].ID;
  38. // }
  39. if (list[i].Result == 1) {
  40. listRight.push(list[i]);
  41. TestTask.TestRightStr.push(list[i].Word);
  42. } else if (list[i].Result == -1) {
  43. listWrong.push(list[i]);
  44. TestTask.TestWrongStr.push(list[i].Word);
  45. } else if (list[i].Result == 0) {
  46. listSkip.push(list[i]);
  47. TestTask.TestSkipStr.push(list[i].Word);
  48. }
  49. }
  50. var result = [];
  51. if (listWrong.length > 0) {
  52. result.push({
  53. Name: "答错的题目",
  54. Expand: 1,
  55. List: listWrong
  56. });
  57. if (listSkip.length > 0)
  58. result.push({
  59. Name: "没学过的题目",
  60. Expand: 1,
  61. List: listSkip
  62. });
  63. if (listRight.length > 0)
  64. result.push({
  65. Name: "答对的题目",
  66. Expand: 1,
  67. List: listRight
  68. });
  69. } else {
  70. if (listSkip.length > 0) {
  71. result.push({
  72. Name: "没学过的题目",
  73. Expand: 1,
  74. List: listSkip
  75. });
  76. if (listRight.length > 0)
  77. result.push({
  78. Name: "答对的题目",
  79. Expand: 1,
  80. List: listRight
  81. });
  82. } else {
  83. if (listRight.length > 0)
  84. result.push({
  85. Name: "答对的题目",
  86. Expand: 1,
  87. List: listRight
  88. });
  89. }
  90. }
  91. var name = "";
  92. if (TestTask.Name && TestTask.Name.indexOf("#") > 0) {
  93. name = TestTask.Name;
  94. name = name.substr(name.indexOf("#") + 1);
  95. if (name.indexOf("#")>0)
  96. name = name.substr(0,name.indexOf("#"));
  97. if (TestTask.TestType == "read")
  98. name += " 会念";
  99. else if (TestTask.TestType == "recite")
  100. name += " 会背";
  101. else
  102. name += " 会写";
  103. }
  104. that.setData({
  105. NumberWrong: listWrong.length,
  106. NumberSkip: listSkip.length,
  107. NumberRight: listRight.length,
  108. BookID: Number(TestTask.BookID),
  109. Name: name,
  110. List: result,
  111. NumberTotal: list.length,
  112. });
  113. if (that.data.ReportType == "new")
  114. that.saveInfo(TestTask);
  115. wx.setNavigationBarTitle({
  116. title: "报告"
  117. });
  118. }
  119. },
  120. expandPanel: function (e) {
  121. var that = this;
  122. var index = e.currentTarget.dataset.index;
  123. if (that.data.List[index].Expand == "1")
  124. that.data.List[index].Expand = "0";
  125. else
  126. that.data.List[index].Expand = "1";
  127. that.setData({
  128. List: that.data.List,
  129. });
  130. },
  131. onSelectItem: function (e) {
  132. var that = this;
  133. var index = e.currentTarget.dataset.index;
  134. var word = e.currentTarget.dataset.word;
  135. for (var i = 0; i < that.data.List[index].List.length; i++) {
  136. if (that.data.List[index].List[i].Word == word) {
  137. if (that.data.List[index].List[i].Css == "Select") {
  138. that.data.List[index].List[i].Css = "";
  139. that.setData({
  140. List: that.data.List,
  141. });
  142. } else if (that.data.List[index].List[i].Css == "Select2") {
  143. wx.showToast({
  144. title: '已经生成过了',
  145. image: "../images/universalpic_ribbon_white_96x120.png",
  146. });
  147. } else {
  148. that.data.List[index].List[i].Css = "Select";
  149. that.setData({
  150. List: that.data.List,
  151. });
  152. }
  153. break;
  154. }
  155. }
  156. },
  157. buildCard: function () {
  158. var that = this;
  159. var arr = [],
  160. TestExistStr = [];
  161. for (var i = 0; i < that.data.List.length; i++) {
  162. for (var j = 0; j < that.data.List[i].List.length; j++) {
  163. if (that.data.List[i].List[j].Css === "Select") {
  164. var item = that.data.List[i].List[j];
  165. var obj = {};
  166. obj.Field1 = item.Content[1].Content;
  167. obj.Field2 = item.Content[2].Content;
  168. if (item.Content[3] && item.Content[3].Content)
  169. obj.Field3 = item.Content[3].Content;
  170. else
  171. obj.Field3="";
  172. obj.Tags = item.Content[0].Content;
  173. if (!common.checkIsArray(obj.Tags))
  174. obj.Tags = obj.Tags.split(",");
  175. obj.ID = 0;
  176. obj.LimitTime = common.formatTime(new Date());
  177. obj.FontSize = item.FontSize;
  178. arr.push(obj);
  179. TestExistStr.push(item.Word);
  180. } else if (that.data.List[i].List[j].Css === "Select2") {
  181. var item = that.data.List[i].List[j];
  182. TestExistStr.push(item.Word);
  183. }
  184. }
  185. }
  186. //console.log(arr);
  187. if (arr.length > 0) {
  188. that.setData({
  189. IsBuild: 1,
  190. });
  191. var buildCardNumber = 0;
  192. intervalBuild = setInterval(function () {
  193. that.addCard(arr[buildCardNumber]);
  194. buildCardNumber++;
  195. that.setData({
  196. BuildCardNumber: Math.round(100 * buildCardNumber / arr.length) + "%",
  197. });
  198. if (buildCardNumber >= arr.length) {
  199. clearInterval(intervalBuild);
  200. var TestTask = {};
  201. TestTask.TestExistStr = TestExistStr;
  202. that.saveInfo(TestTask);
  203. that.setData({
  204. IsBuild: 2,
  205. });
  206. }
  207. }, 500);
  208. } else {
  209. wx.showToast({
  210. title: '先选题目',
  211. image: "../images/universalpic_wrong_white_120x120.png",
  212. });
  213. }
  214. },
  215. addCard: function (card) {
  216. var userid = app.globalData.userInfo.UserID;
  217. main.postData('AddMiaoguoCard?Type=add&UserID=' + userid, card, function (data) {
  218. });
  219. },
  220. close: function (e) {
  221. wx.removeStorageSync("TestTask");
  222. wx.navigateBack({
  223. delta: 1,
  224. });
  225. },
  226. saveInfo: function (TestTask) {
  227. var that = this;
  228. clearInterval(intervalBuild);
  229. var userid = app.globalData.userInfo.UserID;
  230. var param1 = wx.getStorageSync("TestTask");
  231. if (param1.List)
  232. param1.TestTotal = param1.List.length;
  233. var symbol="";
  234. if (that.data.BookID > 12) {
  235. symbol=","
  236. }
  237. if (TestTask.TestRightStr)
  238. param1.TestRightStr = TestTask.TestRightStr.join(symbol);
  239. if (common.checkIsArray(param1.TestRightStr))
  240. param1.TestRightStr=param1.TestRightStr.join(symbol);
  241. if (TestTask.TestWrongStr)
  242. param1.TestWrongStr = TestTask.TestWrongStr.join(symbol);
  243. if (common.checkIsArray(param1.TestWrongStr))
  244. param1.TestWrongStr=param1.TestWrongStr.join(symbol);
  245. if (TestTask.TestSkipStr)
  246. param1.TestSkipStr = TestTask.TestSkipStr.join(symbol);
  247. if (common.checkIsArray(param1.TestSkipStr))
  248. param1.TestSkipStr=param1.TestSkipStr.join(symbol);
  249. if (TestTask.TestExistStr)
  250. param1.TestExistStr = TestTask.TestExistStr.join(symbol);
  251. if (common.checkIsArray(param1.TestExistStr))
  252. param1.TestExistStr=param1.TestExistStr.join(symbol);
  253. if (TestReportID)
  254. param1.ID = TestReportID;
  255. param1.BookID=that.data.BookID;
  256. wx.setStorageSync('TestTask', param1);
  257. delete param1.List;
  258. main.postData('InsertTestReport?UserID=' + userid, param1, function (data) {
  259. if (data){
  260. TestReportID = data;
  261. var userid = app.globalData.userInfo.UserID;
  262. main.GetTestReportList(userid,function (data,GradeArrResult) {});
  263. }
  264. });
  265. },
  266. gotoReport: function (e) {
  267. if ((this.data.NumberRight + this.data.NumberWrong + this.data.NumberSkip) >= this.data.NumberTotal) {
  268. wx.showToast({
  269. title: '已经完成!',
  270. image: "../images/universalpic_wrong_white_120x120.png",
  271. });
  272. } else {
  273. var testTask = wx.getStorageSync("TestTask");
  274. if (TestReportID)
  275. testTask.ID=TestReportID;
  276. wx.setStorageSync("TestTask2", testTask);
  277. var url = "./item?type=edit";
  278. wx.redirectTo({
  279. url: url,
  280. });
  281. }
  282. },
  283. btnSelectAll:function(e){
  284. var name=e.currentTarget.dataset.name;
  285. var list=this.data.List;
  286. for(var i=0;i<list.length;i++){
  287. if (list[i].Name==name){
  288. for(var j=0;j<list[i].List.length;j++){
  289. if (!list[i].List[j].Css || list[i].List[j].Css=="")
  290. list[i].List[j].Css="Select";
  291. }
  292. }
  293. }
  294. this.setData({
  295. List: this.data.List,
  296. });
  297. },
  298. onUnload: function () {
  299. wx.removeStorageSync("TestTask");
  300. },
  301. onShareAppMessage: function () {
  302. return {
  303. title: app.globalData.ShareTitle,
  304. path: app.globalData.SharePath + '?UserID=' + app.globalData.userInfo.UserID,
  305. imageUrl: app.globalData.ShareImage,
  306. }
  307. },
  308. })