workDetail.js 6.6 KB

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