<template>
  <div>
    <el-form :model="queryParams" ref="queryForm" :inline="true" label-width="68px">
      <el-form-item label="管线名称" prop="pipeName">
        <el-input
          v-model="queryParams.pipeName"
          placeholder="请输入管线名称"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

      <el-form-item label="巡线员" prop="inspector">
        <el-input
          v-model="queryParams.inspector"
          placeholder="请输入巡线人"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>


    <el-table v-loading="loading" :data="pipeStatisticsList">
      <el-table-column label="管线名称" align="center" prop="pipeName" />
      <el-table-column label="巡线员" align="center" prop="inspector" />
      <el-table-column label="管线设置打卡点数" align="center" prop="totalPointNum">
      </el-table-column>
      <el-table-column label="巡检打卡点数" align="center" prop="finishPointNum" />
      <el-table-column label="巡检打卡率" align="center">
        <template slot-scope="scope">
          <span>{{ (scope.row.finishPointNum/scope.row.totalPointNum * 100).toFixed() }}%</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-document"
            @click="handleDetail(scope.row)"
          >查看巡检进度</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getPipeStatistics"
    />

    <!-- 详情 -->
    <DetailInfo title="管线巡检记录" class="border-bottom-none" ref="detailInfo"/>
  </div>
</template>

<script>
  import { selectTaskInspectStatisticsByPipe }from "@/api/pipetask/task";
  import DetailInfo from "./DetailInfo";
  export default {
    name: "pipe-statistics",
    props:{
      taskId: {
        type: Number
      },
      pushTime: {
        type: String
      }
    },
    components:{
      DetailInfo
    },
    data(){
        return{
          loading: false,
          total: 0,
          pipeStatisticsList: [],
          // 查询参数
          queryParams: {
            pageNum: 1,
            pageSize: 10,
            taskId: null,
            inspector: null,
            pipeName: null
          },
        }
    },
    created(){
      this.queryParams.taskId = this.taskId;
      this.getPipeStatistics();
    },
    methods: {
      getPipeStatistics(){
        this.loading = true;
        selectTaskInspectStatisticsByPipe(this.queryParams).then(res =>{
          this.loading = false;
          if(res.code == 200){
            this.total = res.total;
            this.pipeStatisticsList = res.rows;
          }
        })
      },
      handleDetail(row){
        this.$refs.detailInfo.queryParams.taskId = row.taskId;
        this.$refs.detailInfo.queryParams.pipeId = row.pipeId;
        this.$refs.detailInfo.taskInfo = {pipeName:row.pipeName,pushTime:this.pushTime,finishPointNum:row.finishPointNum,totalPointNum:row.totalPointNum,type:"pipe"};
        this.$refs.detailInfo.initInfo();
      },
      /** 搜索按钮操作 */
      handleQuery() {
        this.queryParams.pageNum = 1;
        this.getPipeStatistics();
      },
      /** 重置按钮操作 */
      resetQuery() {
        this.resetForm("queryForm");
        this.handleQuery();
      },
    }
  }
</script>

<style scoped>

</style>
