<template>
  <div class="app-container scroll-auto">
    <el-form ref="queryForm" :model="queryParams" size="small" :inline="true">
      <el-form-item label="批次工程名称" prop="batchName">
        <el-input
          v-model="queryParams.batchName"
          placeholder="请输入批次工程名称"
          clearable
        />
      </el-form-item>
      <el-form-item label="工程名称" prop="proName">
        <el-input
          v-model="queryParams.proName"
          placeholder="请输入工程名称"
          clearable
        />
      </el-form-item>
      <el-form-item label="年度" prop="planYear">
        <el-date-picker
          v-model="queryParams.planYear"
          type="year"
          placeholder="选择年度"
          value-format="yyyy"
          clearable
        />
      </el-form-item>
      <el-form-item label="工程状态" prop="completeFlag">
        <el-select
          v-model="queryParams.completeFlag"
          placeholder="请选择工程状态"
          clearable
        >
          <el-option
            v-for="dict in completeFlagOptions"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="项目类别" prop="proCategory">
        <el-select
          v-model="queryParams.proCategory"
          placeholder="请选择项目类别"
          clearable
        >
          <el-option
            v-for="dict in proCategoryOptions"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </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>
    <div class="table">
      <el-table
        ref="renewalTable"
        v-loading="loading"
        :data="dataList"
        border
        height="calc(100% - 50px)"
      >
        <el-table-column
          label="年度"
          prop="planYear"
          align="center"
          width="80"
          fixed="left"
        />
        <el-table-column
          label="工程状态"
          prop="completeFlag"
          align="center"
          width="90"
          fixed="left"
        >
          <template slot-scope="scope">
            {{ scope.row.completeFlag === "1" ? "已竣工" : "未竣工" }}
          </template>
        </el-table-column>
        <el-table-column
          label="项目类别"
          prop="proCategory"
          align="center"
          width="90"
          fixed="left"
        >
          <template slot-scope="scope">
            {{ scope.row.proCategory === "10" ? "农网" : "城网" }}
          </template>
        </el-table-column>
        <el-table-column
          label="批次工程名称"
          prop="batchName"
          align="center"
          width="200"
          fixed="left"
        />
        <el-table-column
          label="工程名称"
          prop="proName"
          align="center"
          width="200"
          fixed="left"
        />
        <el-table-column
          label="10千伏电缆线路"
          prop="vehicleNo"
          align="center"
          :show-overflow-tooltip="true"
        >
          <el-table-column
            label="计划量"
            align="center"
            prop="lineCableNewPlanQt"
            :show-overflow-tooltip="true"
          />
          <el-table-column
            label="累计量"
            align="center"
            prop="lineCableNewAccuQt"
            :show-overflow-tooltip="true"
          />
          <el-table-column
            label="作业数量"
            align="center"
            prop="lineCableNewAccuQtWork"
            :show-overflow-tooltip="true"
          >
          </el-table-column>
        </el-table-column>

        <el-table-column
          label="10千伏架空线路"
          align="center"
          :show-overflow-tooltip="true"
        >
          <el-table-column
            label="计划量"
            align="center"
            prop="lineOverhdNewPlanQt"
            :show-overflow-tooltip="true"
          />
          <el-table-column
            label="累计量"
            align="center"
            prop="lineOverhdNewAccuQt"
            :show-overflow-tooltip="true"
          />
          <el-table-column
            label="作业数量"
            align="center"
            prop="lineOverhdNewAccuQtWork"
            :show-overflow-tooltip="true"
          >
          </el-table-column>
        </el-table-column>
        <el-table-column
          label="配电变压器"
          align="center"
          :show-overflow-tooltip="true"
        >
          <el-table-column
            label="计划量"
            align="center"
            prop="distTransNewPlanQt"
            :show-overflow-tooltip="true"
          />
          <el-table-column
            label="累计量"
            align="center"
            prop="distTransNewAccuQt"
            :show-overflow-tooltip="true"
          />
          <el-table-column
            label="作业数量"
            align="center"
            prop="distTransNewAccuQtWork"
            :show-overflow-tooltip="true"
          >
          </el-table-column>
        </el-table-column>
        <el-table-column
          label="低压线路"
          prop="vehicleNo"
          align="center"
          :show-overflow-tooltip="true"
        >
          <el-table-column
            label="计划量"
            align="center"
            prop="lowVoltLinePlanQt"
            :show-overflow-tooltip="true"
          />
          <el-table-column
            label="累计量"
            align="center"
            prop="lowVoltLineAccuQt"
            :show-overflow-tooltip="true"
          />
          <el-table-column
            label="作业数量"
            align="center"
            prop="lowVoltLineAccuQtWork"
            :show-overflow-tooltip="true"
          >
          </el-table-column>
        </el-table-column>

        <el-table-column
          label="高低压杆塔"
          align="center"
          :show-overflow-tooltip="true"
        >
          <el-table-column
            label="计划量"
            align="center"
            prop="towerPlanQt"
            :show-overflow-tooltip="true"
          />
          <el-table-column
            label="累计量"
            align="center"
            prop="towerAccuQt"
            :show-overflow-tooltip="true"
          />
          <el-table-column
            label="作业数量"
            align="center"
            prop="towerAccuQtWork"
            :show-overflow-tooltip="true"
          >
          </el-table-column>
        </el-table-column>
        <el-table-column
          label="环网柜"
          align="center"
          :show-overflow-tooltip="true"
        >
          <el-table-column
            label="计划量"
            align="center"
            prop="ringCabinetPlanQt"
            :show-overflow-tooltip="true"
          />
          <el-table-column
            label="累计量"
            align="center"
            prop="ringCabinetAccuQt"
            :show-overflow-tooltip="true"
          />
          <el-table-column
            label="作业数量"
            align="center"
            prop="ringCabinetAccuQtWork"
            :show-overflow-tooltip="true"
          >
          </el-table-column>
        </el-table-column>
        <el-table-column
          label="柱上设备"
          align="center"
          :show-overflow-tooltip="true"
        >
          <el-table-column
            label="计划量"
            align="center"
            prop="poleTabPlanQt"
            :show-overflow-tooltip="true"
          />
          <el-table-column
            label="累计量"
            align="center"
            prop="poleTabAccuQt"
            :show-overflow-tooltip="true"
          />
          <el-table-column
            label="作业数量"
            align="center"
            prop="poleTabAccuQtWork"
            :show-overflow-tooltip="true"
          >
          </el-table-column>
        </el-table-column>
      </el-table>
      <pagination
        class="page-box"
        v-show="total > 0"
        :total="total"
        :page.sync="queryParams.pageNum"
        :limit.sync="queryParams.pageSize"
        @pagination="getList"
      />
    </div>
  </div>
</template>

<script>
import { workCompleStatistics } from "@/api/powerdistribution/quantity-of-work";

export default {
  data() {
    return {
      dataList: [],
      loading: true,
      total: 0,
      // 工程状态选项
      completeFlagOptions: [
        { value: "0", label: "未竣工" },
        { value: "1", label: "已竣工" },
      ],
      // 项目类别选项
      proCategoryOptions: [
        { value: "10", label: "农网" },
        { value: "20", label: "城网" },
      ],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        batchName: "", // 批次工程名称
        proName: "", // 工程名称
        planYear: new Date().getFullYear().toString(), // 年度，转为字符串
        completeFlag: "", // 工程状态
        proCategory: "", // 项目类别
      },
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询列表 */
    getList() {
      this.loading = true;
      workCompleStatistics({ ...this.queryParams }).then((response) => {
        this.dataList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.queryParams = {
        pageNum: 1,
        pageSize: 10,
        batchName: "",
        proName: "",
        planYear: new Date().getFullYear().toString(), // 年度，转为字符串
        completeFlag: "",
        proCategory: "",
      };
      this.resetForm("queryForm");
      this.handleQuery();
    },
  },
};
</script>

<style lang="scss" scoped>
.table {
  height: calc(100% - 60px);
  position: relative;
  padding-bottom: 50px; // 为分页组件预留空间
}
::v-deep {
  .el-table {
    width: 100%;

    .el-table__body-wrapper {
      width: 100% !important;
      overflow-y: scroll;
    }

    // 调整固定列的样式
    .el-table__fixed-right,
    .el-table__fixed {
      height: 100% !important;
      bottom: 0; // 确保固定列延伸到底部
      .el-table__fixed-body-wrapper {
        overflow-y: auto; // 改为auto以防止出现不必要的滚动条
      }
    }
  }

  // 分页组件样式
  .page-box {
    position: absolute;
    bottom: 0;
    width: 100%;
    padding: 10px 0;
    background-color: #fff;
  }

  .el-form--inline .el-form-item {
    margin-right: 10px;
    margin-bottom: 10px;
  }
}
</style>
