answer.js 3.6 KB

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