<template>
  <div class="device-info">
    <el-dialog
      title="布防历史"
      :visible.sync="isShow"
      width="600px"
      @close="close"
    >
      <div class="page-body">
        <div>
          <div style="margin-bottom: 20px">
            <span> 所属机构：</span>
            <span>{{ protection.orgName }}</span>
          </div>
          <div style="margin-bottom: 20px">
            <span>防区名称：</span>
            <span>{{ protection.name }}</span>
          </div>
          <div style="margin-bottom: 20px">
            <span> 24小时防区：</span>
            <span>{{ protection.allHour ? "是" : "否" }}</span>
          </div>
          <div style="margin-bottom: 20px">
            <span>上报时间范围：</span>
            <el-date-picker
              v-model="queryParams.updateTime"
              :default-time="defaultTime"
              type="datetimerange"
              range-separator="至"
              clearable
              start-placeholder="开始日期"
              end-placeholder="结束日期"
              @change="refresh"
            >
            </el-date-picker>
          </div>
          <el-table :data="tableData" border style="width: 100%">
            <el-table-column type="index" label="序号"></el-table-column>
            <el-table-column prop="statusText" label="布防状态"
              ><template slot-scope="r">
                {{ getLabel(statusDict, r.row.status) }}
              </template></el-table-column
            >
            <el-table-column prop="updateTime" label="上报时间">
            </el-table-column>
            <el-table-column
              prop="statusUpdatorName"
              label="上报人"
            ></el-table-column>
          </el-table>
          <div style="margin-top: 20px; text-align: right">
            <pagination
              v-show="total > 0"
              :total="total"
              :page.sync="queryParams.pageNum"
              :limit.sync="queryParams.pageSize"
              @pagination="getList"
            />
          </div>
        </div>
      </div>

      <div slot="footer" class="dialog-footer">
        <!-- <el-button @click="onHide">取消</el-button>
          <el-button type="primary" @click="onSubmit">确定</el-button> -->
      </div>
    </el-dialog>
  </div>
</template>

<script>
import * as api from "@/api/resumption/protection";
import { getLabel } from "./../../commonOption";
export default {
  data() {
    const params = this.$route.params;
    return {
      id: params ? params.id : null,
      isShow: false,
      protection: {},
      tableData: [],
      defaultTime: ["00:00:00", "23:59:59"],
      queryParams: this.resetSearch(),
      total: 1,
    };
  },
  props: {
    statusDict: {
      type: Array,
    },
  },
  watch: {},
  computed: {},
  methods: {
    getLabel,
    async refresh() {
      this.pageNum = 1;
      this.getList();
    },
    async getList() {
      await api.history(this.queryParams).then((v) => {
        this.tableData = v.rows;
        this.total = v.total;
      });
    },
    close() {
      this.queryParams = this.resetSearch();
      this.tableData = [];
      this.total = 0;
    },
    async show(protection) {
      this.protection = protection;
      this.queryParams = this.resetSearch();
      this.queryParams.protectionId = protection.id;
      await this.refresh();
      this.isShow = true;
    },
    handleSizeChange(val) {
      this.queryParams.pageSize = val;
      this.getList();
    },
    handleCurrentChange(val) {
      this.queryParams.pageNum = val;
      this.getList();
    },
    resetSearch() {
      return {
        pageNum: 1,
        pageSize: 10,
        protectionId: null,
        updateTime: [new Date(new Date() - 3600 * 1000 * 24 * 90), new Date()],
      };
    },
    // 事件
    //apimark//
  },
  created() {},
  mounted() {},
  components: {
    // EditAttribute,
  },
};
</script>

<style lang="scss">
.device_info {
  .el-form {
    width: 600px;
    padding-top: 40px;
  }
}
</style>
