report.js 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  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. var TestTask = wx.getStorageSync("TestTask");
  23. var list = TestTask.List;
  24. var listRight = [];
  25. var listSkip = [];
  26. var listWrong = [];
  27. TestTask.TestRightStr=[];
  28. TestTask.TestWrongStr=[];
  29. TestTask.TestSkipStr=[];
  30. if (list) {
  31. for (var i = 0; i < list.length; i++) {
  32. if (list[i].Result == 1) {
  33. listRight.push(list[i]);
  34. TestTask.TestRightStr.push(list[i].Word);
  35. }
  36. else if (list[i].Result == -1) {
  37. listWrong.push(list[i]);
  38. TestTask.TestWrongStr.push(list[i].Word);
  39. }
  40. else if (list[i].Result == 0) {
  41. listSkip.push(list[i]);
  42. TestTask.TestSkipStr.push(list[i].Word);
  43. }
  44. }
  45. var result = [];
  46. if (listWrong.length > 0) {
  47. result.push({ Name: "答错的题目", Expand: 1, List: listWrong });
  48. if (listSkip.length > 0)
  49. result.push({ Name: "跳过的题目", Expand: 1, List: listSkip });
  50. if (listRight.length > 0)
  51. result.push({ Name: "答对的题目", Expand: 1, List: listRight });
  52. }
  53. else {
  54. if (listSkip.length > 0) {
  55. result.push({ Name: "跳过的题目", Expand: 1, List: listSkip });
  56. if (listRight.length > 0)
  57. result.push({ Name: "答对的题目", Expand: 1, List: listRight });
  58. }
  59. else {
  60. if (listRight.length > 0)
  61. result.push({ Name: "答对的题目", Expand: 1, List: listRight });
  62. }
  63. }
  64. var name = "";
  65. if (TestTask.Name && TestTask.Name.indexOf("#")>0){
  66. name=TestTask.Name;
  67. name=name.substr(name.indexOf("#")+1);
  68. if (TestTask.TestType=="read")
  69. name+=" 会念";
  70. else
  71. name+=" 会写";
  72. }
  73. that.setData({
  74. NumberWrong: listWrong.length,
  75. NumberSkip: listSkip.length,
  76. NumberRight: listRight.length,
  77. Name: name,
  78. List: result,
  79. NumberTotal: list.length,
  80. });
  81. if (that.data.ReportType=="new")
  82. that.saveInfo(TestTask);
  83. wx.setNavigationBarTitle({
  84. title: "报告"
  85. });
  86. }
  87. },
  88. expandPanel: function (e) {
  89. var that = this;
  90. var index = e.currentTarget.dataset.index;
  91. if (that.data.List[index].Expand == "1")
  92. that.data.List[index].Expand = "0";
  93. else
  94. that.data.List[index].Expand = "1";
  95. that.setData({
  96. List: that.data.List,
  97. });
  98. },
  99. onSelectItem: function (e) {
  100. var that = this;
  101. var index = e.currentTarget.dataset.index;
  102. var word = e.currentTarget.dataset.word;
  103. for (var i = 0; i < that.data.List[index].List.length; i++) {
  104. if (that.data.List[index].List[i].Word == word) {
  105. if (that.data.List[index].List[i].Css == "Select") {
  106. that.data.List[index].List[i].Css = "";
  107. that.setData({
  108. List: that.data.List,
  109. });
  110. }
  111. else if (that.data.List[index].List[i].Css == "Select2") {
  112. wx.showToast({
  113. title: '已经生成过了',
  114. image: "../images/universalpic_ribbon_white_96x120.png",
  115. });
  116. }
  117. else {
  118. that.data.List[index].List[i].Css = "Select";
  119. that.setData({
  120. List: that.data.List,
  121. });
  122. }
  123. break;
  124. }
  125. }
  126. },
  127. buildCard: function () {
  128. var that = this;
  129. var arr = [],TestExistStr=[];
  130. for (var i = 0; i < that.data.List.length; i++) {
  131. for (var j = 0; j < that.data.List[i].List.length; j++) {
  132. if (that.data.List[i].List[j].Css === "Select") {
  133. var item = that.data.List[i].List[j];
  134. var obj = {};
  135. obj.Field1 = item.Content[1].Content;
  136. obj.Field2 = item.Content[2].Content;
  137. obj.Field3 = "";
  138. obj.Tags = item.Content[0].Content;
  139. obj.IsTodayStudy = 0;
  140. obj.ID = 0;
  141. obj.LimitTime = common.formatTime(new Date());
  142. obj.FontSize = item.FontSize;
  143. arr.push(obj);
  144. TestExistStr.push(item.Word);
  145. }
  146. else if (that.data.List[i].List[j].Css === "Select2") {
  147. var item = that.data.List[i].List[j];
  148. TestExistStr.push(item.Word);
  149. }
  150. }
  151. }
  152. //console.log(arr);
  153. if (arr.length > 0) {
  154. that.setData({
  155. IsBuild: 1,
  156. });
  157. var buildCardNumber = 0;
  158. intervalBuild = setInterval(function () {
  159. that.addCard(arr[buildCardNumber]);
  160. buildCardNumber++;
  161. that.setData({
  162. BuildCardNumber: Math.round(100 * buildCardNumber / arr.length) + "%",
  163. });
  164. if (buildCardNumber >= arr.length) {
  165. clearInterval(intervalBuild);
  166. var TestTask={};
  167. TestTask.TestExistStr=TestExistStr;
  168. that.saveInfo(TestTask);
  169. that.setData({
  170. IsBuild: 2,
  171. });
  172. }
  173. }, 500);
  174. }
  175. else {
  176. wx.showToast({
  177. title: '先选题目',
  178. image: "../images/universalpic_wrong_white_120x120.png",
  179. });
  180. }
  181. },
  182. addCard: function (card) {
  183. var userid = app.globalData.userInfo.UserID;
  184. main.postData('AddMiaoguoCard?Type=add&UserID=' + userid, card, function (data) {
  185. });
  186. },
  187. close: function (e) {
  188. wx.removeStorageSync("TestTask");
  189. var delta=2;
  190. if (this.data.ReportType=="edit")
  191. delta=1;
  192. wx.navigateBack({
  193. delta: delta,
  194. });
  195. },
  196. saveInfo: function (TestTask) {
  197. var that = this;
  198. clearInterval(intervalBuild);
  199. var userid = app.globalData.userInfo.UserID;
  200. var param1 = wx.getStorageSync("TestTask");
  201. param1.TestTotal = param1.List.length;
  202. if (TestTask.TestRightStr)
  203. param1.TestRightStr=TestTask.TestRightStr.join("");
  204. if (TestTask.TestWrongStr)
  205. param1.TestWrongStr=TestTask.TestWrongStr.join("");
  206. if (TestTask.TestSkipStr)
  207. param1.TestSkipStr=TestTask.TestSkipStr.join("");
  208. if (TestTask.TestExistStr)
  209. param1.TestExistStr=TestTask.TestExistStr.join("");
  210. //param1.List = JSON.stringify(param1.List);
  211. delete param1.List;
  212. main.postData('InsertTestReport?UserID=' + userid, param1, function (data) {
  213. if (data)
  214. TestReportID = data;
  215. });
  216. },
  217. gotoReport: function (e) {
  218. if ((this.data.NumberRight + this.data.NumberWrong + this.data.NumberSkip) >= this.data.NumberTotal) {
  219. wx.showToast({
  220. title: '已经完成!',
  221. image: "../images/universalpic_wrong_white_120x120.png",
  222. });
  223. }
  224. else {
  225. var testTask = wx.getStorageSync("TestTask");
  226. if (TestReportID)
  227. testTask.ID = TestReportID;
  228. wx.setStorageSync("TestTask2", testTask);
  229. var url = "./item?type=edit";
  230. wx.redirectTo({
  231. url: url,
  232. });
  233. }
  234. },
  235. onUnload: function () {
  236. wx.removeStorageSync("TestTask");
  237. },
  238. onShareAppMessage: function () {
  239. return {
  240. title: app.globalData.ShareTitle,
  241. path: app.globalData.SharePath + '?UserID=' + app.globalData.userInfo.UserID,
  242. imageUrl: app.globalData.ShareImage,
  243. }
  244. },
  245. })