taskDetail.js 4.3 KB

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