<template>
  <div class="RoadNetworkMonitoring">
    <!-- 搜索栏 -->
    <div class="filter">
      <div class="filter-btn">
        <ButtonGradient @click.native="handleExport">
          <template #prefix>
            <img src="@screen/images/export.svg" />
          </template>
          导出
        </ButtonGradient>
        <ButtonGradient @click="onRefresh" class="refresh-btn">
          <template #prefix>
            <img src="./images/refresh.svg" />
          </template>
          刷新
        </ButtonGradient>
      </div>

      <InputSearch
        ref="searchComp"
        style="width: 402px"
        :formList="searchFormList"
        :formConfigOptions="{ dFormData: { eventState: '0' } }"
        @handleSearch="handleSearch"
      />
    </div>

    <!-- 内容 -->
    <div class="body">
        <div class="content">
              <!-- 内容 -->
    <div class="scrollPanel">
      <ManualWarningCard
        v-for="(item, index) in data"
        :key="index"
        :cardData="item"
      />
    </div>
      </div>
      </div>

    <!-- 分页 -->
    <div class="footer">
      <Pagination
        @current-change="initData"
        @size-change="onSizeChange"
        width="'100%'"
        :page-sizes="[12, 16, 20, 30, 50]"
        :page-size="pageSize"
        :current-page.sync="pageNum"
        layout="total, sizes, prev, pager, next"
        :total="total"
      >
      </Pagination>
    </div>
  </div>
</template>

<script>
import ButtonGradient from "@screen/components/Buttons/ButtonGradient.vue";
import Pagination from "@screen/components/Pagination.vue";
import InputSearch from "@screen/components/InputSearch/index.vue";
import ManualWarningCard from "@screen/components/ManualWarningCard/index.vue";
import { perceivedEventsList } from "@/api/manualWarning/index.js";
// import EventDispatchDialog from "./EventDispatchDialog/index";
import { searchFormList } from "./data";
import request from "@/utils/request";
import { exportFile } from "@screen/utils/common";
import { WarningType, WarningSubclass } from "@screen/utils/enum.js";

const directionMapping = {
  1: "菏泽方向",
  2: "双向",
  3: "济南方向",
};

export default {
  name: "RoadNetworkMonitoring",
  components: {
    Pagination,
    ManualWarningCard,
    InputSearch,
    Pagination,
    ButtonGradient,
  },
  data() {
    return {
      WarningSubclass,
      searchFormList,
      detailDialogFormData: {},
      total: 0,
      data: [],
      eventId: "0",
      pageSize: 12,
      pageNum: 1,
      searchData: {
        pageNum: 1,
        warningSource:"6"
      },
    };
  },
  created() {
    this.initSearch();
    this.initData();
  },
  methods: {
    initSearch(){
      request({
        url: `business/facility/query?facilityType=1`,
        method: "get",
      }).then(res=>{
        if (res.code != 200) return Message.error(res?.msg);
        const options = [];
        res.data.forEach(e => {
          options.push({
            key: e.facilityName,
            label: e.facilityName,
          })
        });
        this.searchFormList[2].options.options = options
      })
    },
    // 导出
    handleExport() {
      exportFile({
        url: "/business/warning/export",
        filename: "事件列表",
        data: this.searchData
      });
    },
    // 刷新
    onRefresh() {
      this.searchData.pageNum = 1;
      this.$refs.searchComp.handleResetForm();
    },
    initData() {
     
      perceivedEventsList(this.searchData, this.pageNum, this.pageSize).then(
        (res) => {
          if (res.code != 200) return Message.error(res?.msg);
          this.total = res.total;
          res.rows.forEach((it) => {
            it.source = "非机预警";
            it.stringDirection = directionMapping[it.direction] || it.direction;
            it.otherConfig = JSON.parse(it.otherConfig);
            if (it.warningSubclass) {
              let i = it.warningType;
              let r = it.warningSubclass;
              it.warningTypeName =
                WarningType[i] +
                (WarningSubclass[i][r]
                  ? "(" + WarningSubclass[i][r] + ")"
                  : "");
            }
          });
          this.data = res.rows;
        }
      );
    },
    onSizeChange(pageSize) {
      this.pageSize = pageSize;
      this.initData();
    },
    getStateCardBind(item) {},

    firstBtnClick(id) {},
    handleSearch(data) {
      this.searchData.facilityName = data.facilityName;
      this.searchData.startTime = data.warningTime && data.warningTime[0];
      this.searchData.completeTime = data.warningTime && data.warningTime[1];
      if(data.warningType){
        this.searchData.warningType = data.warningType
      } else {
       delete this.searchData.warningType; 
      }
      this.initData();
    },
  },
};
</script>

<style lang="scss" scoped>
.RoadNetworkMonitoring {
  padding: 21px;

  height: 100%;
  display: flex;
  flex-direction: column;
  z-index: 6;

  .filter {
    height: 38px;
    display: flex;
    // justify-content: flex-end;
    justify-content: space-between;
    .filter-btn {
      width: 150px;
      justify-content: space-between;
      display: flex;
    }
  }


  .body {
    flex: 1;
    overflow: hidden;
    position: relative;
    overflow: hidden;

    .content {
      position: absolute;
      width: 100%;
      height: 100%;
      overflow: hidden;
      display: flex;
      flex-direction: column;
      .scrollPanel {
        display: grid;
        grid-template-columns: repeat(4, 1fr);
        grid-gap: 24px;
        grid-auto-rows: minmax(220px, max-content);
        position: relative;
        flex: 1;
        overflow-y: auto;
        overflow-x: hidden;
      }
    }
  }


  // .body {
  //   flex: 1;
  //   overflow: auto;
  //   display: grid;
  //   grid-template-columns: repeat(4, 1fr);
  //   grid-gap: 20px;
  //   // grid-row-gap: 9px;
  //   // grid-column-gap: 9px;
  //   grid-auto-rows: min-content;
  // }

  .footer {
    margin-top: 15px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
  }
}
</style>
