report.js 8.8 KB

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