answer.js 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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. FileUrl: app.globalData.fileUrl,
  8. IsEdit: false,
  9. ListHeight: 1320,
  10. ListHeight2: 1490,
  11. SelectedCount: 0,
  12. },
  13. onLoad: function () {
  14. this.setData({
  15. Containnerheight: server.getWindowHeight(),
  16. });
  17. this.getList();
  18. },
  19. getList: function () {
  20. var that = this;
  21. var list = wx.getStorageSync("AnswerList");
  22. if (list && list.length > 0) {
  23. var arr = [];
  24. for (var i = 0; i < list.length; i++) {
  25. list[i].Selected = false;
  26. arr.push(list[i]);
  27. }
  28. var ListHeight = 1320;
  29. var ListHeight2 = 1490;
  30. var ListHeight3 = arr.length * 130 + 20;
  31. if (arr.length > 10) {
  32. ListHeight = 1320 + (arr.length - 10) * 130;
  33. ListHeight2 = 1490 + (arr.length - 10) * 130;
  34. }
  35. that.setData({
  36. AnswerList: arr,
  37. ListHeight: ListHeight,
  38. ListHeight2: ListHeight2,
  39. ListHeight3: ListHeight3,
  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. }
  66. }
  67. },
  68. deleteItem: function () {
  69. var list = this.data.AnswerList;
  70. for (var i = list.length - 1; i >= 0; i--) {
  71. if (list[i].Selected) {
  72. list.splice(i, 1);
  73. }
  74. }
  75. list.sort(function (a, b) {
  76. if (a.CreateTime == b.CreateTime) {
  77. return b.AnswerID - b.AnswerID;
  78. } else {
  79. return b.CreateTime > a.CreateTime;
  80. }
  81. });
  82. this.setData({
  83. AnswerList: list,
  84. SelectedCount: 0,
  85. });
  86. wx.setStorageSync("AnswerList", list);
  87. },
  88. btnEdit: function () {
  89. var that = this;
  90. that.data.IsEdit = !that.data.IsEdit;
  91. for (var i = 0; i < that.data.AnswerList.length; i++) {
  92. that.data.AnswerList[i].Selected = false;
  93. }
  94. that.setData({
  95. IsEdit: that.data.IsEdit,
  96. AnswerList: that.data.AnswerList,
  97. });
  98. },
  99. onShareAppMessage: function () {
  100. return {
  101. title: '',
  102. path: 'pages/index/index',
  103. success: function (res) {
  104. },
  105. fail: function (err) {
  106. console.log(err);
  107. },
  108. complete: function (res) {
  109. console.log(res);
  110. },
  111. }
  112. },
  113. })