| 方法 | 路径 | 说明 |
|---|---|---|
| PUT | /inspectionTask/complete/{id} | 单条巡检完成 |
| PUT | /inspectionTask/batchComplete | 一键巡检完成 |
请求参数:
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
| id | Long | 是 | 巡检任务ID(路径参数) |
响应:json { "code": 200, "msg": "操作成功" }
请求参数:
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
| dateStr | String | 是 | 日期(格式:yyyy-MM-dd) |
响应:json { "code": 200, "msg": "操作成功" }
参照销售/采购订单布局,将巡检记录按日期分组折叠展示。
<el-collapse v-model="activeDateGroups" accordion>
<el-collapse-item v-for="group in groupedInspectionList" :key="group.dateStr" :name="group.dateStr">
<template slot="title">
<div class="group-header">
<span>{{ group.dateStr }}</span>
<span>共 {{ group.items.length }} 条</span>
<el-button type="success" size="small" @click.stop="handleBatchComplete(group.dateStr)">一键巡检完成</el-button>
</div>
</template>
<el-table :data="group.items" border>
<el-table-column prop="taskName" label="巡检任务名称" />
<el-table-column prop="inspectionProject" label="巡检项目" />
<el-table-column prop="inspector" label="巡检人" />
<el-table-column prop="inspectionResult" label="巡检结果">
<template slot-scope="scope">
<el-tag v-if="scope.row.inspectionResult === '1'" type="success">正常</el-tag>
<el-tag v-else-if="scope.row.inspectionResult === '0'" type="danger">异常</el-tag>
<el-tag v-else type="info">未完成</el-tag>
</template>
</el-table-column>
<el-table-column prop="status" label="状态">
<template slot-scope="scope">
<el-tag :type="scope.row.status === 0 ? 'warning' : 'success'">
{{ scope.row.status === 0 ? '待巡检' : '已完成' }}
</el-tag>
</template>
</el-table-column>
<el-table-column label="操作" width="120">
<template slot-scope="scope">
<el-button v-if="scope.row.status === 0" type="primary" size="small" @click="handleComplete(scope.row.id)">
巡检完成
</el-button>
</template>
</el-table-column>
</el-table>
</el-collapse-item>
</el-collapse>
data() {
return {
activeDateGroups: [],
inspectionList: [],
}
}
computed: {
groupedInspectionList() {
const groups = {};
this.inspectionList.forEach(item => {
const dateStr = item.dateStr; // 后端已返回 dateStr 字段
if (!groups[dateStr]) {
groups[dateStr] = { dateStr, items: [] };
}
groups[dateStr].items.push(item);
});
return Object.values(groups).sort((a, b) => b.dateStr.localeCompare(a.dateStr));
}
}
async handleComplete(id) {
try {
await this.$confirm('确认该巡检任务已完成?', '提示', { type: 'warning' });
await this.$http.put(`/inspectionTask/complete/${id}`);
this.$message.success('巡检完成');
this.loadList();
} catch (e) {
if (e !== 'cancel') {
this.$message.error(e.msg || '操作失败');
}
}
},
async handleBatchComplete(dateStr) {
try {
await this.$confirm(`确认将 ${dateStr} 的所有待巡检任务一键完成?`, '提示', { type: 'warning' });
await this.$http.put('/inspectionTask/batchComplete', null, { params: { dateStr } });
this.$message.success('批量巡检完成');
this.loadList();
} catch (e) {
if (e !== 'cancel') {
this.$message.error(e.msg || '操作失败');
}
}
},
async loadList() {
const res = await this.$http.get('/inspectionTask/list', { params: this.queryParams });
this.inspectionList = res.data.records || [];
}