report.js 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355
  1. import common from '../../utils/util';
  2. import main from '../../utils/main';
  3. const app = getApp();
  4. var intervalBuild = null;
  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. that.data.List[index].List[i].Css = "Select3";
  144. that.setData({
  145. List: that.data.List,
  146. });
  147. } else if (that.data.List[index].List[i].Css == "Select3") {
  148. that.data.List[index].List[i].Css = "Select2";
  149. that.setData({
  150. List: that.data.List,
  151. });
  152. } else {
  153. that.data.List[index].List[i].Css = "Select";
  154. that.setData({
  155. List: that.data.List,
  156. });
  157. }
  158. break;
  159. }
  160. }
  161. },
  162. buildCard: function () {
  163. var that = this;
  164. var arr = [],
  165. TestExistStr = [];
  166. for (var i = 0; i < that.data.List.length; i++) {
  167. for (var j = 0; j < that.data.List[i].List.length; j++) {
  168. if (that.data.List[i].List[j].Css === "Select" || that.data.List[i].List[j].Css === "Select3") {
  169. var item = that.data.List[i].List[j];
  170. var obj = {};
  171. obj.Field1 = item.Content[1].Content;
  172. obj.Field2 = item.Content[2].Content;
  173. if (item.Content[3] && item.Content[3].Content)
  174. obj.Field3 = item.Content[3].Content;
  175. else
  176. obj.Field3="";
  177. obj.Tags = item.Content[0].Content;
  178. if (!Array.isArray(obj.Tags))
  179. obj.Tags = obj.Tags.split(",");
  180. obj.ID = 0;
  181. obj.LimitTime = common.formatTime(new Date());
  182. obj.FontSize = item.FontSize;
  183. obj.Type="add";
  184. if (that.data.List[i].List[j].Css === "Select3")
  185. obj.Type="IsExist";
  186. arr.push(obj);
  187. TestExistStr.push(item.Word);
  188. }
  189. }
  190. }
  191. //console.log(arr);
  192. if (arr.length > 0) {
  193. that.setData({
  194. IsBuild: 1,
  195. });
  196. var buildCardNumber = 0;
  197. if (intervalBuild!=null){
  198. clearInterval(intervalBuild);
  199. intervalBuild=null;
  200. }
  201. intervalBuild = setInterval(function () {
  202. if (arr.length>0){
  203. that.addCard(arr[buildCardNumber]);
  204. buildCardNumber++;
  205. that.setData({
  206. BuildCardNumber: Math.round(100 * buildCardNumber / arr.length) + "%",
  207. });
  208. if (buildCardNumber >= arr.length) {
  209. clearInterval(intervalBuild);
  210. //intervalBuild=null;
  211. buildCardNumber=0;
  212. arr=[];
  213. var TestTask = {};
  214. TestTask.TestExistStr = TestExistStr;
  215. that.saveInfo(TestTask);
  216. that.setData({
  217. IsBuild: 2,
  218. });
  219. }
  220. }
  221. else{
  222. clearInterval(intervalBuild);
  223. //intervalBuild=null;
  224. }
  225. }, 500);
  226. } else {
  227. wx.showToast({
  228. title: '先选题目',
  229. image: "../../pages/images/universalpic_wrong_white_120x120.png",
  230. });
  231. }
  232. },
  233. addCard: function (card) {
  234. var userid = app.globalData.userInfo.UserID;
  235. var cardType=card.Type;
  236. delete card.Type;
  237. main.postData('AddMiaoguoCard?Type='+cardType+'&UserID=' + userid, card, function (data) {
  238. });
  239. },
  240. close: function (e) {
  241. wx.removeStorageSync("TestTask");
  242. wx.navigateBack({
  243. delta: 1,
  244. });
  245. },
  246. saveInfo: function (TestTask) {
  247. var that = this;
  248. var userid = app.globalData.userInfo.UserID;
  249. var param1 = wx.getStorageSync("TestTask");
  250. if (param1.List)
  251. param1.TestTotal = param1.List.length;
  252. var symbol="";
  253. if (that.data.BookID > 12) {
  254. symbol=","
  255. }
  256. if (TestTask.TestRightStr)
  257. param1.TestRightStr = TestTask.TestRightStr.join(symbol);
  258. if (Array.isArray(param1.TestRightStr))
  259. param1.TestRightStr=param1.TestRightStr.join(symbol);
  260. if (TestTask.TestWrongStr)
  261. param1.TestWrongStr = TestTask.TestWrongStr.join(symbol);
  262. if (Array.isArray(param1.TestWrongStr))
  263. param1.TestWrongStr=param1.TestWrongStr.join(symbol);
  264. if (TestTask.TestSkipStr)
  265. param1.TestSkipStr = TestTask.TestSkipStr.join(symbol);
  266. if (Array.isArray(param1.TestSkipStr))
  267. param1.TestSkipStr=param1.TestSkipStr.join(symbol);
  268. if (TestTask.TestExistStr)
  269. param1.TestExistStr = TestTask.TestExistStr.join(symbol);
  270. if (Array.isArray(param1.TestExistStr))
  271. param1.TestExistStr=param1.TestExistStr.join(symbol);
  272. if (TestReportID)
  273. param1.ID = TestReportID;
  274. param1.BookID=that.data.BookID;
  275. wx.setStorageSync('TestTask', param1);
  276. delete param1.List;
  277. main.postData('InsertTestReport?UserID=' + userid, param1, function (data) {
  278. if (data){
  279. TestReportID = data;
  280. var userid = app.globalData.userInfo.UserID;
  281. main.GetTestReportList(userid,function (data,GradeArrResult) {});
  282. }
  283. });
  284. },
  285. gotoReport: function (e) {
  286. if ((this.data.NumberRight + this.data.NumberWrong + this.data.NumberSkip) >= this.data.NumberTotal) {
  287. wx.showToast({
  288. title: '已经完成!',
  289. image: "../../pages/images/universalpic_wrong_white_120x120.png",
  290. });
  291. } else {
  292. var testTask = wx.getStorageSync("TestTask");
  293. if (TestReportID)
  294. testTask.ID=TestReportID;
  295. wx.setStorageSync("TestTask2", testTask);
  296. var url = "./item?type=edit";
  297. wx.redirectTo({
  298. url: url,
  299. });
  300. }
  301. },
  302. btnSelectAll:function(e){
  303. var name=e.currentTarget.dataset.name;
  304. var list=this.data.List;
  305. for(var i=0;i<list.length;i++){
  306. if (list[i].Name==name){
  307. for(var j=0;j<list[i].List.length;j++){
  308. if (!list[i].List[j].Css || list[i].List[j].Css=="")
  309. list[i].List[j].Css="Select";
  310. if (list[i].List[j].Css=="Select2")
  311. list[i].List[j].Css="Select3";
  312. }
  313. }
  314. }
  315. this.setData({
  316. List: this.data.List,
  317. });
  318. },
  319. onUnload: function () {
  320. wx.removeStorageSync("TestTask");
  321. },
  322. onShareAppMessage: function () {
  323. return {
  324. title: app.globalData.ShareTitle,
  325. path: app.globalData.SharePath + '?UserID=' + app.globalData.userInfo.UserID,
  326. imageUrl: app.globalData.ShareImage,
  327. }
  328. },
  329. })