taskSList.js 7.2 KB

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