<template>
  <div class="app-container">
    <el-form
      ref="queryForm"
      :model="queryParams"
      size="small"
      :inline="true"
      v-show="showSearch"
    >
      <el-form-item label="线路名称" prop="lineNm">
        <el-input v-model="queryParams.lineNm" placeholder="请输入" clearable></el-input>
      </el-form-item>
	  <el-form-item label="主分支名称" prop="voltLvlDsc">
	    <el-input
	      v-model="queryParams.branchLineNm"
	      placeholder="请输入"
		  clearable
	    ></el-input>
	  </el-form-item>
      <el-form-item label="是否检修超期" prop="isMaintOverdue">
        <el-checkbox v-model="queryParams.isMaintOverdue"></el-checkbox>
      </el-form-item>
      <el-form-item label="是否重复停电" prop="isRepeatPoweroff">
        <el-checkbox v-model="queryParams.isRepeatPoweroff"></el-checkbox>
      </el-form-item>
      <!--el-form-item label="电压等级" prop="voltLvlDsc">
        <el-input
          v-model="queryParams.voltLvlDsc"
          placeholder="请输入"
        ></el-input>
      </el-form-item>
      <el-form-item label="所属县公司" prop="stdCountyOrgNm">
        <el-input
          v-model="queryParams.stdCountyOrgNm"
          placeholder="请输入"
        ></el-input>
      </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-row :gutter="10" class="mb8">
      <right-toolbar
        :showSearch.sync="showSearch"
        @queryTable="getList"
      ></right-toolbar>
    </el-row>
    <div class="table">
      <el-table
        v-loading="loading"
        :data="dataList"
        row-key="id"
        :expand-row-keys="expands"
        @expand-change="expndChange"
      >
        <el-table-column type="expand">
          <el-table :data="childrenList" v-loading="childrenLoading">
            <el-table-column label="序号" width="80" align="center">
              <template slot-scope="scope">
                {{ scope.$index + 1 }}
              </template>
            </el-table-column>
            <el-table-column
              label="主分支名称"
              align="center"
              prop="lineNm"
			  width="150"
              :show-overflow-tooltip="true"
            />
            <el-table-column
              label="电压等级"
              prop="voltLvlDsc"
              align="center"
              :show-overflow-tooltip="true"
            >
            </el-table-column>
            <el-table-column
              label="线路长度(km)"
              prop="lineTolLen"
              align="center"
              :show-overflow-tooltip="true"
            >
            </el-table-column>
            <!--el-table-column
              label="所属省公司"
              prop="stdOrgNm"
              align="center"
              :show-overflow-tooltip="true"
           / -->
            <el-table-column
              label="所属市公司"
              prop="stdCityOrgNm"
              align="center"
              :show-overflow-tooltip="true"
            />
            <el-table-column
              label="所属县公司"
              prop="stdCountyOrgNm"
              align="center"
			  width="150"
              :show-overflow-tooltip="true"
            >
            </el-table-column>
            <el-table-column
              label="所属供电所"
              prop="maintTeamNm"
              align="center"
              :show-overflow-tooltip="true"
            />
            <!--el-table-column
              label="变电站名称"
              prop="subNm"
              align="center"
              :show-overflow-tooltip="true"
            /-->
            <el-table-column
              label="运维单位名称"
              prop="opMaintOrgNm"
              align="center"
              :show-overflow-tooltip="true"
            />
            <el-table-column
              label="维护班组名称"
              prop="maintTeamNm"
              align="center"
              :show-overflow-tooltip="true"
            />
			<el-table-column
			  label="状态"
			  prop="runStDsc"
			  align="center"
			/>
            <el-table-column
              label="停电次数"
              prop="poweroffNum"
              align="center"
            />
            <el-table-column
              label="无故障持续时间"
              prop="faultFreeDuration"
              align="center"
              :show-overflow-tooltip="true"
            >
            </el-table-column>
            <el-table-column
              label="奖励金额(￥)"
              prop="rewardAmount"
              align="center"
              :show-overflow-tooltip="true"
            >
            </el-table-column>
            <el-table-column
              label="数据日期"
              prop="dataDt"
              align="center"
              :show-overflow-tooltip="true"
            />
          </el-table>
        </el-table-column>
        <el-table-column prop="" label="序号" width="80" align="center">
          <template slot-scope="scope">
            {{ scope.row.index }}
          </template>
        </el-table-column>
        <el-table-column
          label="线路名称"
          align="center"
          prop="lineNm"
          :show-overflow-tooltip="true"
        />
        <el-table-column
          label="电压等级"
          prop="voltLvlDsc"
          align="center"
          :show-overflow-tooltip="true"
        >
        </el-table-column>
        <!--el-table-column
          label="线路长度(km)"
          prop="lineTolLen"
          align="center"
          :show-overflow-tooltip="true"
        >
        </el-table-column>
        <el-table-column
          label="所属省公司"
          prop="stdOrgNm"
          align="center"
          :show-overflow-tooltip="true"
        /-->
        <el-table-column
          label="所属市公司"
          prop="stdCityOrgNm"
          align="center"
          :show-overflow-tooltip="true"
        />
        <el-table-column
          label="所属县公司"
          prop="stdCountyOrgNm"
          align="center"
		   width="150"
          :show-overflow-tooltip="true"
        >
        </el-table-column>
        <el-table-column
          label="所属供电所"
          prop="orgNm"
          align="center"
          :show-overflow-tooltip="true"
        />
        <el-table-column
          label="变电站名称"
          prop="subsNm"
          align="center"
          :show-overflow-tooltip="true"
        />
        <el-table-column
          label="运维单位名称"
          prop="opMaintOrgNm"
          align="center"
          :show-overflow-tooltip="true"
        />
        <el-table-column
          label="维护班组名称"
          prop="maintTeamNm"
          align="center"
          :show-overflow-tooltip="true"
        />
        <el-table-column label="停电次数" prop="poweroffNum" align="center" />
        <el-table-column
          label="无故障持续时间"
          prop="faultFreeDuration"
          align="center"
          :show-overflow-tooltip="true"
        >
        </el-table-column>
        <el-table-column
          label="奖励金额(￥)"
          prop="rewardAmount"
          align="center"
          :show-overflow-tooltip="true"
        >
        </el-table-column>
        <el-table-column
          label="数据日期"
          prop="dataDt"
          align="center"
          :show-overflow-tooltip="true"
        />
      </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 { getWorkPlanList } from "@/api/secure/pdm-work-plan";
import {
  selectCompleteList,
  selectBranchLineCompleteList,
} from "@/api/powerdistribution/maintenance";
export default {
  data() {
    return {
      dataList: [],
      childrenList: [],
      // 显示搜索条件
      showSearch: true,
      // 遮罩层
      loading: true,
      childrenLoading: true,
      total: 0,
      // 日期范围
      dateRange: [],
      // 查询参数
      queryParams: {
        lineNm: "",
		branchLineNm: "",
        isMaintOverdue: false,
        isRepeatPoweroff: false,
        pageNum: 1,
        pageSize: 10,
      },
      // 作业类型
      workTypeList: [],
      // 专业类型
      zyTypeList: [],
      // 作业单位
      workUnitOptions: [],
      // 风险类型
      exceptionTypeList: [],
      expands: [],
    };
  },
  created() {
    this.getList();
  },
  methods: {
    async expndChange(row, expandedRows) {
      // 先判断该行是否已经展开了
      if (!row.expand) {
        this.childrenLoading = true;
        const data = await selectBranchLineCompleteList({
          pageNum: 1,
          pageSize: 9999,
          blgBigFeederId: row.feederId,
		  lineNm: this.queryParams.branchLineNm,
        });
        this.childrenList = data.rows;
        this.childrenLoading = false;
        row.expand = true;
        this.expands = [row.id];
      } else {
        row.expand = false;
        this.expands = [];
      }
    },
    /** 查询列表 */
    getList() {
      this.loading = true;
      selectCompleteList({ ...this.queryParams }).then((response) => {
        this.dataList = response.rows.map((ite, i) => {
          ite.hasChildren = true;
          ite.children = [];
          ite.index =
            i + (this.queryParams.pageNum - 1) * this.queryParams.pageSize + 1;
          return ite;
        });
        this.total = response.total;
        this.loading = false;
      });
    },
    // async load(tree, treeNode, resolve) {
    //   const data = await selectBranchLineCompleteList({
    //     pageNum: 1,
    //     pageSize: 9999,
    //     blgBigFeederId: tree.feederId,
    //   });
    //   resolve(
    //     data.rows.map((ite, i) => {
    //       ite.id = Math.random();
    //       ite.index = i + 1;
    //       return ite;
    //     })
    //   );
    // },
    /** 搜索按钮操作 */
    handleQuery() {
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.queryParams.pageNum = 1;
      this.resetForm("queryForm");
      this.handleQuery();
    },
  },
};
</script>
<style lang="scss" scoped>
.table {
  height: calc(100% - 150px);
}
::v-deep {
  .el-table {
    height: 100%;
    width: 100%;
    .el-table__body-wrapper {
      width: 100% !important;
      height: calc(100% - 50px) !important; // 表格高度减去表头的高度
      overflow-y: scroll;
    }
  }
}
</style>
