<template>
  <div class="picReportClass">
    <div class="logTitle">
      <!-- <h3>装置图片报表</h3> -->

      <el-form :inline="true" :model="formdata" class="demo-form-inline">
        <el-form-item label="开始日期" class="dateclass">
          <el-date-picker
            v-model="formdata.starttime"
            type="datetime"
            placeholder="开始日期"
            value-format="timestamp"
            :picker-options="pickerOptions"
          >
          </el-date-picker>
        </el-form-item>
        <el-form-item label="结束日期" class="dateclass">
          <el-date-picker
            v-model="formdata.endtime"
            type="datetime"
            placeholder="结束日期"
            value-format="timestamp"
            :picker-options="pickerOptions"
          >
          </el-date-picker>
        </el-form-item>
      </el-form>
      <selectLine></selectLine>
      <el-button type="primary" @click="onSubmit">查询</el-button>
    </div>

    <div class="boxLogTable">
      <el-table
        v-loading="picLoading"
        :data="tableData"
        border
        stripe
        style="width: 100%"
        height="100%"
      >
        <el-table-column type="index" width="50" label="序号">
        </el-table-column>

        <el-table-column label="线路" show-overflow-tooltip>
          <template slot-scope="scope">
            <el-link
              type="primary"
              @click="detailFun(scope.row.line.id)"
              size="small"
              >{{ scope.row.line.name }}</el-link
            >
          </template>
        </el-table-column>
        <el-table-column prop="day" label="日期">
          <template slot-scope="scope">
            {{ scope.row.dayList[0].day }}
          </template>
        </el-table-column>
        <el-table-column label="装置总数">
          <template slot-scope="scope">
            {{ scope.row.termList.length }}</template
          >
        </el-table-column>
        <el-table-column label="运维上线数量">
          <template slot-scope="scope">
            {{ scope.row.dayList[0].termList.length }}</template
          >
        </el-table-column>
        <el-table-column label="运维上线率">
          <template slot-scope="scope">
            {{
              (
                (scope.row.dayList[0].termList.length /
                  scope.row.termList.length) *
                100
              ).toFixed(2) + "%"
            }}</template
          >
        </el-table-column>
        <el-table-column label="上图设备数量">
          <template slot-scope="scope">
            {{
              scope.row.dayList[0].termList.filter(
                (term) => parseInt(term.uploads, 10) > 0
              ).length
            }}
          </template>
        </el-table-column>
        <el-table-column prop="cmdid" label="上图率">
          <template slot-scope="scope">
            {{
              (
                (scope.row.dayList[0].termList.filter(
                  (term) => parseInt(term.uploads, 10) > 0
                ).length /
                  scope.row.termList.length) *
                100
              ).toFixed(2) + "%"
            }}</template
          >
        </el-table-column>
        <el-table-column label="正常上图设备数量">
          <template slot-scope="scope">
            {{
              scope.row.dayList[0].termList.filter(
                (term) =>
                  parseInt(term.uploads, 10) >=
                  (parseInt(scope.row.line.photoCount, 10) *
                    parseInt(scope.row.line.photoRate.replace("%", ""), 10)) /
                    100
              ).length
            }}
          </template>
        </el-table-column>
        <el-table-column label="正常上图率">
          <template slot-scope="scope">
            {{
              (
                (scope.row.dayList[0].termList.filter(
                  (term) =>
                    parseInt(term.uploads, 10) >=
                    (parseInt(scope.row.line.photoCount, 10) *
                      parseInt(scope.row.line.photoRate.replace("%", ""), 10)) /
                      100
                ).length /
                  scope.row.termList.length) *
                100
              ).toFixed(2) + "%"
            }}
          </template>
        </el-table-column>
      </el-table>
    </div>

    <lineStatusDialog ref="statusLineRef"></lineStatusDialog>
  </div>
</template>
<script>
import { picRportApi } from "@/utils/api/index";
import selectLine from "./components/selectLine";
import lineStatusDialog from "./components/lineStatusDialog";
export default {
  name: "picReport",
  components: { selectLine, lineStatusDialog },
  data() {
    return {
      pickerOptions: {
        disabledDate(date) {
          return date.getTime() > Date.now(); // 禁用大于今天的日期
        },
      },

      formdata: {
        starttime: new Date(new Date().setHours(0, 0, 0, 0)).getTime(), // 设置开始时间为当天凌晨00:00:00的时间戳,
        endtime: new Date(new Date().setHours(23, 59, 59, 0)).getTime(), // 设置结束时间为当天夜晚23:59:59的时间戳
      },
      tableData: [],
      picLoading: false,
      termTotalNum: 0,
      dyName: "",
      xlName: "",
      //从本地获取选中的线路
      localSelectLine: [],
    };
  },
  watch: {},
  filters: {},
  computed: {},
  created() {},
  mounted() {
    this.localSelectLine = JSON.parse(localStorage.getItem("checkListLocal"));
    console.log(this.localSelectLine);
  },
  methods: {
    onSubmit() {
      if (this.formdata.starttime > this.formdata.endtime) {
        return this.$message({
          duration: 1500,
          showClose: true,
          message: "开始日期不能大于结束日期",
          type: "warning",
        });
      }
      let params = {
        start: this.formdata.starttime / 1000,
        end: this.formdata.endtime / 1000,
        lineIds: this.localSelectLine,
      };
      this.getpicList(params);
    },

    getpicList(params) {
      setTimeout(() => {
        this.picLoading = true;
        picRportApi(params)
          .then((res) => {
            this.picLoading = false;
            if (res.data.length !== 0) {
              console.log(res.data);
              this.tableData = res.data;
            } else {
              this.tableData = [];
            }
          })
          .catch((err) => {});
      }, 100);
    },

    //获取多条线路的信息
    getTablefun() {
      console.log("我是点击了确定");
      this.localSelectLine = JSON.parse(localStorage.getItem("checkListLocal"));
      this.onSubmit();
    },
    //获取详细线路
    detailFun(row) {
      console.log(row);
      this.$refs.statusLineRef.display(row);
    },
  },
};
</script>
<style lang="less">
.picReportClass {
  height: calc(100% - 24px);
  width: calc(100% - 24px);
  padding: 12px;
  .logTitle {
    display: flex;
    align-items: center;
    height: 32px;
    margin-bottom: 12px;

    h3 {
      margin-right: 24px;
    }
    .el-form-item--small.el-form-item {
      margin-bottom: 0px;
    }

    .lineBtn {
      margin-right: 12px;
    }
    .dateclass {
      .el-date-editor.el-input,
      .el-date-editor.el-input__inner {
        width: 190px;
      }
    }
  }
  .boxLogTable {
    height: calc(100% - 44px);

    .el-table__cell {
      text-align: center;
    }
    .el-table thead {
      th.el-table__cell {
        background: #fafafa;
      }
    }
    .buttonText {
      cursor: pointer;
      white-space: pre-wrap;
      &:hover {
        text-decoration: underline;
      }
    }
  }
}
</style>
