answer.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. import common from '../../utils/util';
  2. import server from '../../utils/main';
  3. const app = getApp()
  4. Page({
  5. data: {
  6. version: app.globalData.version,
  7. IsEdit: false,
  8. ListHeight2: 600,
  9. SelectedCount: 0,
  10. },
  11. onLoad: function () {
  12. var that = this;
  13. this.setData({
  14. Containnerheight: server.getWindowHeight(),
  15. });
  16. this.getList();
  17. common.getStorageValue(this, "HelpHidden5", false, function () {
  18. that.showHelp();
  19. });
  20. },
  21. onUnload: function () {
  22. this.closeHelp();
  23. },
  24. getList: function () {
  25. //console.log(new Date().getTime());
  26. var that = this;
  27. var list = wx.getStorageSync("AnswerList");
  28. if (list && list.length > 0) {
  29. var arr = [];
  30. for (var i = 0; i < list.length; i++) {
  31. list[i].Selected = false;
  32. arr.push(list[i]);
  33. }
  34. that.setData({
  35. AnswerList: arr,
  36. });
  37. this.setListHeight();
  38. if (arr.length>10){
  39. wx.showToast({
  40. title:"请删除不用试卷!",
  41. duration:2000,
  42. });
  43. }
  44. }
  45. },
  46. selectItem: function (e) {
  47. if (e.currentTarget.dataset.id) {
  48. var id = e.currentTarget.dataset.id;
  49. if (this.data.IsEdit) {
  50. var count = 0;
  51. var list = this.data.AnswerList;
  52. for (var i = 0; i < list.length; i++) {
  53. if (id == list[i].AnswerID) {
  54. list[i].Selected = !list[i].Selected;
  55. }
  56. if (list[i].Selected)
  57. count++;
  58. }
  59. this.setData({
  60. AnswerList: list,
  61. SelectedCount: count,
  62. });
  63. }
  64. else {
  65. wx.navigateTo({
  66. url: '../main/item?id=' + id,
  67. });
  68. this.closeHelp();
  69. }
  70. }
  71. },
  72. deleteItem: function () {
  73. var list = this.data.AnswerList;
  74. for (var i = list.length - 1; i >= 0; i--) {
  75. if (list[i].Selected) {
  76. wx.removeSavedFile({
  77. filePath:list[i].TempImagePath
  78. });
  79. list.splice(i, 1);
  80. }
  81. }
  82. list.sort(function (a, b) {
  83. if (a.CreateTime == b.CreateTime) {
  84. return b.AnswerID - b.AnswerID;
  85. } else {
  86. return b.CreateTime > a.CreateTime;
  87. }
  88. });
  89. this.setData({
  90. AnswerList: list,
  91. SelectedCount: 0,
  92. });
  93. this.setListHeight();
  94. wx.setStorageSync("AnswerList", list);
  95. },
  96. setListHeight:function(){
  97. var ListHeight2 = 600;
  98. if (this.data.AnswerList.length > 3) {
  99. ListHeight2 = 570 + (this.data.AnswerList.length - 3) * 130;
  100. }
  101. this.setData({
  102. ListHeight2: ListHeight2,
  103. });
  104. },
  105. btnEdit: function () {
  106. var that = this;
  107. that.data.IsEdit = !that.data.IsEdit;
  108. for (var i = 0; i < that.data.AnswerList.length; i++) {
  109. that.data.AnswerList[i].Selected = false;
  110. }
  111. that.setData({
  112. IsEdit: that.data.IsEdit,
  113. AnswerList: that.data.AnswerList,
  114. });
  115. },
  116. showHelp: function () {
  117. if (!this.data.HelpHidden5) {
  118. this.audioCtx = wx.createAudioContext('myAudio');
  119. var str = "哇哦,已经做完了呀。接下来,根据卷子右上角的编号,从传送带上选择答案吧。";
  120. server.playAudio(this.audioCtx, str);
  121. }
  122. },
  123. closeHelp: function () {
  124. this.setData({
  125. HelpHidden5: true,
  126. });
  127. wx.setStorageSync("HelpHidden5", true);
  128. this.audioCtx = wx.createAudioContext('myAudio');
  129. this.audioCtx.pause();
  130. },
  131. onShareAppMessage: function () {
  132. return {
  133. title: app.globalData.ShareTitle,
  134. path: 'pages/index/index?UserID=' + app.globalData.userInfo.UserID,
  135. imageUrl: app.globalData.ShareImage,
  136. }
  137. },
  138. })