<template>
  <div class="container">
    <div class="card">
      <div class="card-header">
        <i class="icon-line" />
        <div class="text">气温降水实况</div>
      </div>
      <div class="card-content">
        <div class="flex-end">
          <el-select v-model="tabActive" :teleported="false" cl>
            <el-option
              v-for="item in tabs"
              :key="item.value"
              :label="item.name"
              :value="item.value"
            />
          </el-select>
        </div>
        <img
          class="img-box"
          :src="liveMapState.data[0] ? liveMapState.data[0].pic_url : ''"
        />
      </div>
    </div>
    <div class="card">
      <div class="card-header">
        <i class="icon-line" />
        <div class="text">气象卫星图</div>
      </div>
      <div class="card-content">
        <img class="img-box" :src="temp1" />
      </div>
    </div>
    <div class="card">
      <div class="card-header">
        <i class="icon-line" />
        <div class="text">一周预报</div>
      </div>
      <div class="card-content3">
        <div v-for="(item, index) in weekForecast" :key="index" class="card-item">
          <div class="text1">{{ item.name }}</div>
          <div class="text1"><i :class="getClass(item.type1)" />{{ item.type1 }}</div>
          <div class="text1">{{ item.data1 }}℃</div>
          <div class="text1">{{ item.data2 }}</div>
          <div class="text1">|</div>
          <div class="text1"><i :class="getClass(item.type2)" />{{ item.type2 }}</div>
          <div class="text1">{{ item.data3 }}℃</div>
          <div class="text1">{{ item.data4 }}</div>
        </div>
      </div>
    </div>
    <div class="card">
      <div class="card-header">
        <i class="icon-line" />
        <div class="text">逐小时预报</div>
      </div>
      <div class="card-content">
        <Chart :option="option1" style="height: 240px" />
      </div>
    </div>
    <div class="card">
      <div class="card-header">
        <i class="icon-line" />
        <div class="text">水库监测</div>
      </div>
      <div class="card-content2">
        <div class="card-item">
          <i class="icon" />
          <div class="flex">
            <div class="text1">漫坝</div>
            <div class="text2 text-red">
              11
              <div class="text3">个</div>
            </div>
          </div>
        </div>
        <div class="card-item">
          <i class="icon" />
          <div class="flex">
            <div class="text1">超保证</div>
            <div class="text2 text-orange">
              40
              <div class="text3">个</div>
            </div>
          </div>
        </div>
        <div class="card-item">
          <i class="icon" />
          <div class="flex">
            <div class="text1">超警戒</div>
            <div class="text2 text-blue">
              37
              <div class="text3">个</div>
            </div>
          </div>
        </div>
      </div>
    </div>
    <div class="card">
      <div class="card-header">
        <i class="icon-line" />
        <div class="text">河道监测</div>
      </div>
      <div class="card-content2">
        <div class="card-item">
          <i class="icon" />
          <div class="flex">
            <div class="text1">漫坝</div>
            <div class="text2 text-red">
              30
              <div class="text3">个</div>
            </div>
          </div>
        </div>
        <div class="card-item">
          <i class="icon" />
          <div class="flex">
            <div class="text1">超保证</div>
            <div class="text2 text-orange">
              69
              <div class="text3">个</div>
            </div>
          </div>
        </div>
        <div class="card-item">
          <i class="icon" />
          <div class="flex">
            <div class="text1">超警戒</div>
            <div class="text2 text-blue">
              41
              <div class="text3">个</div>
            </div>
          </div>
        </div>
      </div>
    </div>
    <div class="card">
      <div class="card-header">
        <i class="icon-line" />
        <div class="text">易涝点</div>
      </div>
      <div class="card-content2">
        <el-table
          :data="detailsData.dataList"
          header-cell-class-name="common-table-header"
          :row-class-name="getTableRowClass"
          table-layout="auto"
          class="common-table"
        >
          <el-table-column prop="area" align="center">
            <template #header>
              <div class="table-line" @click="showPicker = true">
                <div>{{ !!labelData ? labelData : "所有区县" }}</div>
                <i class="icon-down" />
              </div>
            </template>
          </el-table-column>
          <el-table-column label="易涝点名称" prop="name" align="center" />
          <el-table-column label="提供单位" prop="data1" align="center" />
          <el-table-column label="视频" prop="publicTime" align="center">
            <template #default="scope">
              <div class="btn" @click="handlePlay">播放</div>
            </template>
          </el-table-column>
        </el-table>
      </div>
    </div>
    <van-popup v-model:show="showPicker" round position="bottom">
      <van-picker
        :columns="columns"
        @cancel="showPicker = false"
        @confirm="onSelectTypeConfirm"
      />
    </van-popup>
  </div>
</template>

<script lang="ts" setup>
import { ElSelect, ElOption, ElTable, ElTableColumn } from "element-plus";
import { onMounted, reactive, ref, watch } from "vue";
import { getTemperature } from "@/api/disasterRiskMonitor/windAndFloodPrevention";
import temp1 from "@/assets/temp1.jfif";
import { chartOption2 } from "./chartOptions";

let tabs = reactive([
  { name: "6h降水", value: "6h_precipitation" },
  { name: "24h降水", value: "24h_precipitation" },
  { name: "整点气温", value: "hourly_temperature" },
  { name: "24h最高温", value: "24h_max_temperature" },
  { name: "24h最低温", value: "24h_min_temperature" },
  { name: "24小时变温", value: "24h_variable_temperature" }
]);
let tabActive = ref("hourly_temperature");

const liveMapState = reactive({
  show: false,
  activeIndex: 0,
  speed: 1,
  playing: false,
  data: []
});
let weekForecast = ref([
  { name: '今天', type1: '晴', data1: '32.6', data2: '小于3级', type2: '阴', data3: '32.6', data4: '小于3级' },
  { name: '今天', type1: '晴', data1: '32.6', data2: '小于3级', type2: '阴', data3: '32.6', data4: '小于3级' },
  { name: '今天', type1: '雷雨', data1: '32.6', data2: '小于3级', type2: '阴', data3: '32.6', data4: '小于3级' },
  { name: '今天', type1: '晴', data1: '32.6', data2: '小于3级', type2: '阴', data3: '32.6', data4: '小于3级' },
  { name: '今天', type1: '雷雨', data1: '32.6', data2: '小于3级', type2: '阴', data3: '32.6', data4: '小于3级' },
  { name: '今天', type1: '晴', data1: '32.6', data2: '小于3级', type2: '阴', data3: '32.6', data4: '小于3级' },
  { name: '今天', type1: '晴', data1: '32.6', data2: '小于3级', type2: '阴', data3: '32.6', data4: '小于3级' },
]);
let detailsData = ref({
  dataList: []
});
let showPicker = ref(false);
let labelData = ref("");
const columns = ref([
  { text: "所有区县", value: "" },
  { text: "茂南区", value: "1" },
  { text: "信宜市", value: "2" }
]);
let queryParams = reactive({
  area: ""
});
const option1 = ref(chartOption2);
watch(
  () => liveMapState.show,
  () => {
    if (!liveMapState.show) {
      liveMapState.playing = false;
      liveMapState.activeIndex = 0;
    }
  },
  {
    immediate: true
  }
);
const onSelectTypeConfirm = ({ selectedOptions }) => {
  showPicker.value = false;
  labelData.value = selectedOptions[0].text;
  queryParams.area = selectedOptions[0].value;
  initData();
};

const getClass = (name) => {
  let res = ''
  if (name === '晴') {
    res = 'icon1'
  } else if (name === '阴') {
    res = 'icon2'
  } else if (name === '雷雨') {
    res = 'icon3'
  }
  return res
}

const initData = () => {
  getTemperature({ args: tabActive.value }).then(res => {
    liveMapState.data = res.data.max_level;
  });
  detailsData.value.dataList = [
    { area: "茂南区", name: "高山铁路桥底", data1: "城市管理和综合执法局" },
    { area: "茂南区", name: "油城二路桥底", data1: "城市管理和综合执法局" },
    { area: "茂南区", name: "榕园东北侧", data1: "城市管理和综合执法局" },
    { area: "茂南区", name: "人民中路", data1: "城市管理和综合执法局" },
    { area: "化州市", name: "橘城南路", data1: "城市管理和综合执法局" },
    { area: "化州市", name: "下郭大道", data1: "城市管理和综合执法局" },
    { area: "化州市", name: "河西沙埚村", data1: "城市管理和综合执法局" }
  ];
  option1.value.xAxis.data = [
    "19时",
    "20时",
    "21时",
    "22时",
    "23时",
    "24时",
    "1时",
    "2时",
    "3时",
    "40时",
    "5时",
    "6时",
    "7时",
    "8时",
    "9时",
    "10时",
    "11时",
    "12时",
    "13时",
    "14时",
    "15时",
    "16时",
    "17时",
    "18时"
  ];
  option1.value.series[0].data = [
    "22",
    "22",
    "21",
    "21",
    "20",
    "20",
    "19",
    "19",
    "19",
    "20",
    "21",
    "22",
    "22",
    "23",
    "24",
    "25",
    "25",
    "25",
    "24",
    "23",
    "24",
    "23",
    "22",
    "22"
  ];
  option1.value.series[1].data = [
    "0.0",
    "0.0",
    "0.0",
    "0.0",
    "0.0",
    "0.0",
    "0.0",
    "0.0",
    "0.0",
    "0.0",
    "0.0",
    "0.0",
    "0.0",
    "0.0",
    "11.0",
    "13.0",
    "10.0",
    "9.0",
    "0.0",
    "0.0",
    "0.0",
    "0.0",
    "0.0",
    "0.0"
  ];
};

// table样式
const getTableRowClass = ({ rowIndex }) => {
  return rowIndex % 2 === 0 ? "" : "common-table-tr";
};

const handlePlay = id => {};
onMounted(() => {
  initData();
});
</script>

<style lang="scss" scoped>
.container {
  height: calc(100vh);
  padding: 16px;
  .card {
    background-color: #ffffff;
    border: 1px solid #eaedf7;
    box-shadow: 0 0 4px 0 #4554661a;
    border-radius: 4px;
    background-image: linear-gradient(
      to bottom,
      #f3f7fd 0%,
      #f7fafe 20px,
      #fcfdff 50px,
      #ffffff 50px,
      #ffffff 100%
    );
    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;
      .icon-line {
        display: inline-block;
        width: 6px;
        height: 16px;
        background: url("@/assets/images/line.jpg") no-repeat;
        background-size: 100% 100%;
        margin-right: 3px;
      }
    }
    .card-content {
      padding-bottom: 13px;
      .flex-end {
        display: flex;
        justify-content: flex-end;
        padding: 0 5px;
        .el-select {
          width: 120px;
        }
      }
      .img-box {
        cursor: pointer;
        margin-top: 13px;
      }
    }
    .card-content2 {
      display: flex;
      justify-content: space-between;
      align-items: center;
      .card-item {
        width: 106px;
        height: 71px;
        background: url("@/assets/images/disasterRiskMonitor/windAndFloodPrevention/box1.png")
          no-repeat;
        background-size: 100% 100%;
        display: flex;
        align-items: center;
        padding: 10px 13px;
        .icon {
          display: inline-block;
          width: 18px;
          height: 18px;
          background: url("@/assets/images/disasterRiskMonitor/windAndFloodPrevention/icon1.png")
            no-repeat;
          background-size: 100% 100%;
        }
        .flex {
          display: flex;
          flex-direction: column;
          margin-left: 16px;
          .text1 {
            font-size: 12px;
          }
          .text2 {
            display: flex;
            align-items: baseline;
            font-size: 24px;
            font-weight: bold;
          }
          .text3 {
            font-size: 12px;
            font-weight: normal;
            color: #414f64;
          }
          .text-red {
            color: #ff2f3c;
          }
          .text-orange {
            color: #ffaf00;
          }
          .text-blue {
            color: #2c81ff;
          }
        }
      }
    }
    .card-content3 {
      display: flex;
      padding-bottom: 16px;
      overflow-x: auto;
      .card-item {
        display: flex;
        flex-direction: column;
        align-items: center;
        min-width: 60px;
        height: 194px;
        background-image: linear-gradient(180deg, #FFFFFF 0%, #F6F9FF 79%, #F8FAFF 100%);
        border: 2px solid #FFFFFF;
        box-shadow: 0 2px 1px -1px #bcd7ffb5, inset 0 1px 3px 6px #ace2ff08;
        border-radius: 4px;
        margin-left: 5px;
        padding: 20px 5px;
        &:first-child {
          margin-left: 0;
        }
        .text1 {
          display: flex;
          justify-content: center;
          align-items: center;
          font-size: 12px;
          color: #414F64;
          line-height: 21px;
        }
      }
    }
  }
  .btn {
    font-size: 14px;
    color: #2c81ff;
  }
}
</style>
