report.js 6.5 KB

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