workDetail.js 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  1. var app = getApp()
  2. var that;
  3. import moment from 'moment' // 时间库
  4. Page({
  5. data: {
  6. date: app.globalData.month,
  7. activeIndex: 1,
  8. id: '',
  9. userId: '',
  10. process: [],
  11. array: ['编辑任务', '删除任务'],
  12. isPublisher: true,//是不是发布者
  13. corpId: '',
  14. isNot:false,
  15. keepTheScore:false,//是否展示记分
  16. },
  17. onLoad(e) {
  18. that = this;
  19. dd.setNavigationBar({ title: "任务详情" });
  20. if (e.id) {
  21. this.setData({
  22. id: parseInt(e.id),
  23. userId: app.globalData.userData.id,
  24. isNot:e.isNot?true:false,
  25. })
  26. }
  27. if (e.corpId) {
  28. that.setData({ corpId: e.corpId });
  29. app.globalData.corpId = e.corpId
  30. }
  31. },
  32. onShareAppMessage() {
  33. return {
  34. title: '积分任务-功道云积分制',
  35. desc: app.globalData.userData.name+'分享了任务:'+this.data.dataDetail.task_name,
  36. path: 'pages/statistics/workDetail/workDetail'
  37. };
  38. },
  39. onShow() {
  40. if (app.globalData.userData) {
  41. dd.hideLoading();
  42. that.getDetail(that.data.id);
  43. } else {
  44. let corpId = that.data.corpId ? that.data.corpId : app.globalData.corpId
  45. app.login(corpId, function (is) {
  46. if (is) {
  47. dd.hideLoading();
  48. that.setData({
  49. userId: app.globalData.userData.id
  50. })
  51. that.getDetail(that.data.id);
  52. } else {
  53. dd.reLaunch({
  54. url: '../../noJurisdiction/noJurisdiction'
  55. })
  56. }
  57. }, function () { })
  58. }
  59. },
  60. // 判断当前账号与发布工作者是否同一人;
  61. current_none(data) {
  62. var actions = []
  63. // 这里比较复杂,因为团队绩效的工作详情跟我的发布的工作详情都调用这个页面
  64. if (data.status == 1) {
  65. if (data.pt_id != 1) {
  66. actions.push('编辑任务')
  67. actions.push('删除任务')
  68. } else {
  69. actions.push('删除任务')
  70. }
  71. } else {
  72. actions.push('删除任务')
  73. }
  74. this.setData({ array: actions })
  75. },
  76. bindPickerChange(e) {
  77. var page = getCurrentPages()[getCurrentPages().length - 2]//上一个页面的数据
  78. if (this.data.array[e.detail.value] == '删除任务') {
  79. dd.confirm({
  80. title: '删除任务',
  81. content: '删除此任务将会删除其相关记录和积分数据,确认删除吗?',
  82. confirmButtonText: '确定',
  83. cancelButtonText: '取消',
  84. success: (result) => {
  85. if (result.confirm) {
  86. app.$get("api/integral/work/delete", { work_id: this.data.id }).then((res) => {
  87. app.globalData.showToast(res.data.msg);
  88. if (page) {
  89. page.filtrationList(2, this.data.id);
  90. setTimeout(() => {
  91. dd.navigateBack({ delta: 1 })
  92. }, 1000);
  93. } else {
  94. setTimeout(() => {
  95. dd.reLaunch({
  96. url: '/pages/workbench/index/index'
  97. })
  98. }, 1000);
  99. }
  100. })
  101. }
  102. },
  103. });
  104. } else if (this.data.array[e.detail.value] == '编辑任务') {//编辑任务
  105. dd.navigateTo({
  106. url: '../assaign_set/assaign_set?item=' + JSON.stringify(this.data.dataDetail)
  107. })
  108. }
  109. },
  110. //显示图片
  111. showImg(e) {
  112. var index = e.target.dataset.index;
  113. var item = e.target.dataset.item
  114. dd.previewImage({
  115. current: index,
  116. urls: item
  117. });
  118. },
  119. activeItem(e) {
  120. var index = e.target.dataset.index;
  121. this.setData({ activeIndex: index })
  122. },
  123. openReview(){
  124. dd.navigateTo({
  125. url: '../reviewsList/reviewsList?list=' + JSON.stringify(this.data.dataDetail.reviews)
  126. })
  127. },
  128. openJyt() {
  129. dd.navigateTo({
  130. url: '../workpoints/workpoints?item=' + JSON.stringify(this.data.process) + '&id=' + this.data.dataDetail.id + '&isJf=' + false
  131. })
  132. },
  133. openJf(e) {
  134. dd.navigateTo({
  135. url: '../workpoints/workpoints?item=' + JSON.stringify(this.data.process) + '&id=' + this.data.dataDetail.id + '&isJf=' + true
  136. })
  137. },
  138. employee_me(data){
  139. let params = {
  140. id: data.employee_id
  141. }
  142. app.$get('api/employee/info', params).then(res =>{
  143. this.setData({
  144. keepTheScore: this.keepTheScore(data,res.data.data)
  145. })
  146. })
  147. },
  148. keepTheScore(cer,data) {
  149. if(cer.status > 2){
  150. return false
  151. }
  152. if(this.data.userId == cer.reviewer_id){
  153. return true
  154. }
  155. return data.employee_detail.superior_list.some(x =>{
  156. if(this.data.userId == x.id){
  157. return true
  158. }
  159. })
  160. },
  161. deleteItem(e) {
  162. dd.confirm({
  163. title: '提示',
  164. content: '确定永久删除此项?',
  165. confirmButtonText: '确定',
  166. cancelButtonText: '取消',
  167. success: (result) => {
  168. if (result.confirm) {
  169. var index = e.target.dataset.index;
  170. var data = {
  171. work_id: this.data.id,
  172. process: this.data.process
  173. }
  174. data.process.splice(index, 1)
  175. if (data.process.length == 0) {
  176. data.process = "[1]"
  177. } else {
  178. data.process = JSON.stringify(data.process);
  179. }
  180. app.$post("api/integral/work", data).then((res) => {
  181. app.globalData.showToast(res.data.msg);
  182. this.getDetail(this.data.id);
  183. })
  184. }
  185. },
  186. });
  187. },
  188. getDetail(id, fun = function () { }) {
  189. this.setData({
  190. total: 0,
  191. process: []//清空数据,避免头像组件未刷新造成的视图问题
  192. })
  193. app.$get("api/integral/work", { work_id: id },'application/vnd.test.v2+json').then((res) => {
  194. fun();
  195. this.current_none(res.data.data)
  196. var process = res.data.data.process.list || [];
  197. var data = res.data.data;
  198. data.jf = [];
  199. data.gc = [];
  200. process.forEach(item => {
  201. if (item.recorder_id == data.publisher_id) {
  202. data.jf.push(item)
  203. } else {
  204. data.gc.push(item)
  205. }complete_task.time
  206. })
  207. if(data.complete_task.time){
  208. data.complete_task.time=moment(data.complete_task.time).format('YYYY-MM-DD HH:mm')
  209. }
  210. this.employee_me(data)
  211. this.setData({
  212. dataDetail: data,
  213. total: res.data.data.process.total,
  214. process: process,
  215. isPublisher: data.publisher_id == this.data.userId ? true : false,
  216. // keepTheScore: that.keepTheScore(data)
  217. })
  218. })
  219. },
  220. openWc() {
  221. console.log(this.data.dataDetail)
  222. // return false
  223. dd.navigateTo({
  224. url: '../../workbench/approve/approve?id=' + this.data.dataDetail.reviews.id
  225. })
  226. },
  227. // 完成任务
  228. openPerform() {
  229. dd.navigateTo({
  230. url: '../openPerform/openPerform?id=' + this.data.dataDetail.id + '&is=detail'
  231. })
  232. },
  233. openSchedule() {
  234. dd.navigateTo({
  235. url: '../schedule/schedule?id=' + this.data.dataDetail.id + "&progress=" + this.data.dataDetail.progress
  236. })
  237. },
  238. });