report.js 8.1 KB

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