work-list.js 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. // pages/progress/work-list.js
  2. const api = require('../../utils/o2Api.js');
  3. const util = require('../../utils/util.js');
  4. const firstId = '(0)';
  5. const defaultPageSize = 15;
  6. Page({
  7. /**
  8. * Page initial data
  9. */
  10. data: {
  11. navTitle: '',
  12. type: 'task', //task | taskCompleted | read | readCompleted
  13. articleList: [],
  14. lastId: firstId,
  15. },
  16. /**
  17. * Lifecycle function--Called when page load
  18. */
  19. onLoad: function (options) {
  20. if(!options.type) {
  21. util.toast('参数不正确!');
  22. wx.navigateBack({
  23. delta: 1,
  24. });
  25. }else {
  26. if (options.type == 'task') {
  27. this.setData({
  28. navTitle: '待办列表',
  29. type:'task'
  30. });
  31. this.loadData(true);
  32. } else if (options.type == 'taskCompleted') {
  33. this.setData({
  34. navTitle: '已办列表',
  35. type:'taskCompleted'
  36. });
  37. this.loadData(true);
  38. } else if (options.type == 'read') {
  39. this.setData({
  40. navTitle: '待阅列表',
  41. type:'read'
  42. });
  43. this.loadData(true);
  44. } else if (options.type == 'readCompleted') {
  45. this.setData({
  46. navTitle: '已阅列表',
  47. type:'readCompleted'
  48. });
  49. this.loadData(true);
  50. } else {
  51. util.toast('参数不正确!');
  52. wx.navigateBack({
  53. delta: 1,
  54. });
  55. }
  56. }
  57. },
  58. loadData: function(isRefresh) {
  59. var lastId = this.data.lastId;
  60. if (isRefresh) {
  61. this.data.lastId = firstId;
  62. lastId = firstId;
  63. }
  64. if (this.data.type == 'task') {
  65. var future = api.taskList(lastId, defaultPageSize);
  66. } else if (this.data.type == 'taskCompleted') {
  67. var future = api.taskCompletedList(lastId, defaultPageSize);
  68. } else if (this.data.type == 'read') {
  69. var future = api.readList(lastId, defaultPageSize);
  70. } else if (this.data.type == 'readCompleted') {
  71. var future = api.readCompletedList(lastId, defaultPageSize);
  72. }
  73. future.then(list => {
  74. if (isRefresh) {
  75. this.data.articleList = [];
  76. }
  77. if (list && list.length > 0) {
  78. var taskList = [];
  79. list.forEach(function(v) {
  80. var obj = {
  81. work: v.work,
  82. workCompleted: v.workCompleted,
  83. title: v.title == '' ? '无标题' : v.title,
  84. type: '【'+v.processName+'】',
  85. date: v.startTime.length > 9 ? v.startTime.substring(0, 10) : v.startTime
  86. };
  87. taskList.push(obj);
  88. });
  89. this.data.articleList.push(...taskList);
  90. var lastId = list[list.length-1].id;
  91. this.setData({
  92. articleList: this.data.articleList,
  93. lastId: lastId
  94. });
  95. }else {
  96. this.setData({
  97. articleList: this.data.articleList
  98. });
  99. }
  100. wx.stopPullDownRefresh();
  101. }).catch(err => {
  102. api.o2Error(err);
  103. wx.stopPullDownRefresh();
  104. })
  105. },
  106. bindTapArticle: function(event) {
  107. let index = event.currentTarget.dataset.index;
  108. let data = this.data.articleList[index];
  109. if (!data.workCompleted) {
  110. wx.navigateTo({
  111. url: '../progress/work-web?work=' + data.work + '&title=' + encodeURIComponent(data.title)
  112. });
  113. }else {
  114. wx.navigateTo({
  115. url: '../progress/work-web?workCompleted=' + data.workCompleted + '&title=' + encodeURIComponent(data.title)
  116. });
  117. }
  118. },
  119. /**
  120. * Lifecycle function--Called when page is initially rendered
  121. */
  122. onReady: function () {
  123. },
  124. /**
  125. * Lifecycle function--Called when page show
  126. */
  127. onShow: function () {
  128. },
  129. /**
  130. * Lifecycle function--Called when page hide
  131. */
  132. onHide: function () {
  133. },
  134. /**
  135. * Lifecycle function--Called when page unload
  136. */
  137. onUnload: function () {
  138. },
  139. /**
  140. * Page event handler function--Called when user drop down
  141. */
  142. onPullDownRefresh: function () {
  143. this.loadData(true);
  144. },
  145. /**
  146. * Called when page reach bottom
  147. */
  148. onReachBottom: function () {
  149. this.loadData(false);
  150. },
  151. /**
  152. * Called when user click on the top right corner to share
  153. */
  154. onShareAppMessage: function () {
  155. }
  156. })