|
|
@@ -5,16 +5,16 @@
|
|
|
<view class="plot-info-card">
|
|
|
<view class="plot-header">
|
|
|
<text class="plot-name">{{ plotData.name }}</text>
|
|
|
- <text class="plot-area">{{ plotData.area }}亩</text>
|
|
|
+ <text class="plot-area">{{ plotData.size }}亩</text>
|
|
|
</view>
|
|
|
<view class="plot-details">
|
|
|
<view class="plot-item">
|
|
|
<text class="item-label">作物:</text>
|
|
|
- <text class="item-value">{{ plotData.crop }}</text>
|
|
|
+ <text class="item-value">{{ plotData.growCrops }}</text>
|
|
|
</view>
|
|
|
<view class="plot-item">
|
|
|
<text class="item-label">负责人:</text>
|
|
|
- <text class="item-value">{{ plotData.manager }}</text>
|
|
|
+ <text class="item-value">{{ plotData.managerName }}</text>
|
|
|
</view>
|
|
|
</view>
|
|
|
</view>
|
|
|
@@ -30,7 +30,7 @@
|
|
|
@click="switchStatus(status.value)"
|
|
|
>
|
|
|
<text>{{ status.label }}</text>
|
|
|
- <view class="badge" v-if="status.value === 'pending' && pendingTaskCount > 0">
|
|
|
+ <view class="badge" v-if="status.value === 0 && pendingTaskCount > 0">
|
|
|
{{ pendingTaskCount > 99 ? '99+' : pendingTaskCount }}
|
|
|
</view>
|
|
|
<view class="active-line" v-if="currentStatus === status.value"></view>
|
|
|
@@ -46,13 +46,15 @@
|
|
|
refresher-enabled
|
|
|
:refresher-triggered="isRefreshing">
|
|
|
<view class="task-list">
|
|
|
- <view class="task-card" v-for="(task, index) in taskList" :key="index" @click="viewTaskDetail(task)">
|
|
|
+ <view class="task-card" v-for="(task, index) in taskList" :key="task.id" @click="viewTaskDetail(task)">
|
|
|
<!-- 头部区域:任务名称和状态标签 -->
|
|
|
<view class="task-header">
|
|
|
- <view class="task-name">{{ task.name }}</view>
|
|
|
- <view class="task-status" :class="{ 'status-completed': task.status === 'completed' }">
|
|
|
- {{ task.status === 'pending' ? '待完成' : '已完成' }}
|
|
|
- </view>
|
|
|
+ <view class="task-name">{{ task.taskName }}</view>
|
|
|
+ <dict-tag
|
|
|
+ dict-type="task_status"
|
|
|
+ :value="task.taskStatus"
|
|
|
+ class="task-status-tag"
|
|
|
+ />
|
|
|
</view>
|
|
|
|
|
|
<!-- 信息行:类型、时间、责任人统一放在一行,类型在前 -->
|
|
|
@@ -60,19 +62,24 @@
|
|
|
<!-- 类型标签放在最左侧 -->
|
|
|
<view class="info-type">
|
|
|
<image src="/static/icons/task_icon.png" mode="aspectFit" class="info-icon"></image>
|
|
|
- <text class="info-text">{{ task.type }}</text>
|
|
|
+ <dict-tag
|
|
|
+ dict-type="task_type"
|
|
|
+ :value="task.typeName"
|
|
|
+ :colored="false"
|
|
|
+ class="info-type-tag"
|
|
|
+ />
|
|
|
</view>
|
|
|
|
|
|
<!-- 时间信息放在中间 -->
|
|
|
<view class="info-time">
|
|
|
<image src="/static/icons/clock_icon.png" mode="aspectFit" class="info-icon"></image>
|
|
|
- <text class="info-text">{{ task.executeTime }}</text>
|
|
|
+ <text class="info-text">{{ formatDate(task.executeTime) }}</text>
|
|
|
</view>
|
|
|
|
|
|
<!-- 责任人信息放在右侧 -->
|
|
|
<view class="info-person">
|
|
|
<image src="/static/icons/user.png" mode="aspectFit" class="info-icon"></image>
|
|
|
- <text class="info-text">{{ task.assignee }}</text>
|
|
|
+ <text class="info-text">{{ task.assigneeName || '未分配' }}</text>
|
|
|
</view>
|
|
|
</view>
|
|
|
|
|
|
@@ -107,20 +114,28 @@
|
|
|
</template>
|
|
|
|
|
|
<script>
|
|
|
+import storage from "@/utils/storage.js";
|
|
|
+import { getAgriculturalTasksList, countStatusTypeTasks } from '@/api/services/activity.js';
|
|
|
+import dictMixin from '@/utils/mixins/dictMixin';
|
|
|
+import DictTag from '@/components/common/dict-tag';
|
|
|
+
|
|
|
export default {
|
|
|
+ components: {
|
|
|
+ DictTag
|
|
|
+ },
|
|
|
+ mixins: [dictMixin],
|
|
|
data() {
|
|
|
return {
|
|
|
+ // 需要加载的字典类型
|
|
|
+ dictTypeList: ['task_type','task_status'],
|
|
|
+
|
|
|
// 地块数据
|
|
|
plotData: {
|
|
|
- id: 1,
|
|
|
- name: '东区水稻田',
|
|
|
- area: '128',
|
|
|
- crop: '水稻',
|
|
|
- manager: '张农夫'
|
|
|
+
|
|
|
},
|
|
|
|
|
|
// 待完成任务数
|
|
|
- pendingTaskCount: 5,
|
|
|
+ pendingTaskCount: 0,
|
|
|
|
|
|
// 当前筛选状态
|
|
|
currentStatus: 'all',
|
|
|
@@ -128,8 +143,8 @@ export default {
|
|
|
// 筛选相关数据
|
|
|
taskStatus: [
|
|
|
{ label: '全部', value: 'all' },
|
|
|
- { label: '待完成', value: 'pending' },
|
|
|
- { label: '已完成', value: 'completed' }
|
|
|
+ { label: '待完成', value: 0 },
|
|
|
+ { label: '已完成', value: 1 }
|
|
|
],
|
|
|
|
|
|
// 任务列表数据
|
|
|
@@ -137,173 +152,133 @@ export default {
|
|
|
isLoading: false,
|
|
|
isRefreshing: false,
|
|
|
noMoreData: false,
|
|
|
- page: 1,
|
|
|
+ pageNum: 1,
|
|
|
pageSize: 10,
|
|
|
-
|
|
|
- // 模拟任务数据
|
|
|
- mockTasks: [
|
|
|
- {
|
|
|
- id: 1,
|
|
|
- name: '水稻田施肥',
|
|
|
- type: '施肥',
|
|
|
- status: 'pending',
|
|
|
- executeTime: '2023-06-15',
|
|
|
- assignee: '李明',
|
|
|
- remark: '使用复合肥,每亩用量20kg',
|
|
|
- remarkExpanded: false
|
|
|
- },
|
|
|
- {
|
|
|
- id: 2,
|
|
|
- name: '病虫害防治喷药',
|
|
|
- type: '喷药',
|
|
|
- status: 'completed',
|
|
|
- executeTime: '2023-06-10',
|
|
|
- assignee: '王强',
|
|
|
- remark: '使用杀虫剂,注意安全防护',
|
|
|
- remarkExpanded: false
|
|
|
- },
|
|
|
- {
|
|
|
- id: 3,
|
|
|
- name: '早稻收割',
|
|
|
- type: '采摘',
|
|
|
- status: 'pending',
|
|
|
- executeTime: '2023-06-20',
|
|
|
- assignee: '张农夫',
|
|
|
- remark: '天气晴好时进行',
|
|
|
- remarkExpanded: false
|
|
|
- },
|
|
|
- {
|
|
|
- id: 4,
|
|
|
- name: '水渠疏通',
|
|
|
- type: '灌溉',
|
|
|
- status: 'pending',
|
|
|
- executeTime: '2023-06-12',
|
|
|
- assignee: '周华',
|
|
|
- remark: '',
|
|
|
- remarkExpanded: false
|
|
|
- },
|
|
|
- {
|
|
|
- id: 5,
|
|
|
- name: '田间除草',
|
|
|
- type: '除草',
|
|
|
- status: 'pending',
|
|
|
- executeTime: '2023-06-18',
|
|
|
- assignee: '刘艳',
|
|
|
- remark: '使用除草剂,避开雨天',
|
|
|
- remarkExpanded: false
|
|
|
- }
|
|
|
- ]
|
|
|
}
|
|
|
},
|
|
|
|
|
|
- components: {
|
|
|
- // No longer needed as we're using standard image icons
|
|
|
- },
|
|
|
-
|
|
|
methods: {
|
|
|
- // 根据任务类型返回颜色
|
|
|
- getTypeColor(type, mode = 'bg') {
|
|
|
- const colors = {
|
|
|
- '施肥': {
|
|
|
- bg: 'linear-gradient(135deg, rgba(59, 180, 74, 0.8), rgba(59, 180, 74, 0.6))',
|
|
|
- text: '#3BB44A'
|
|
|
- },
|
|
|
- '喷药': {
|
|
|
- bg: 'linear-gradient(135deg, rgba(255, 82, 82, 0.8), rgba(255, 82, 82, 0.6))',
|
|
|
- text: '#FF5252'
|
|
|
- },
|
|
|
- '灌溉': {
|
|
|
- bg: 'linear-gradient(135deg, rgba(64, 158, 255, 0.8), rgba(64, 158, 255, 0.6))',
|
|
|
- text: '#409EFF'
|
|
|
- },
|
|
|
- '采摘': {
|
|
|
- bg: 'linear-gradient(135deg, rgba(250, 173, 20, 0.8), rgba(250, 173, 20, 0.6))',
|
|
|
- text: '#FAAD14'
|
|
|
- },
|
|
|
- '播种': {
|
|
|
- bg: 'linear-gradient(135deg, rgba(121, 85, 72, 0.8), rgba(121, 85, 72, 0.6))',
|
|
|
- text: '#795548'
|
|
|
- },
|
|
|
- '除草': {
|
|
|
- bg: 'linear-gradient(135deg, rgba(156, 39, 176, 0.8), rgba(156, 39, 176, 0.6))',
|
|
|
- text: '#9C27B0'
|
|
|
- }
|
|
|
- };
|
|
|
+ // 格式化日期
|
|
|
+ formatDate(dateStr) {
|
|
|
+ if (!dateStr) return '';
|
|
|
|
|
|
- const defaultColor = {
|
|
|
- bg: 'linear-gradient(135deg, rgba(158, 158, 158, 0.8), rgba(158, 158, 158, 0.6))',
|
|
|
- text: '#909399'
|
|
|
- };
|
|
|
+ // 如果是时间戳,转换为日期对象
|
|
|
+ let date;
|
|
|
+ if (typeof dateStr === 'number') {
|
|
|
+ date = new Date(dateStr);
|
|
|
+ } else {
|
|
|
+ date = new Date(dateStr.replace(/-/g, '/'));
|
|
|
+ }
|
|
|
+
|
|
|
+ const year = date.getFullYear();
|
|
|
+ const month = String(date.getMonth() + 1).padStart(2, '0');
|
|
|
+ const day = String(date.getDate()).padStart(2, '0');
|
|
|
|
|
|
- return (colors[type] || defaultColor)[mode];
|
|
|
+ return `${year}-${month}-${day}`;
|
|
|
},
|
|
|
-
|
|
|
+
|
|
|
// 切换任务状态筛选
|
|
|
switchStatus(status) {
|
|
|
if (this.currentStatus === status) return;
|
|
|
|
|
|
this.currentStatus = status;
|
|
|
- this.page = 1;
|
|
|
+ this.pageNum = 1;
|
|
|
this.noMoreData = false;
|
|
|
this.loadTaskData();
|
|
|
},
|
|
|
|
|
|
// 加载任务数据
|
|
|
loadTaskData() {
|
|
|
+ this.plotData = JSON.parse(storage.getPlots() || '{}')
|
|
|
+ console.log("this.plotData",this.plotData);
|
|
|
this.isLoading = true;
|
|
|
|
|
|
- // 模拟API请求延迟
|
|
|
- setTimeout(() => {
|
|
|
- // 模拟筛选
|
|
|
- let filteredTasks = [...this.mockTasks];
|
|
|
-
|
|
|
- // 按状态筛选
|
|
|
- if (this.currentStatus !== 'all') {
|
|
|
- filteredTasks = filteredTasks.filter(task => task.status === this.currentStatus);
|
|
|
- }
|
|
|
-
|
|
|
- // 分页处理
|
|
|
- const start = (this.page - 1) * this.pageSize;
|
|
|
- const end = start + this.pageSize;
|
|
|
- const pageData = filteredTasks.slice(start, end);
|
|
|
-
|
|
|
- if (this.page === 1) {
|
|
|
- this.taskList = pageData;
|
|
|
+ // 构建查询参数
|
|
|
+ const params = {
|
|
|
+ pageNum: this.pageNum,
|
|
|
+ pageSize: this.pageSize,
|
|
|
+ plotId: this.plotData.id
|
|
|
+ };
|
|
|
+
|
|
|
+ // 如果不是查询全部,添加状态过滤条件
|
|
|
+ if (this.currentStatus !== 'all') {
|
|
|
+ params.taskStatus = this.currentStatus;
|
|
|
+ }
|
|
|
+
|
|
|
+ getAgriculturalTasksList(params).then(res => {
|
|
|
+ if (res.data.code === 200) {
|
|
|
+ const { rows, total } = res.data;
|
|
|
+
|
|
|
+ // 处理返回的数据
|
|
|
+ const tasks = rows.map(item => {
|
|
|
+ // 确保每个任务都有remarkExpanded属性
|
|
|
+ item.remarkExpanded = false;
|
|
|
+ return item;
|
|
|
+ });
|
|
|
+
|
|
|
+ if (this.pageNum === 1) {
|
|
|
+ this.taskList = tasks;
|
|
|
+ } else {
|
|
|
+ this.taskList = [...this.taskList, ...tasks];
|
|
|
+ }
|
|
|
+
|
|
|
+ // 判断是否还有更多数据
|
|
|
+ this.noMoreData = this.taskList.length >= total;
|
|
|
+
|
|
|
+ // 统计待完成任务数量
|
|
|
+ this.countPendingTasks();
|
|
|
} else {
|
|
|
- this.taskList = [...this.taskList, ...pageData];
|
|
|
+ uni.showToast({
|
|
|
+ title: res.data.msg || '获取任务列表失败',
|
|
|
+ icon: 'none'
|
|
|
+ });
|
|
|
}
|
|
|
-
|
|
|
- this.noMoreData = end >= filteredTasks.length;
|
|
|
+ }).catch(err => {
|
|
|
+ console.error('获取任务列表失败:', err);
|
|
|
+ uni.showToast({
|
|
|
+ title: '获取任务列表失败',
|
|
|
+ icon: 'none'
|
|
|
+ });
|
|
|
+ }).finally(() => {
|
|
|
this.isLoading = false;
|
|
|
this.isRefreshing = false;
|
|
|
-
|
|
|
- // 更新待完成任务数
|
|
|
- this.pendingTaskCount = this.mockTasks.filter(task => task.status === 'pending').length;
|
|
|
- }, 500);
|
|
|
+ });
|
|
|
+ },
|
|
|
+
|
|
|
+ // 统计待完成任务数量
|
|
|
+ countPendingTasks() {
|
|
|
+ // 如果当前已经是按状态筛选,直接使用当前列表长度
|
|
|
+ if (this.currentStatus === 'pending') {
|
|
|
+ this.pendingTaskCount = this.taskList.length;
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 否则,请求获取待完成任务数量
|
|
|
+ const params = {
|
|
|
+ plotId: this.plotData.id,
|
|
|
+ taskStatus: 0
|
|
|
+ };
|
|
|
+
|
|
|
+ countStatusTypeTasks(params).then(res => {
|
|
|
+ console.log("nongsh",res);
|
|
|
+ if (res.data.code === 200) {
|
|
|
+ this.pendingTaskCount = res.data.data || 0;
|
|
|
+ }
|
|
|
+ });
|
|
|
},
|
|
|
|
|
|
// 下拉刷新
|
|
|
refreshData(e) {
|
|
|
this.isRefreshing = true;
|
|
|
- this.page = 1;
|
|
|
+ this.pageNum = 1;
|
|
|
this.noMoreData = false;
|
|
|
-
|
|
|
- // 模拟API请求延迟
|
|
|
- setTimeout(() => {
|
|
|
- this.loadTaskData();
|
|
|
- // 显示刷新成功的提示
|
|
|
- uni.showToast({
|
|
|
- title: '刷新成功',
|
|
|
- icon: 'success',
|
|
|
- duration: 1000
|
|
|
- });
|
|
|
- }, 1000);
|
|
|
+ this.loadTaskData();
|
|
|
},
|
|
|
|
|
|
// 上拉加载更多
|
|
|
loadMore() {
|
|
|
if (!this.isLoading && !this.noMoreData) {
|
|
|
- this.page++;
|
|
|
+ this.pageNum++;
|
|
|
this.loadTaskData();
|
|
|
}
|
|
|
},
|
|
|
@@ -312,22 +287,16 @@ export default {
|
|
|
viewTaskDetail(task) {
|
|
|
// 根据任务状态决定跳转到不同模式的页面
|
|
|
let mode = '';
|
|
|
- if (task.status === 'pending') {
|
|
|
+ if (task.taskStatus === '0') {
|
|
|
// 待完成任务跳转到编辑页面
|
|
|
mode = 'edit';
|
|
|
- } else if (task.status === 'completed') {
|
|
|
+ } else if (task.taskStatus === '1') {
|
|
|
// 已完成任务跳转到查看页面
|
|
|
mode = 'view';
|
|
|
}
|
|
|
|
|
|
- console.log(`点击任务: ${task.name}, 状态: ${task.status}, 跳转模式: ${mode}`);
|
|
|
- console.log('地块数据:', this.plotData);
|
|
|
- console.log('任务数据:', task);
|
|
|
-
|
|
|
// 使用简化的URL参数传递
|
|
|
- const url = `/pages/activity/activity-detail?id=${task.id}&mode=${mode}&plotName=${encodeURIComponent(this.plotData.name)}&crop=${encodeURIComponent(this.plotData.crop)}&manager=${encodeURIComponent(this.plotData.manager)}&taskName=${encodeURIComponent(task.name)}&taskType=${encodeURIComponent(task.type)}&executeTime=${encodeURIComponent(task.executeTime)}&taskRemark=${encodeURIComponent(task.remark || '')}&taskStatus=${task.status}&assignee=${encodeURIComponent(task.assignee)}`;
|
|
|
-
|
|
|
- console.log('跳转URL:', url);
|
|
|
+ const url = `/pages/activity/activity-detail?id=${task.id}&mode=${mode}&plotName=${encodeURIComponent(this.plotData.name)}&crop=${encodeURIComponent(this.plotData.growCrops)}&manager=${encodeURIComponent(this.plotData.managerName)}`;
|
|
|
|
|
|
uni.navigateTo({
|
|
|
url: url
|
|
|
@@ -336,15 +305,9 @@ export default {
|
|
|
|
|
|
// 创建新任务
|
|
|
createNewTask() {
|
|
|
- console.log('点击新建任务按钮,跳转到创建页面');
|
|
|
- console.log('地块数据:', this.plotData);
|
|
|
-
|
|
|
// 使用简化的URL参数传递
|
|
|
- const url = `/pages/activity/activity-detail?id=new&mode=create&plotName=${encodeURIComponent(this.plotData.name)}&crop=${encodeURIComponent(this.plotData.crop)}&manager=${encodeURIComponent(this.plotData.manager)}`;
|
|
|
-
|
|
|
- console.log('跳转URL:', url);
|
|
|
+ const url = `/pages/activity/activity-detail?id=new&mode=create&plotName=${encodeURIComponent(this.plotData.name)}&crop=${encodeURIComponent(this.plotData.growCrops)}&farmId=${encodeURIComponent(this.plotData.farmId)}&manager=${encodeURIComponent(this.plotData.managerName)}&plotId=${this.plotData.id}`;
|
|
|
|
|
|
- // 跳转到新建任务页面
|
|
|
uni.navigateTo({
|
|
|
url: url
|
|
|
});
|
|
|
@@ -361,6 +324,11 @@ export default {
|
|
|
// 页面加载时获取数据
|
|
|
onLoad() {
|
|
|
this.loadTaskData();
|
|
|
+ },
|
|
|
+
|
|
|
+ // 页面显示时刷新数据
|
|
|
+ onShow() {
|
|
|
+ this.refreshData();
|
|
|
}
|
|
|
}
|
|
|
</script>
|
|
|
@@ -728,4 +696,17 @@ export default {
|
|
|
width: 48rpx;
|
|
|
height: 48rpx;
|
|
|
}
|
|
|
+
|
|
|
+/* 添加字典标签相关样式 */
|
|
|
+.task-status-tag {
|
|
|
+ position: absolute;
|
|
|
+ top: 24rpx;
|
|
|
+ right: 24rpx;
|
|
|
+ z-index: 1;
|
|
|
+ max-width: 120rpx;
|
|
|
+}
|
|
|
+
|
|
|
+.info-type-tag {
|
|
|
+ /* margin-left: 4rpx; */
|
|
|
+}
|
|
|
</style>
|