answer.js 3.5 KB

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