编辑 | blame | 历史 | 原始文档

巡检任务完成功能

涉及页面

  • 设备巡检 - 巡检任务页面

API

方法 路径 说明
PUT /inspectionTask/complete/{id} 单条巡检完成
PUT /inspectionTask/batchComplete 一键巡检完成

1. 巡检完成

请求参数:

参数 类型 必填 说明
id Long 巡检任务ID(路径参数)

响应:
json { "code": 200, "msg": "操作成功" }

2. 一键巡检完成

请求参数:

参数 类型 必填 说明
dateStr String 日期(格式:yyyy-MM-dd)

响应:
json { "code": 200, "msg": "操作成功" }

前端修改点

1. 巡检任务列表改造 - 按日期分组折叠

参照销售/采购订单布局,将巡检记录按日期分组折叠展示。

<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>

2. data 数据

data() {
  return {
    activeDateGroups: [],
    inspectionList: [],
  }
}

3. 计算属性

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));
  }
}

4. 方法

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 || [];
}

注意事项

  • 已完成(status=1)的巡检记录不显示"巡检完成"按钮
  • 一键巡检完成仅处理当天所有待巡检(status=0)的记录
  • 巡检完成时若未设置巡检结果,默认设为"正常"
  • 数据库新增了 status 字段,部署前需执行迁移 SQL