workDetail.js 6.2 KB

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