taskDetail.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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. },
  15. onLoad(e) {
  16. that = this;
  17. dd.setNavigationBar({ title: "任务详情" });
  18. this.setData({
  19. isCreator: app.globalData.isCreator,
  20. date:moment().format('YYYY-MM-DD HH:mm')
  21. })
  22. console.log(this.data.date)
  23. if (e.id) {
  24. // that.getDetail(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. onShareAppMessage() {
  52. return {
  53. title: '任务详情',
  54. desc:'积分任务:'+ this.data.dataDetail.task_name,
  55. path: 'pages/statistics/taskDetail/taskDetail?id=' + this.data.id
  56. };
  57. },
  58. bindPickerChange(e) {
  59. if (this.data.array[e.detail.value] == '删除任务') {
  60. dd.confirm({
  61. title: '删除任务',
  62. content: '删除此任务将会删除其相关记录和积分数据,确认删除吗?',
  63. confirmButtonText: '确定',
  64. cancelButtonText: '取消',
  65. success: (result) => {
  66. if (result.confirm) {
  67. app.$get("api/integral/task/delete", { task_id: this.data.id }).then((res) => {
  68. app.globalData.showToast(res.data.msg);
  69. setTimeout(() => {
  70. dd.navigateBack({ delta: 1 })
  71. }, 1000);
  72. })
  73. }
  74. },
  75. });
  76. } else if (this.data.array[e.detail.value] == '编辑任务') {//编辑任务
  77. dd.navigateTo({
  78. url: '../offerAreward_set/offerAreward_set?item=' + JSON.stringify(this.data.dataDetail)
  79. })
  80. }
  81. },
  82. //领取任务
  83. formSubmit() {
  84. app.$post("api/integral/task", { task_id: this.data.dataDetail.id }).then((res) => {
  85. app.globalData.showToast('已领取');
  86. setTimeout(() => {
  87. dd.navigateBack({ delta: 1 })
  88. }, 1000);
  89. })
  90. },
  91. //显示图片
  92. showImg(e) {
  93. var index = e.target.dataset.index;
  94. var item = e.target.dataset.item
  95. dd.previewImage({
  96. current: index,
  97. urls: item
  98. });
  99. },
  100. activeItem(e) {
  101. var index = e.target.dataset.index;
  102. this.setData({ activeIndex: index })
  103. },
  104. openSearch() {
  105. app.globalData.showToast("暂不支持筛选");
  106. },
  107. getDetail(id, func = function () { }) {
  108. app.$get("api/integral/task", { task_id: id }).then((res) => {
  109. func();
  110. var data = res.data.data;
  111. data.pt_name = app.getTypesItem(data.pt_id).name;
  112. if (data.status == 1 && data.status_mark == '待领取') {
  113. this.setData({
  114. array: ['编辑任务', '删除任务'],
  115. })
  116. } else {
  117. this.setData({
  118. array: ['删除任务'],
  119. })
  120. }
  121. this.setData({
  122. dataDetail: data,
  123. isPublisher: data.owner_id == this.data.userId ? true : false
  124. })
  125. })
  126. },
  127. openSchedule() {
  128. dd.navigateTo({
  129. url: '../schedule/schedule'
  130. })
  131. },
  132. });