TaskDialog.vue 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. <template>
  2. <custom-dialog :visible="visible" title="" content-width="720rpx" background-color="transparent" closeImg="/static/island/UI/btn_close.png" closeImgTop="0rpx" @close="onClose">
  3. <view class="task-board">
  4. <view class="board-title">
  5. <view class="title-dot"></view>
  6. <text>任务看板</text>
  7. <view class="title-dot"></view>
  8. </view>
  9. <view class="task-cards-container">
  10. <view v-for="(task, index) in tasks" :key="index" class="task-card">
  11. <view class="task-header">
  12. <text class="task-label">任务目标:</text>
  13. <text class="task-content">{{task.name}}</text>
  14. </view>
  15. <view class="task-desc">
  16. <text class="task-label">任务描述:</text>
  17. <text class="task-content">{{task.content}}</text>
  18. </view>
  19. <view class="task-rewards">
  20. <text class="task-label">任务奖励:</text>
  21. <view class="reward-list">
  22. <view v-for="(prize, pIndex) in task.prize_list" :key="pIndex" class="reward-item">
  23. <view class="reward-box">
  24. <image :src="prize.shop.image || '/static/island/items/default.png'" class="reward-icon"></image>
  25. </view>
  26. <text class="reward-text">{{prize.shop.name.length > 3 ? prize.shop.name.substring(0, 3) + '' : prize.shop.name}}x{{ prize.num }}</text>
  27. </view>
  28. </view>
  29. </view>
  30. <view class="task-footer">
  31. <text class="task-date">{{task.create_time}}</text>
  32. <view
  33. :class="['task-button', task.state === 1 ? 'completed' : 'uncompleted']"
  34. @click="handleTaskAction(task)"
  35. >
  36. {{task.state === 1 ? '已完成' : '未完成'}}
  37. </view>
  38. </view>
  39. <view class="card-divider"></view>
  40. </view>
  41. </view>
  42. </view>
  43. </custom-dialog>
  44. </template>
  45. <script>
  46. import CustomDialog from '@/components/CustomDialog/CustomDialog.vue'
  47. export default {
  48. name: 'TaskDialog',
  49. components: {
  50. CustomDialog
  51. },
  52. props: {
  53. visible: {
  54. type: Boolean,
  55. default: false
  56. },
  57. type: {
  58. type: String,
  59. default: 'main'
  60. }
  61. },
  62. data() {
  63. return {
  64. tasks: [],
  65. loading: false
  66. }
  67. },
  68. watch: {
  69. visible(val) {
  70. if (val) {
  71. this.fetchTaskData()
  72. }
  73. }
  74. },
  75. methods: {
  76. onClose() {
  77. this.$emit('close')
  78. },
  79. // 获取任务数据
  80. async fetchTaskData() {
  81. if (this.loading) return
  82. this.loading = true
  83. try {
  84. uni.request({
  85. url: this.$apiHost + '/Game/get_task_list',
  86. method: 'GET',
  87. data: {
  88. uuid: getApp().globalData.uuid,
  89. type: this.type
  90. },
  91. header: {
  92. 'Content-Type': 'application/x-www-form-urlencoded',
  93. 'sign': getApp().globalData.headerSign,
  94. },
  95. success: (res) => {
  96. console.log("任务数据:", res.data)
  97. if (res.data && res.data.code === 0) {
  98. this.tasks = res.data.list || []
  99. } else {
  100. uni.showToast({
  101. title: res.data?.msg || '获取任务数据失败',
  102. icon: 'none'
  103. })
  104. }
  105. },
  106. fail: (err) => {
  107. console.error('获取任务数据异常', err)
  108. uni.showToast({
  109. title: '网络异常,请重试',
  110. icon: 'none'
  111. })
  112. },
  113. complete: () => {
  114. this.loading = false
  115. }
  116. })
  117. } catch (error) {
  118. console.error('获取任务数据异常', error)
  119. uni.showToast({
  120. title: '网络异常,请重试',
  121. icon: 'none'
  122. })
  123. this.loading = false
  124. }
  125. },
  126. handleTaskAction(task) {
  127. if (task.state === 1) {
  128. // 处理已完成任务的逻辑
  129. uni.showToast({
  130. title: '任务已完成!',
  131. icon: 'success'
  132. })
  133. } else {
  134. // 处理未完成任务的逻辑
  135. uni.showToast({
  136. title: '任务未完成',
  137. icon: 'none'
  138. })
  139. }
  140. }
  141. }
  142. }
  143. </script>
  144. <style lang="scss">
  145. @import './TaskDialog.scss';
  146. </style>