| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229 |
- <template>
- <view class="ai-task-card">
- <view class="card-header">
- <text class="card-title">{{ task.title }}</text>
- <view class="dimension-badge" :style="{ backgroundColor: dimensionColor }">
- <text class="dimension-text">{{ task.dimension }}</text>
- </view>
- </view>
- <view class="card-body">
- <text class="card-description">{{ task.description }}</text>
- </view>
- <view class="card-footer">
- <view class="reward-info">
- <text class="reward-label">奖励能量</text>
- <text class="reward-points">+{{ task.rewardPoints }}</text>
- </view>
- <button
- class="accept-btn"
- :loading="loading"
- :disabled="loading"
- @click="handleAccept"
- >
- <text class="btn-text">{{ loading ? '接受中...' : '接受任务' }}</text>
- </button>
- </view>
- </view>
- </template>
- <script>
- export default {
- name: 'TaskCard',
- props: {
- task: {
- type: Object,
- default: function() {
- return {
- title: '',
- description: '',
- dimension: '',
- rewardPoints: 0,
- id: null
- }
- }
- },
- conversationId: {
- type: String,
- default: ''
- }
- },
- data: function() {
- return {
- loading: false
- }
- },
- computed: {
- dimensionColor: function() {
- var colorMap = {
- '身': '#10B981',
- '心': '#F59E0B',
- '智': '#3B82F6',
- '行': '#8B5CF6',
- '富': '#F97316'
- }
- return colorMap[this.task.dimension] || '#F97316'
- }
- },
- methods: {
- handleAccept: function() {
- var self = this
- if (self.loading) {
- return
- }
- var token = uni.getStorageSync('token')
- if (!token) {
- uni.showToast({
- title: '请先登录',
- icon: 'none'
- })
- return
- }
- self.loading = true
- uni.request({
- url: self.$apiBase + '/api/growth-task/accept-dynamic',
- method: 'POST',
- header: {
- 'Authorization': 'Bearer ' + token,
- 'Content-Type': 'application/json'
- },
- data: {
- taskId: self.task.id,
- conversationId: self.conversationId
- },
- success: function(res) {
- if (res.statusCode === 200 && res.data && res.data.code === 200) {
- uni.showToast({
- title: '任务已接受',
- icon: 'success'
- })
- self.$emit('accepted', self.task)
- } else {
- var message = (res.data && res.data.message) || '接受失败'
- uni.showToast({
- title: message,
- icon: 'none'
- })
- }
- },
- fail: function() {
- uni.showToast({
- title: '网络请求失败',
- icon: 'none'
- })
- },
- complete: function() {
- self.loading = false
- }
- })
- }
- }
- }
- </script>
- <style scoped>
- .ai-task-card {
- background-color: #FFFFFF;
- border-radius: 16rpx;
- padding: 32rpx;
- margin: 24rpx;
- box-shadow: 0 4rpx 16rpx rgba(0, 0, 0, 0.06);
- }
- .card-header {
- display: flex;
- flex-direction: row;
- justify-content: space-between;
- align-items: center;
- margin-bottom: 24rpx;
- }
- .card-title {
- font-size: 32rpx;
- font-weight: 600;
- color: #1F2937;
- flex: 1;
- margin-right: 16rpx;
- }
- .dimension-badge {
- padding: 8rpx 20rpx;
- border-radius: 24rpx;
- flex-shrink: 0;
- }
- .dimension-text {
- font-size: 24rpx;
- font-weight: 500;
- color: #FFFFFF;
- }
- .card-body {
- margin-bottom: 32rpx;
- }
- .card-description {
- font-size: 28rpx;
- color: #6B7280;
- line-height: 44rpx;
- }
- .card-footer {
- display: flex;
- flex-direction: row;
- justify-content: space-between;
- align-items: center;
- padding-top: 24rpx;
- border-top: 1rpx solid #F3F4F6;
- }
- .reward-info {
- display: flex;
- flex-direction: row;
- align-items: center;
- }
- .reward-label {
- font-size: 26rpx;
- color: #9CA3AF;
- margin-right: 12rpx;
- }
- .reward-points {
- font-size: 32rpx;
- font-weight: 700;
- color: #F97316;
- }
- .accept-btn {
- background-color: #F97316;
- color: #FFFFFF;
- border: none;
- border-radius: 12rpx;
- padding: 20rpx 40rpx;
- font-size: 28rpx;
- font-weight: 500;
- line-height: 1.2;
- }
- .accept-btn:active {
- background-color: #EA580C;
- }
- .accept-btn:disabled {
- background-color: #FDBA74;
- }
- .btn-text {
- color: #FFFFFF;
- }
- </style>
|