taskDetail.js 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. var app = getApp()
  2. var that;
  3. Page({
  4. data: {
  5. date: app.globalData.month,
  6. activeIndex: 1,
  7. array: ['编辑任务', '删除任务'],
  8. isPublisher: true,//是不是发布者
  9. userId: '',
  10. id: '',
  11. isCreator: false,
  12. },
  13. onLoad(e) {
  14. that = this;
  15. dd.setNavigationBar({ title: "任务详情" });
  16. this.setData({
  17. isCreator: app.globalData.isCreator
  18. })
  19. if (e.id) {
  20. // that.getDetail(e.id);
  21. this.setData({
  22. id: e.id,
  23. userId: app.globalData.userData.id
  24. })
  25. }
  26. },
  27. onShow() {
  28. if (app.globalData.userData) {
  29. dd.hideLoading();
  30. that.getDetail(that.data.id);
  31. } else {
  32. app.login(app.globalData.corpId, function (is) {
  33. if (is) {
  34. dd.hideLoading();
  35. that.setData({
  36. userId: app.globalData.userData.id
  37. })
  38. that.getDetail(that.data.id);
  39. } else {
  40. dd.reLaunch({
  41. url: '../../noJurisdiction/noJurisdiction'
  42. })
  43. }
  44. }, function () { })
  45. }
  46. },
  47. onShareAppMessage() {
  48. return {
  49. title: '任务详情',
  50. desc:'积分任务:'+ this.data.dataDetail.task_name,
  51. path: 'pages/statistics/taskDetail/taskDetail?id=' + this.data.id
  52. };
  53. },
  54. bindPickerChange(e) {
  55. if (this.data.array[e.detail.value] == '删除任务') {
  56. dd.confirm({
  57. title: '删除任务',
  58. content: '删除此任务将会删除其相关记录和积分数据,确认删除吗?',
  59. confirmButtonText: '确定',
  60. cancelButtonText: '取消',
  61. success: (result) => {
  62. if (result.confirm) {
  63. app.$get("api/integral/task/delete", { task_id: this.data.id }).then((res) => {
  64. app.globalData.showToast(res.data.msg);
  65. setTimeout(() => {
  66. dd.navigateBack({ delta: 1 })
  67. }, 1000);
  68. })
  69. }
  70. },
  71. });
  72. } else if (this.data.array[e.detail.value] == '编辑任务') {//编辑任务
  73. dd.navigateTo({
  74. url: '../offerAreward_set/offerAreward_set?item=' + JSON.stringify(this.data.dataDetail)
  75. })
  76. }
  77. },
  78. //领取任务
  79. formSubmit() {
  80. app.$post("api/integral/task", { task_id: this.data.dataDetail.id }).then((res) => {
  81. app.globalData.showToast('已领取');
  82. setTimeout(() => {
  83. dd.navigateBack({ delta: 1 })
  84. }, 1000);
  85. })
  86. },
  87. //显示图片
  88. showImg(e) {
  89. var index = e.target.dataset.index;
  90. var item = e.target.dataset.item
  91. dd.previewImage({
  92. current: index,
  93. urls: item
  94. });
  95. },
  96. activeItem(e) {
  97. var index = e.target.dataset.index;
  98. this.setData({ activeIndex: index })
  99. },
  100. openSearch() {
  101. app.globalData.showToast("暂不支持筛选");
  102. },
  103. getDetail(id, func = function () { }) {
  104. app.$get("api/integral/task", { task_id: id }).then((res) => {
  105. func();
  106. var data = res.data.data;
  107. data.pt_name = app.getTypesItem(data.pt_id).name;
  108. if (data.status == 1 && data.status_mark == '待领取') {
  109. this.setData({
  110. array: ['编辑任务', '删除任务'],
  111. })
  112. } else {
  113. this.setData({
  114. array: ['删除任务'],
  115. })
  116. }
  117. this.setData({
  118. dataDetail: data,
  119. isPublisher: data.owner_id == this.data.userId ? true : false
  120. })
  121. })
  122. },
  123. openSchedule() {
  124. dd.navigateTo({
  125. url: '../schedule/schedule'
  126. })
  127. },
  128. });