report.js 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. var app = getApp();
  2. var that;
  3. import 'dingtalk-jsapi/entry/mobile';
  4. import openLink from 'dingtalk-jsapi/api/biz/util/openLink';
  5. Page({
  6. data: {
  7. showIndex: 1,
  8. thisweek: {
  9. end_day: '',
  10. start_day: ''
  11. },
  12. employee_id: '',
  13. isUrl: true,
  14. start: '',//查看周开始时间
  15. allDate:'',
  16. },
  17. onLoad(e) {
  18. that = this;
  19. dd.setNavigationBar({ title: "积分周报" });
  20. if (e.employee_id) {
  21. this.setData({
  22. employee_id: e.employee_id
  23. })
  24. }
  25. if (e.start) {
  26. this.setData({
  27. isUrl: e.start,
  28. })
  29. }
  30. if (e.isUrl) {
  31. this.setData({
  32. isUrl: false,
  33. })
  34. }
  35. this.setData({
  36. allDate: app.globalData.allDate,
  37. })
  38. this.setDate();
  39. dd.showLoading({
  40. content: '加载中...',
  41. });
  42. setTimeout(() => {
  43. dd.hideLoading();
  44. }, 1000)
  45. },
  46. onShareAppMessage() {
  47. let userId = this.data.employee_id ? this.data.employee_id : app.globalData.userData.id
  48. return {
  49. title: '积分周报',
  50. desc: that.data.result.employee.name + '的积分周报分享',
  51. path: 'pages/reportBox/report/report?employee_id=' + userId + '&isUrl=123&start' + that.data.result.date.start
  52. };
  53. },
  54. onShow() {
  55. this.opneWebSocket()
  56. },
  57. //跳转
  58. openView(e) {
  59. let index = e.target.dataset.index
  60. if (!this.data.isUrl && index != 6) {
  61. return false
  62. }
  63. if (index == 1) {
  64. dd.navigateTo({
  65. url: '../../statistics/my_task/my_task'
  66. })
  67. } else if (index == 2) {
  68. dd.navigateTo({
  69. url: '../../statistics/my_issue/my_issue'
  70. })
  71. } else if (index == 3) {
  72. dd.navigateTo({
  73. url: '../../workbench/prize_buckle/prize_buckle'
  74. })
  75. } else if (index == 4) {
  76. let data = {
  77. type: 'week_statistics',
  78. employee_id: this.data.employee_id ? this.data.employee_id : app.globalData.userData.id,
  79. start_date: this.data.start ? this.data.start : this.data.thisweek.start_day,
  80. method: 'ruleList',
  81. page_size: 1000,
  82. rule_item_id: e.target.dataset.item.rule_item_id
  83. }
  84. dd.navigateTo({
  85. url: '../moreE/moreE?data=' + JSON.stringify(data)
  86. })
  87. } else if (index == 5) {
  88. dd.navigateTo({
  89. url: '../noUser/noUser?list=' + JSON.stringify(this.data.result.rank.free_man)
  90. })
  91. } else if (index == 6) {
  92. openLink({
  93. url: 'https://h5.dingtalk.com/open-market/share.html?shareGoodsCode=D34E5A30A9AC7FC6327AB5E6D2D145418457E59F16C3FC969F1A50AEF2E5E320588012470F1AB045&token=d37751d45abad15178adf60f936d7c28&shareUid=C5EB7B5C85793F3D909B2AC4771E12D7'
  94. })
  95. } else if (index == 7) {
  96. let data = {
  97. type: 'week_statistics',
  98. employee_id: this.data.employee_id ? this.data.employee_id : app.globalData.userData.id,
  99. start_date: this.data.start ? this.data.start : this.data.thisweek.start_day,
  100. method: 'myTaskList',
  101. page_size: 1000,
  102. range: 'all'
  103. }
  104. dd.navigateTo({
  105. url: '../newspaperTask/newspaperTask?data=' + JSON.stringify(data)
  106. })
  107. } else if (index == 8) {
  108. let data = {
  109. type: 'week_statistics',
  110. employee_id: this.data.employee_id ? this.data.employee_id : app.globalData.userData.id,
  111. start_date: this.data.start ? this.data.start : this.data.thisweek.start_day,
  112. method: 'taskList',
  113. page_size: 1000,
  114. range: 'all'
  115. }
  116. dd.navigateTo({
  117. url: '../newspaperTask/newspaperTask?data=' + JSON.stringify(data)
  118. })
  119. }
  120. },
  121. setDate() {
  122. var thisweek = {};
  123. var date = new Date();
  124. // 本周一的日期
  125. date.setDate(date.getDate() - date.getDay() + 1);
  126. let month = (date.getMonth() + 1) < 10 ? '0' + (date.getMonth() + 1) : (date.getMonth() + 1)
  127. let getDate = date.getDate() < 10 ? '0' + (date.getDate()) : date.getDate()
  128. thisweek.start_day = date.getFullYear() + "-" + month + "-" + getDate;
  129. // 本周日的日期
  130. date.setDate(date.getDate() + 6);
  131. let month2 = (date.getMonth() + 1) < 10 ? '0' + (date.getMonth() + 1) : (date.getMonth() + 1)
  132. let getDate2 = date.getDate() < 10 ? '0' + (date.getDate()) : date.getDate()
  133. thisweek.end_day = date.getFullYear() + "-" + month2 + "-" + getDate2;
  134. this.setData({
  135. thisweek: thisweek
  136. })
  137. },
  138. // 页面被关闭
  139. onUnload() {
  140. app.globalData.socketApi.closewebsocket();
  141. },
  142. opneWebSocket() {
  143. let data = {
  144. type: 'week_statistics',
  145. employee_id: this.data.employee_id ? this.data.employee_id : app.globalData.userData.id,
  146. start_date: this.data.start ? this.data.start : this.data.thisweek.start_day
  147. }
  148. app.globalData.socketApi.sendData(data, this.onmessageWS);
  149. },
  150. onmessageWS(e) {
  151. // 因为作用域问题,这个函数不能使用this
  152. if (e.type == 'week_statistics' && e.msg == 'all') {
  153. let result = e.result
  154. that.setData({
  155. result: result
  156. })
  157. // app.globalData.socketApi.closewebsocket();
  158. }
  159. }
  160. });