report.js 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  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. start: 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. getTime(n) {
  122. var now = new Date();
  123. var year = now.getFullYear();
  124. //因为月份是从0开始的,所以获取这个月的月份数要加1才行
  125. var month = now.getMonth() + 1;
  126. var date = now.getDate();
  127. var day = now.getDay();
  128. console.log(date);
  129. //判断是否为周日,如果不是的话,就让今天的day-1(例如星期二就是2-1)
  130. if (day !== 0) {
  131. n = n + (day - 1);
  132. } else {
  133. n = n + day;
  134. }
  135. if (day) {
  136. //这个判断是为了解决跨年的问题
  137. if (month > 1) {
  138. month = month;
  139. }
  140. //这个判断是为了解决跨年的问题,月份是从0开始的
  141. else {
  142. year = year - 1;
  143. month = 12;
  144. }
  145. }
  146. now.setDate(now.getDate() - n);
  147. year = now.getFullYear();
  148. month = now.getMonth() + 1;
  149. date = now.getDate();
  150. // console.log(n);
  151. var s = year + "-" + (month < 10 ? ('0' + month) : month) + "-" + (date < 10 ? ('0' + date) : date);
  152. return s;
  153. },
  154. setDate() {
  155. this.setData({
  156. thisweek: {
  157. start_day:this.getTime(7),
  158. end_day:this.getTime(7)
  159. }
  160. })
  161. return false
  162. var thisweek = {};
  163. var date = new Date();
  164. // 本周一的日期
  165. date.setDate(date.getDate() - date.getDay() + 1);
  166. let month = (date.getMonth() + 1) < 10 ? '0' + (date.getMonth() + 1) : (date.getMonth() + 1)
  167. let getDate = date.getDate() < 10 ? '0' + (date.getDate()) : date.getDate()
  168. thisweek.start_day = date.getFullYear() + "-" + month + "-" + getDate;
  169. // 本周日的日期
  170. date.setDate(date.getDate() + 6);
  171. let month2 = (date.getMonth() + 1) < 10 ? '0' + (date.getMonth() + 1) : (date.getMonth() + 1)
  172. let getDate2 = date.getDate() < 10 ? '0' + (date.getDate()) : date.getDate()
  173. thisweek.end_day = date.getFullYear() + "-" + month2 + "-" + getDate2;
  174. this.setData({
  175. thisweek: thisweek
  176. })
  177. },
  178. // 页面被关闭
  179. onUnload() {
  180. app.globalData.socketApi.closewebsocket();
  181. },
  182. opneWebSocket() {
  183. let data = {
  184. type: 'week_statistics',
  185. employee_id: this.data.employee_id ? this.data.employee_id : app.globalData.userData.id,
  186. start_date: this.data.start ? this.data.start : this.data.thisweek.start_day
  187. }
  188. app.globalData.socketApi.sendData(data, this.onmessageWS);
  189. },
  190. onmessageWS(e) {
  191. // 因为作用域问题,这个函数不能使用this
  192. if (e.type == 'week_statistics' && e.msg == 'all') {
  193. let result = e.result
  194. that.setData({
  195. result: result
  196. })
  197. // app.globalData.socketApi.closewebsocket();
  198. }
  199. }
  200. });