answer.js 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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. SelectedCount: 0,
  11. },
  12. onLoad: function () {
  13. this.setData({
  14. Containnerheight: server.getWindowHeight(),
  15. });
  16. this.getList();
  17. },
  18. getList: function () {
  19. var that = this;
  20. var list = wx.getStorageSync("AnswerList");
  21. if (list && list.length > 0) {
  22. var arr = [];
  23. for (var i = 0; i < list.length; i++) {
  24. list[i].Selected = false;
  25. arr.push(list[i]);
  26. }
  27. var ListHeight = 1320;
  28. var ListHeight2 = 1490;
  29. var ListHeight3 = arr.length * 130 + 20;
  30. if (arr.length > 10) {
  31. ListHeight = 1320 + (arr.length - 10) * 130;
  32. ListHeight2 = 1490 + (arr.length - 10) * 130;
  33. }
  34. that.setData({
  35. AnswerList: arr,
  36. ListHeight: ListHeight,
  37. ListHeight2: ListHeight2,
  38. ListHeight3: ListHeight3,
  39. });
  40. }
  41. },
  42. selectItem: function (e) {
  43. if (e.currentTarget.dataset.id) {
  44. var id = e.currentTarget.dataset.id;
  45. if (this.data.IsEdit) {
  46. var count = 0;
  47. var list = this.data.AnswerList;
  48. for (var i = 0; i < list.length; i++) {
  49. if (id == list[i].AnswerID) {
  50. list[i].Selected = !list[i].Selected;
  51. }
  52. if (list[i].Selected)
  53. count++;
  54. }
  55. this.setData({
  56. AnswerList: list,
  57. SelectedCount: count,
  58. });
  59. }
  60. else {
  61. wx.navigateTo({
  62. url: '../main/item?id=' + id,
  63. });
  64. }
  65. }
  66. },
  67. deleteItem: function () {
  68. var list = this.data.AnswerList;
  69. for (var i = list.length - 1; i >= 0; i--) {
  70. if (list[i].Selected) {
  71. list.splice(i, 1);
  72. }
  73. }
  74. list.sort(function (a, b) {
  75. if (a.CreateTime == b.CreateTime) {
  76. return b.AnswerID - b.AnswerID;
  77. } else {
  78. return b.CreateTime > a.CreateTime;
  79. }
  80. });
  81. this.setData({
  82. AnswerList: list,
  83. SelectedCount: 0,
  84. });
  85. wx.setStorageSync("AnswerList", list);
  86. },
  87. btnEdit: function () {
  88. var that = this;
  89. that.data.IsEdit = !that.data.IsEdit;
  90. for (var i = 0; i < that.data.AnswerList.length; i++) {
  91. that.data.AnswerList[i].Selected = false;
  92. }
  93. that.setData({
  94. IsEdit: that.data.IsEdit,
  95. AnswerList: that.data.AnswerList,
  96. });
  97. },
  98. onShareAppMessage: function () {
  99. return {
  100. title: '',
  101. path: 'pages/index/index',
  102. success: function (res) {
  103. },
  104. fail: function (err) {
  105. console.log(err);
  106. },
  107. complete: function (res) {
  108. console.log(res);
  109. },
  110. }
  111. },
  112. })