taskDetail.js 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  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. array: ['编辑任务', '删除任务'],
  9. isPublisher: true,//是不是发布者
  10. userId: '',
  11. id: '',
  12. isCreator: false,
  13. date:'',
  14. works:[],
  15. },
  16. onLoad(e) {
  17. that = this;
  18. dd.setNavigationBar({ title: "抢单详情" });
  19. this.setData({
  20. isCreator: app.globalData.isCreator,
  21. date:moment().format('YYYY-MM-DD HH:mm')
  22. })
  23. if (e.id) {
  24. this.setData({
  25. id: e.id,
  26. userId: app.globalData.userData.id
  27. })
  28. }
  29. },
  30. onShow() {
  31. if (app.globalData.userData) {
  32. dd.hideLoading();
  33. that.getDetail(that.data.id);
  34. } else {
  35. app.login(app.globalData.corpId, function (is) {
  36. if (is) {
  37. dd.hideLoading();
  38. that.setData({
  39. userId: app.globalData.userData.id
  40. })
  41. that.getDetail(that.data.id);
  42. } else {
  43. dd.reLaunch({
  44. url: '../../noJurisdiction/noJurisdiction'
  45. })
  46. }
  47. }, function () { })
  48. }
  49. },
  50. openUser(){
  51. dd.navigateTo({
  52. url: '../userList/userList?list=' + JSON.stringify(this.data.works)
  53. })
  54. },
  55. onShareAppMessage() {
  56. return {
  57. title: '任务详情',
  58. desc:'积分任务:'+ this.data.dataDetail.task_name,
  59. path: 'pages/statistics/taskDetail/taskDetail?id=' + this.data.id
  60. };
  61. },
  62. bindPickerChange(e) {
  63. if (this.data.array[e.detail.value] == '删除任务') {
  64. dd.confirm({
  65. title: '删除任务',
  66. content: '删除此任务将会删除其相关记录和积分数据,确认删除吗?',
  67. confirmButtonText: '确定',
  68. cancelButtonText: '取消',
  69. success: (result) => {
  70. if (result.confirm) {
  71. app.$get("api/integral/task/delete", { task_id: this.data.id }).then((res) => {
  72. app.globalData.showToast(res.data.msg);
  73. setTimeout(() => {
  74. dd.navigateBack({ delta: 1 })
  75. }, 1000);
  76. })
  77. }
  78. },
  79. });
  80. } else if (this.data.array[e.detail.value] == '编辑任务') {//编辑任务
  81. dd.navigateTo({
  82. url: '../offerAreward_set/offerAreward_set?item=' + JSON.stringify(this.data.dataDetail)
  83. })
  84. }
  85. },
  86. //抢任务
  87. formSubmit() {
  88. this.setData({ disabled: true })
  89. app.$post('/api/integral/task/exist',{task_id:this.data.dataDetail.id}).then(res => {
  90. let exist=res.data.data.exist
  91. if(exist){
  92. that.setData({ disabled: false })
  93. app.globalData.showToast("你已经抢到该任务了,请前往【我抢到的】查看");
  94. }else{
  95. app.$post("api/integral/task", { task_id: this.data.dataDetail.id }).then((res) => {
  96. app.globalData.showToast('抢单成功!');
  97. setTimeout(() => {
  98. dd.navigateBack({ delta: 1 })
  99. }, 1000);
  100. }).finally(() => {
  101. that.setData({ disabled: false })
  102. });
  103. }
  104. })
  105. },
  106. //显示图片
  107. showImg(e) {
  108. var index = e.target.dataset.index;
  109. var item = e.target.dataset.item
  110. dd.previewImage({
  111. current: index,
  112. urls: item
  113. });
  114. },
  115. activeItem(e) {
  116. var index = e.target.dataset.index;
  117. this.setData({ activeIndex: index })
  118. },
  119. getDetail(id, func = function () { }) {
  120. app.$get("api/integral/task", { task_id: id }).then((res) => {
  121. func();
  122. var data = res.data.data;
  123. data.pt_name = app.getTypesItem(data.pt_id).name;
  124. if (data.composite_state==1&&data.total_chance == data.chance ) {
  125. this.setData({
  126. array: ['编辑任务', '删除任务'],
  127. })
  128. } else {
  129. this.setData({
  130. array: ['删除任务'],
  131. })
  132. }
  133. this.setData({
  134. dataDetail: data,
  135. works:data.works,
  136. isPublisher: data.owner_id == this.data.userId ? true : false
  137. })
  138. })
  139. },
  140. openSchedule() {
  141. dd.navigateTo({
  142. url: '../schedule/schedule'
  143. })
  144. },
  145. });