workDetail.js 5.4 KB

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