<template>
  <div class="container">
    <div class="event-box">
      <div class="box-header">
        <div class="title-box">
          <div class="title"><i class="icon-speaker" />重大事件信息</div>
        </div>
        <div class="more">查看更多>></div>
      </div>
      <div class="event-content">
        <div class="text1">{{ noticeBarState.event_title }}</div>
        <div class="text2">{{ noticeBarState.time }}</div>
      </div>
    </div>
    <div class="content" style="margin-top: 0">
      <div class="card-box">
        <div class="card-item">
          <div class="text1">事故数量</div>
          <div class="text-box">
            <div class="text2">47</div>
            <div class="text3">起</div>
          </div>
        </div>
        <div class="card-item">
          <div class="text1">伤亡人数</div>
          <div class="text-box">
            <div class="text2">1,302</div>
            <div class="text3">人</div>
          </div>
        </div>
        <div class="card-item">
          <div class="text1">经济损失</div>
          <div class="text-box">
            <div class="text2">221</div>
            <div class="text3">万</div>
          </div>
        </div>
      </div>
    </div>
    <div class="content" style="margin-top: 0">
      <div class="card">
        <div class="card-header">
          <i class="icon-line" />
          <div class="text">交通事故隐患点情况</div>
        </div>
        <div class="card-content2">
          <div class="card1">
            <div class="text1">交通事故隐患点总数</div>
            <div class="text-box">
              <div class="text-blue">10</div>
              <div class="text2">个</div>
            </div>
          </div>
          <div class="flex-box">
            <div class="card2">
              <div class="text1">高风险</div>
              <div class="text-box">
                <div class="text-red">2</div>
                <div class="text2">个</div>
              </div>
            </div>
            <div class="card3">
              <div class="text1">中风险</div>
              <div class="text-box">
                <div class="text-orange">3</div>
                <div class="text2">个</div>
              </div>
            </div>
            <div class="card4">
              <div class="text1">低风险</div>
              <div class="text-box">
                <div class="text-green">5</div>
                <div class="text2">个</div>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>

    <div class="content">
      <div class="card">
        <div class="card-header">
          <i class="icon-line" />
          <div class="text">事故原因统计</div>
        </div>
        <Chart :option="option1" style="height: 200px" />
      </div>
    </div>
    <div class="content">
      <div class="card">
        <div class="card-header">
          <i class="icon-line" />
          <div class="text">事件列表</div>
        </div>
        <div class="select-box" @click="showPicker = true">
          <div class="text1">年度</div>
          <div class="select-item">
            <div class="label">{{ yearLabel ? yearLabel : "请选择" }}</div>
            <i class="icon-down" />
          </div>
        </div>
        <el-table :data="detailsData.dataList" border table-layout="auto">
          <el-table-column label="类型" prop="data1" align="center" />
          <el-table-column label="位置" prop="data2" align="center" />
          <el-table-column label="发生时间" prop="data3" align="center" />
          <el-table-column label="受伤人数" prop="data4" align="center" />
          <el-table-column label="死亡人数" prop="data5" align="center" />
        </el-table>
      </div>
    </div>
    <van-popup v-model:show="showPicker" round position="bottom">
      <van-picker
        :columns="columns"
        @cancel="showPicker = false"
        @confirm="onPickerConfirm"
      />
    </van-popup>
  </div>
</template>

<script lang="ts" setup name="cityEmergencyEvent">
import { reactive, ref } from "vue";
import { onClickOutside } from "@vueuse/core";
import { chartOption7 } from "@/views/disasterRiskMonitor/chartOptions";
import { ElTable, ElTableColumn } from "element-plus";
const noticeBarState = reactive({
  show: false,
  event_id: "",
  time: "2024-03-01 12:12:12",
  event_title:
    "2025年3月24日，S10山海高速五指山往保亭方向32km+300m路段。一辆白色小型普通客车在快车道行驶时，突然向左偏离方向剐蹭了中央护栏…"
});
// 搜索
const searchBoxRef = ref();
let showSearch = ref();
const queryParams = reactive({
  page: 0,
  page_size: 10,
  year: "",
  keywords: ""
});
let yearLabel = ref("");
onClickOutside(searchBoxRef, event => {
  showSearch.value = false;
});

let detailsData = ref({
  dataList: []
});
const option1 = ref(chartOption7);
let showPicker = ref(false);
let columns = reactive([
  { text: "2024年", value: "2024" },
  { text: "2023年", value: "2023" },
  { text: "2022年", value: "2022" },
  { text: "2021年", value: "2021" }
]);
const getImageUrl = name => {
  return new URL(
    `../../assets/images/disasterRiskMonitor/cityEmergencyEvent/${name}`,
    import.meta.url
  ).href;
};
let iconList = reactive({
  "1": {
    image: getImageUrl("icon2.png"),
    size: [20, 20]
  },
  "2": {
    image: getImageUrl("icon1.png"),
    size: [20, 20]
  }
});
const onPickerConfirm = ({ selectedOptions }) => {
  showPicker.value = false;
  yearLabel.value = selectedOptions[0].text;
  queryParams.year = selectedOptions[0].value;
};
const initData = () => {
  option1.value.xAxis.data = [
    "2024-01",
    "2024-02",
    "2024-03",
    "2024-04",
    "2024-05",
    "2024-06"
  ];
  option1.value.series[0].data = [
    502.84, 205.97, 332.79, 281.55, 398.35, 214.02
  ];
  // 事件列表
  detailsData.value.dataList = [
    {
      data1: "追尾",
      data2: "茂名市电白区黄岭镇石头村",
      data3: "2024-12-14 12:12:13",
      data4: 1,
      data5: 0,
      longitude: "110.719914",
      latitude: "21.609269",
      dataType: "1"
    },
    {
      data1: "碰撞行人",
      data2: "茂名市茂南区羊角镇",
      data3: "2024-10-07 08:00:00",
      data4: 2,
      data5: 0,
      longitude: "110.984948",
      latitude: "21.669318",
      dataType: "1"
    }
  ];
  detailsData.value.dataList.forEach(item => {
    const icon =
      item.dataType && !!iconList[item.dataType].image
        ? iconList[item.dataType].image
        : "";
    item.icon = icon;
    item.image = icon;
    item.imageHover = icon;
    item.size = iconList[item.dataType].size;
    item.lnglat = [item.longitude, item.latitude];
  });
};
initData();
</script>

<style lang="scss" scoped>
.container {
  .map {
    width: 100%;
    height: 250px;
  }
  .event-box {
    position: relative;
    width: 375px;
    height: 117px;
    background: url("@/assets/images/disasterRiskMonitor/cityEmergencyEvent/box1.png")
      no-repeat;
    background-size: 100% 100%;
    box-shadow: 0 2px 4px 0 rgba(228, 240, 255, 1);
    .box-header {
      display: flex;
      justify-content: space-between;
      align-items: center;
      padding: 0 6px;
      .more {
        font-size: 12px;
        color: #2c81ff;
      }
    }
    .title-box {
      height: 30px;
      background-color: #ffffff; /* 背景颜色 */
      transform: skewX(-20deg); /* 斜切变形 */
      box-shadow: 0 2px 4px 0 rgba(250, 217, 97, 0.18);
      padding: 0 10px;
      display: flex;
      align-items: center;
      border-radius: 2px;
      &::after {
        content: "";
        position: absolute;
        top: 0;
        right: -6px;
        transform: skewX(20deg);
        width: 11px;
        height: 27px;
        background: url("@/assets/images/disasterRiskMonitor/riverMonitor/thickness.png")
          no-repeat;
        background-size: 100% 100%;
      }
      .title {
        font-size: 14px;
        color: #ffaf00;
        transform: skewX(20deg);
        display: flex;
        align-items: center;
        .icon-speaker {
          display: inline-block;
          width: 16px;
          height: 16px;
          background: url("@/assets/images/disasterRiskMonitor/riverMonitor/speaker.png")
            no-repeat;
          background-size: 100% 100%;
          margin-right: 5px;
        }
      }
    }
    .event-content {
      padding: 0 10px;
    }
    .text1 {
      display: -webkit-box;
      -webkit-line-clamp: 3;
      -webkit-box-orient: vertical;
      overflow: hidden;
      text-overflow: ellipsis;
      font-size: 14px;
      color: #414f64;
    }
    .text2 {
      font-size: 12px;
      color: rgba(0, 0, 0, 0.45);
      text-align: right;
    }
  }
}
.search-box {
  padding: 16px 16px 10px;
}
.search-list {
  position: absolute;
  top: 50px;
  left: 0;
  z-index: 9;
  width: 100%;
  height: calc(100vh - 400px);
  overflow-y: auto;
  background-color: #ffffff;
  border-top: 1px solid #eeeeee;
  .item {
    padding: 8px 15px;
    border-bottom: 1px solid #eeeeee;
  }
}
.common-search {
  border: 1px solid #dce0ee;
  border-radius: 2px;
  padding: 0;
  :deep(.van-field__control) {
    &::placeholder {
      color: #c9cfd9;
    }
  }
  :deep(.van-search__content) {
    background-color: #ffffff;
    border: none !important;
  }
  :deep(.van-field__left-icon) {
    .van-icon__image {
      width: 12px;
      height: 12px;
    }
  }
  :deep(.van-field__right-icon) {
    width: 30px;
    height: 30px;
    padding: 0;
    .van-icon__image {
      width: 30px;
      height: 30px;
    }
  }
  .search-btn {
    font-size: 14px;
    color: #2c81ff;
  }
}
.card {
  background-color: #ffffff;
  border: 1px solid #eaedf7;
  border-radius: 4px;
  padding: 2px;
  margin-top: 16px;
  &:first-child {
    margin-top: 0;
  }
  .card-header {
    font-size: 16px;
    color: #414f64;
    font-weight: bold;
    line-height: 26px;
    padding: 11px 10px;
    display: flex;
    align-items: center;
    border-top-left-radius: 4px;
    border-top-right-radius: 4px;
    background-image: linear-gradient(180deg, #f3f7fd 0%, #ffffff 100%);
    .icon-line {
      display: inline-block;
      width: 6px;
      height: 16px;
      background: url("@/assets/images/line.jpg") no-repeat;
      background-size: 100% 100%;
      margin-right: 3px;
    }
  }
}
.content {
  padding: 0 16px;
  margin-top: 16px;
}
.select-box {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  margin-bottom: 10px;
  padding-right: 20px;
  .text1 {
    font-size: 14px;
    color: #414f64;
    margin-right: 5px;
  }
  .select-item {
    background-color: #f4f7fc;
    padding: 5px;
    min-width: 92px;
    height: 32px;
    border-raduis: 4px;
    font-size: 14px;
    color: #414f64;
    display: flex;
    align-items: center;
    .label {
      flex: 1;
    }
    .icon-down {
      flex-shrink: 0;
      display: inline-block;
      width: 14px;
      height: 14px;
      background: url("@/assets/images/down.png") no-repeat;
      background-size: 100% 100%;
      margin-left: 5px;
    }
  }
}
.card-box {
  display: flex;
  justify-content: space-between;
  padding: 15px 10px;
  .card-item {
    width: 101px;
    height: 104px;
    background: url("@/assets/images/disasterRiskMonitor/geologicalDisaster/card3.png")
      no-repeat;
    background-size: 100% 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding-top: 9px;
    &:nth-child(2) {
      background: url("@/assets/images/disasterRiskMonitor/geologicalDisaster/card4.png")
        no-repeat;
      background-size: 100% 100%;
    }
    &:nth-child(3) {
      background: url("@/assets/images/disasterRiskMonitor/geologicalDisaster/card5.png")
        no-repeat;
      background-size: 100% 100%;
    }
    .text1 {
      font-size: 14px;
      color: #414f64;
      line-height: 26px;
    }
    .text-box {
      display: flex;
      align-items: baseline;
      .text2 {
        font-size: 24px;
        font-weight: bold;
        color: #ff2f3c;
      }
      .text3 {
        font-size: 12px;
        color: #414f64;
        line-height: 26px;
        margin-left: 5px;
      }
    }
  }
}
.card {
  background-color: #ffffff;
  border: 1px solid #eaedf7;
  box-shadow: 0 0 4px 0 #4554661a;
  border-radius: 4px;
  padding: 2px;
  margin-top: 16px;
  &:first-child {
    margin-top: 0;
  }
  .card-header {
    font-size: 16px;
    color: #414f64;
    font-weight: bold;
    line-height: 26px;
    padding: 11px 10px;
    display: flex;
    align-items: center;
    border-top-left-radius: 4px;
    border-top-right-radius: 4px;
    background-image: linear-gradient(180deg, #f3f7fd 0%, #ffffff 100%);
    .flex {
      display: flex;
      align-items: center;
    }
    .icon-line {
      display: inline-block;
      width: 6px;
      height: 16px;
      background: url("@/assets/images/line.jpg") no-repeat;
      background-size: 100% 100%;
      margin-right: 3px;
    }
  }
  .sub-text {
    font-size: 12px;
    padding: 0 5px;
    color: rgba(0, 0, 0, 0.45);
    margin-top: -7px;
  }
  .sub-text2 {
    font-size: 12px;
    font-weight: normal;
    padding: 0 5px;
    color: #7f8b9f;
  }
  .card-content {
    padding: 0 5px 13px 8px;
    //padding-bottom: 13px;
    display: flex;
    justify-content: space-between;
    .card1 {
      width: 147px;
      height: 99px;
      background: url("@/assets/images/disasterRiskMonitor/forestFirePrevention/card5.png")
        no-repeat;
      background-size: 100% 100%;
      box-shadow: 0 2px 11px 0 rgba(44, 129, 255, 0.1);
      padding: 5px 15px;
      color: #ff2f3c;
      .text1 {
        font-size: 16px;
        font-weight: bold;
      }
      .text2 {
        font-size: 18px;
        font-weight: bold;
      }
      .text {
        font-size: 14px;
      }
    }
    .card2 {
      width: 169px;
      height: 99px;
      padding: 5px 8px;
      background: url("@/assets/images/disasterRiskMonitor/forestFirePrevention/card6.png")
        no-repeat;
      background-size: 100% 100%;
      box-shadow: 0 2px 11px 0 rgba(44, 129, 255, 0.1);
      display: flex;
      flex-direction: column;
      justify-content: space-between;
      .tr {
        display: flex;
        justify-content: space-between;
        align-items: center;
        &:nth-child(1) {
          color: #ff2f3c;
        }
        &:nth-child(2) {
          color: #ff7d00;
        }
        &:nth-child(3) {
          color: #ffd45e;
        }
        .text1 {
        }
        .td {
          margin: 0 2px;
          font-size: 13px;
          &:nth-child(3) {
            font-size: 15px;
            font-weight: bold;
          }
        }
      }
    }
  }
  .card-content2 {
    padding-bottom: 7px;
    display: flex;
    flex-direction: column;
    align-items: center;
    .card1 {
      width: 341px;
      height: 84px;
      background: url("@/assets/images/disasterRiskMonitor/forestFirePrevention/card1.png")
        no-repeat;
      background-size: 100% 100%;
      padding: 5px 185px 5px 27px;
      display: flex;
      flex-direction: column;
      justify-content: center;
      align-items: center;
    }
    .text1 {
      font-size: 14px;
      color: #414f64;
      line-height: 26px;
    }
    .text-box {
      display: flex;
      align-items: center;
      .text-blue {
        font-size: 24px;
        color: #2c81ff;
        font-width: bold;
      }
      .text-red {
        font-size: 24px;
        color: #ff2f3c;
        font-width: bold;
      }
      .text-orange {
        font-size: 24px;
        color: #ffaf00;
        font-width: bold;
      }
      .text-green {
        font-size: 24px;
        color: #40c75f;
        font-width: bold;
      }
      .text2 {
        font-size: 12px;
        color: #414f64;
      }
    }
    .flex-box {
      width: 328px;
      display: flex;
      justify-content: space-between;
    }
    .card2 {
      background: url("@/assets/images/disasterRiskMonitor/forestFirePrevention/card2.png")
        no-repeat;
    }
    .card3 {
      background: url("@/assets/images/disasterRiskMonitor/forestFirePrevention/card3.png")
        no-repeat;
      box-shadow: 0 1px 6px 0 rgba(245, 225, 160, 0.24);
    }
    .card4 {
      background: url("@/assets/images/disasterRiskMonitor/forestFirePrevention/card4.png")
        no-repeat;
      box-shadow: 0 0 4px 0 rgba(69, 84, 102, 0.1);
    }
    .card2,
    .card3,
    .card4 {
      width: 106px;
      height: 71px;
      background-position: center center;
      background-size: 118px 84px;
      padding: 5px 27px 5px 27px;
      display: flex;
      flex-direction: column;
      justify-content: center;
      align-items: center;
    }
  }
  .card-content3 {
    .box1 {
      display: flex;
      align-items: center;
      margin: 12px 12px 12px 16px;
      .select-box {
        width: 80px;
        margin-left: 10px;
        display: flex;
        align-items: center;
        .icon-down {
          margin-left: 3px;
          display: inline-block;
          flex-shrink: 0;
          width: 14px;
          height: 14px;
          background: url("@/assets/images/down.png") no-repeat;
          background-size: 100% 100%;
        }
      }
    }
    .box2 {
      padding: 0 30px;
      display: flex;
      justify-content: space-between;
      .box-item {
        .icon1 {
          background: url("@/assets/images/disasterRiskMonitor/forestFirePrevention/icon1.png")
            no-repeat;
        }
        .icon2 {
          background: url("@/assets/images/disasterRiskMonitor/forestFirePrevention/icon2.png")
            no-repeat;
        }
        .icon3 {
          background: url("@/assets/images/disasterRiskMonitor/forestFirePrevention/icon3.png")
            no-repeat;
        }
        .icon1,
        .icon2,
        .icon3 {
          display: inline-block;
          width: 48px;
          height: 48px;
          background-size: 100% 100%;
          box-shadow:
            0 2px 1px -1px #bcd7ffb5,
            inset 0 1px 3px 6px #ace2ff08;
          border-radius: 11px;
        }
        .text1 {
          font-size: 14px;
          color: #414f64;
          line-height: 26px;
        }
        .text-box {
          display: flex;
          align-items: center;
          .text-blue {
            font-size: 24px;
            margin-right: 5px;
            color: #80c2ff;
          }
          .text-orange {
            font-size: 24px;
            margin-right: 5px;
            color: #ffaf00;
          }
          .text-red {
            font-size: 24px;
            margin-right: 5px;
            color: #ff2f3c;
          }
        }
      }
    }
  }
}
</style>
