report.js 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321
  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 (name.indexOf("#")>0)
  94. name = name.substr(0,name.indexOf("#"));
  95. if (TestTask.TestType == "read")
  96. name += " 会念";
  97. else if (TestTask.TestType == "recite")
  98. name += " 会背";
  99. else
  100. name += " 会写";
  101. }
  102. that.setData({
  103. NumberWrong: listWrong.length,
  104. NumberSkip: listSkip.length,
  105. NumberRight: listRight.length,
  106. BookID: Number(TestTask.BookID),
  107. Name: name,
  108. List: result,
  109. NumberTotal: list.length,
  110. });
  111. if (that.data.ReportType == "new")
  112. that.saveInfo(TestTask);
  113. wx.setNavigationBarTitle({
  114. title: "报告"
  115. });
  116. }
  117. },
  118. expandPanel: function (e) {
  119. var that = this;
  120. var index = e.currentTarget.dataset.index;
  121. if (that.data.List[index].Expand == "1")
  122. that.data.List[index].Expand = "0";
  123. else
  124. that.data.List[index].Expand = "1";
  125. that.setData({
  126. List: that.data.List,
  127. });
  128. },
  129. onSelectItem: function (e) {
  130. var that = this;
  131. var index = e.currentTarget.dataset.index;
  132. var word = e.currentTarget.dataset.word;
  133. for (var i = 0; i < that.data.List[index].List.length; i++) {
  134. if (that.data.List[index].List[i].Word == word) {
  135. if (that.data.List[index].List[i].Css == "Select") {
  136. that.data.List[index].List[i].Css = "";
  137. that.setData({
  138. List: that.data.List,
  139. });
  140. } else if (that.data.List[index].List[i].Css == "Select2") {
  141. wx.showToast({
  142. title: '已经生成过了',
  143. image: "../images/universalpic_ribbon_white_96x120.png",
  144. });
  145. } else {
  146. that.data.List[index].List[i].Css = "Select";
  147. that.setData({
  148. List: that.data.List,
  149. });
  150. }
  151. break;
  152. }
  153. }
  154. },
  155. buildCard: function () {
  156. var that = this;
  157. var arr = [],
  158. TestExistStr = [];
  159. for (var i = 0; i < that.data.List.length; i++) {
  160. for (var j = 0; j < that.data.List[i].List.length; j++) {
  161. if (that.data.List[i].List[j].Css === "Select") {
  162. var item = that.data.List[i].List[j];
  163. var obj = {};
  164. obj.Field1 = item.Content[1].Content;
  165. obj.Field2 = item.Content[2].Content;
  166. if (item.Content[3] && item.Content[3].Content)
  167. obj.Field3 = item.Content[3].Content;
  168. else
  169. obj.Field3="";
  170. obj.Tags = item.Content[0].Content;
  171. if (!common.checkIsArray(obj.Tags))
  172. obj.Tags = obj.Tags.split(",");
  173. obj.ID = 0;
  174. obj.LimitTime = common.formatTime(new Date());
  175. obj.FontSize = item.FontSize;
  176. arr.push(obj);
  177. TestExistStr.push(item.Word);
  178. } else if (that.data.List[i].List[j].Css === "Select2") {
  179. var item = that.data.List[i].List[j];
  180. TestExistStr.push(item.Word);
  181. }
  182. }
  183. }
  184. //console.log(arr);
  185. if (arr.length > 0) {
  186. that.setData({
  187. IsBuild: 1,
  188. });
  189. var buildCardNumber = 0;
  190. intervalBuild = setInterval(function () {
  191. that.addCard(arr[buildCardNumber]);
  192. buildCardNumber++;
  193. that.setData({
  194. BuildCardNumber: Math.round(100 * buildCardNumber / arr.length) + "%",
  195. });
  196. if (buildCardNumber >= arr.length) {
  197. clearInterval(intervalBuild);
  198. var TestTask = {};
  199. TestTask.TestExistStr = TestExistStr;
  200. that.saveInfo(TestTask);
  201. that.setData({
  202. IsBuild: 2,
  203. });
  204. }
  205. }, 500);
  206. } else {
  207. wx.showToast({
  208. title: '先选题目',
  209. image: "../images/universalpic_wrong_white_120x120.png",
  210. });
  211. }
  212. },
  213. addCard: function (card) {
  214. var userid = app.globalData.userInfo.UserID;
  215. main.postData('AddMiaoguoCard?Type=add&UserID=' + userid, card, function (data) {
  216. });
  217. },
  218. close: function (e) {
  219. wx.removeStorageSync("TestTask");
  220. var delta = 2;
  221. if (this.data.ReportType == "edit")
  222. delta = 1;
  223. if (this.data.BookID==100 || (this.data.BookID>=25 && this.data.BookID<=36))
  224. delta = 1;
  225. wx.navigateBack({
  226. delta: delta,
  227. });
  228. },
  229. saveInfo: function (TestTask) {
  230. var that = this;
  231. clearInterval(intervalBuild);
  232. var userid = app.globalData.userInfo.UserID;
  233. var param1 = wx.getStorageSync("TestTask");
  234. if (param1.List)
  235. param1.TestTotal = param1.List.length;
  236. var symbol="";
  237. if (that.data.BookID > 12) {
  238. symbol=","
  239. }
  240. if (TestTask.TestRightStr)
  241. param1.TestRightStr = TestTask.TestRightStr.join(symbol);
  242. if (common.checkIsArray(param1.TestWrongStr))
  243. param1.TestRightStr=param1.TestRightStr.join(symbol);
  244. if (TestTask.TestWrongStr)
  245. param1.TestWrongStr = TestTask.TestWrongStr.join(symbol);
  246. if (common.checkIsArray(param1.TestWrongStr))
  247. param1.TestWrongStr=param1.TestWrongStr.join(symbol);
  248. if (TestTask.TestSkipStr)
  249. param1.TestSkipStr = TestTask.TestSkipStr.join(symbol);
  250. if (common.checkIsArray(param1.TestSkipStr))
  251. param1.TestSkipStr=param1.TestSkipStr.join(symbol);
  252. if (TestTask.TestExistStr)
  253. param1.TestExistStr = TestTask.TestExistStr.join(symbol);
  254. if (common.checkIsArray(param1.TestExistStr))
  255. param1.TestExistStr=param1.TestExistStr.join(symbol);
  256. if (TestReportID)
  257. param1.ID = TestReportID;
  258. param1.BookID=that.data.BookID;
  259. wx.setStorageSync('TestTask', param1);
  260. delete param1.List;
  261. main.postData('InsertTestReport?UserID=' + userid, param1, function (data) {
  262. if (data){
  263. TestReportID = data;
  264. }
  265. });
  266. },
  267. gotoReport: function (e) {
  268. if ((this.data.NumberRight + this.data.NumberWrong + this.data.NumberSkip) >= this.data.NumberTotal) {
  269. wx.showToast({
  270. title: '已经完成!',
  271. image: "../images/universalpic_wrong_white_120x120.png",
  272. });
  273. } else {
  274. var testTask = wx.getStorageSync("TestTask");
  275. if (TestReportID)
  276. testTask.ID=TestReportID;
  277. wx.setStorageSync("TestTask2", testTask);
  278. var url = "./item?type=edit";
  279. wx.redirectTo({
  280. url: url,
  281. });
  282. }
  283. },
  284. onUnload: function () {
  285. wx.removeStorageSync("TestTask");
  286. },
  287. onShareAppMessage: function () {
  288. return {
  289. title: app.globalData.ShareTitle,
  290. path: app.globalData.SharePath + '?UserID=' + app.globalData.userInfo.UserID,
  291. imageUrl: app.globalData.ShareImage,
  292. }
  293. },
  294. })