taskSList.js 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. var app = getApp()
  2. var that;
  3. Page({
  4. data: {
  5. list: [],
  6. parameter:{},
  7. isData:true,
  8. },
  9. onLoad(e) {
  10. that = this;
  11. this.setData({
  12. parameter: JSON.parse(e.data),
  13. })
  14. if(this.data.parameter.index=='1'){
  15. dd.setNavigationBar({ title: "逾期任务" });
  16. }else if(this.data.parameter.index=='2'){
  17. dd.setNavigationBar({ title: "今日任务" });
  18. }else if(this.data.parameter.index=='3'){
  19. dd.setNavigationBar({ title: "进行中任务" });
  20. }else{
  21. dd.setNavigationBar({ title: "待审批任务" });
  22. }
  23. },
  24. onShow() {
  25. if(this.data.parameter.page==1){
  26. this.opneWebSocket();
  27. }
  28. },
  29. activeA(e){
  30. let item = e.target.dataset.item;
  31. let text='';
  32. let users=[];
  33. if(this.data.parameter.index=='1'){//拿执行者ID
  34. users.push(item.receiver.ding_user.user_id)
  35. text=`积分任务【 ${item.task_name} 】已经逾期啦,请尽快完成`
  36. }
  37. if(this.data.parameter.index=='4'){//拿审批者ID
  38. users.push(item.reviewer_ding_info.user_id)
  39. text=`${item.receiver.name}的积分任务【 ${item.task_name} 】还未审批,请及时处理`
  40. }
  41. dd.createDing({
  42. users: users, //默认选中用户工号列表;类型: Array<String>
  43. corpId: app.globalData.corpId, // 类型: String
  44. alertType: 2, // 钉发送方式 0:电话, 1:短信, 2:应用内;类型 Number
  45. alertDate: {"format":"yyyy-MM-dd HH:mm", "value":"2019-08-29 08:25"}, // 非必选,定时发送时间, 非定时DING不需要填写
  46. type: 1,// 附件类型 1:image, 2:link;类型: Number
  47. // 非必选
  48. // 附件信息
  49. // attachment: {
  50. // images: ["https://www.baidu.com/img/bd_logo1.png?where=super"], // 图片附件, type=1时, 必选;类型: Array<String>
  51. // image: "https://www.baidu.com/img/bd_logo1.png?where=super", // 链接附件, type=2时, 必选;类型: String
  52. // title: "这是一个测试", // 链接附件, type=2时, 必选;类型: String
  53. // url: "https://www.baidu.com/", // 链接附件, type=2时, 必选;类型 String
  54. // text: "测试发钉成功" // 链接附件, type=2时, 必选;类型: String
  55. // },
  56. text: text, // 正文
  57. bizType :0, // 业务类型 0:通知DING;1:任务;2:会议;
  58. // 任务信息
  59. // bizType=1的时候选填
  60. taskInfo: {
  61. ccUsers: ['100', '101'],// 抄送用户列表, 工号,类型: Array<String>
  62. deadlineTime: {"format":"yyyy-MM-dd HH:mm", "value":"2015-05-09 08:00"}, // 任务截止时间
  63. taskRemind: 30 // 任务提醒时间, 单位分钟;支持参数: 0:不提醒;15:提前15分钟;60:提前1个小时;180:提前3个小时;1440:提前一天;类型: Number
  64. },
  65. // 日程信息
  66. // bizType=2的时候选填
  67. confInfo: {
  68. bizSubType: 0, // 子业务类型如会议: 0:预约会议, 1:预约电话会议, 2:预约视频会议;类型: Number (注: 目前只有会议才有子业务类型);
  69. location: '某某会议室', // 会议地点(非必选),类型: String
  70. startTime: {"format":"yyyy-MM-dd HH:mm", "value":"2015-05-09 08:00"},// 会议开始时间
  71. endTime: {"format":"yyyy-MM-dd HH:mm", "value":"2015-05-09 08:00"},// 会议结束时间
  72. remindMinutes: 30, // 会前提醒。单位分钟;1:不提醒, 0:事件发生时提醒, 5:提前5分钟, 15:提前15分钟, 30:提前30分钟, 60:提前1个小时, 1440:提前一天
  73. remindType: 2 // 会议提前提醒方式;0:电话, 1:短信, 2:应用内;类型: Number
  74. },
  75. success:function(res){
  76. /*
  77. {
  78. "dingId": "1_1_a09f167xxx",
  79. "text": "钉正文内容",
  80. "result": true
  81. }
  82. */
  83. },
  84. fail:function(err){
  85. }
  86. })
  87. },
  88. //上啦加载
  89. onScrollToLower() {
  90. if (that.data.isData) {
  91. this.setData({
  92. 'parameter.page':++this.data.parameter.page
  93. })
  94. this.opneWebSocket();
  95. }
  96. },
  97. opneWebSocket() {
  98. dd.showLoading({
  99. content: '加载中...',
  100. });
  101. setTimeout(() => {
  102. dd.hideLoading();
  103. }, 600)
  104. app.globalData.socketApi.sendData(this.data.parameter, this.onmessageWS);
  105. },
  106. onmessageWS(e) {
  107. // 因为作用域问题,这个函数不能使用this
  108. if (e.type == 'task_statistics') {
  109. let result = e.result
  110. result.map(item => {
  111. item.date = that.timestampToTime(item.expire_time);
  112. item.pt_name=item.pt_id==3? 'B分':'A分'
  113. item.sub= that.formatSeconds(item.sub);
  114. })
  115. // console.log(result)
  116. var list = that.data.list || [];
  117. that.setData({
  118. list:that.data.parameter.page=='1'?result:list.concat(result),
  119. isData:result.length<100? false:true,
  120. })
  121. }
  122. },
  123. formatSeconds(value) {
  124. var theTime = parseInt(value);// 需要转换的时间秒
  125. var theTime1 = 0;// 分
  126. var theTime2 = 0;// 小时
  127. var theTime3 = 0;// 天
  128. if(theTime > 60) {
  129. theTime1 = parseInt(theTime/60);
  130. theTime = parseInt(theTime%60);
  131. if(theTime1 > 60) {
  132. theTime2 = parseInt(theTime1/60);
  133. theTime1 = parseInt(theTime1%60);
  134. if(theTime2 > 24){
  135. //大于24小时
  136. theTime3 = parseInt(theTime2/24);
  137. theTime2 = parseInt(theTime2%24);
  138. }
  139. }
  140. }
  141. var result = '';
  142. // if(theTime > 0){
  143. // result = ""+parseInt(theTime)+"秒";
  144. // }
  145. // if(theTime1 > 0) {
  146. // result = ""+parseInt(theTime1)+"分"+result;
  147. // }
  148. if(theTime2 > 0) {
  149. result = ""+parseInt(theTime2)+"小时"+result;
  150. }
  151. if(theTime3 > 0) {
  152. result = ""+parseInt(theTime3)+"天";
  153. }
  154. return result;
  155. },
  156. timestampToTime(timestamp) {
  157. var date = new Date(timestamp * 1000);//时间戳为10位需*1000,时间戳为13位的话不需乘1000
  158. var Y = date.getFullYear() + '-';
  159. var M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '-';
  160. var D = date.getDate() + ' ';
  161. var h = date.getHours() + ':';
  162. var m = date.getMinutes() + ':';
  163. var s = date.getSeconds();
  164. // return Y + M + D + h + m + s;
  165. return Y + M + D;
  166. },
  167. activeItem(e) {
  168. var index = Number(e.detail.value)+1;
  169. var status = "";
  170. if (index == 1) {
  171. status = "all"
  172. } else if (index == 2) {
  173. status = "on_time"
  174. } else if (index == 3) {
  175. status = "before"
  176. }else{
  177. status = "over_due"
  178. }
  179. this.setData({
  180. minuteIndex: e.detail.value,
  181. [`parameter.range`]:status
  182. })
  183. // console.log(this.data.parameter)
  184. this.opneWebSocket()
  185. },
  186. openDetail(e) {
  187. var id = e.target.dataset.item.id;
  188. dd.navigateTo({
  189. url: '../../statistics/workDetail/workDetail?id=' + id
  190. })
  191. },
  192. });