<template>
  <div class="app-container">
    <TagCard>
      <template #title>
        各入口预约情况
        <el-date-picker
          v-model="searchDate"
          type="date"
          placeholder="选择时间"
          value-format="yyyy-MM-dd"
          style="width: 140px;margin-left: 20px"
        />
      </template>
      <div class="chart-container">
        <div class="chart__title">
          <span>总预约数</span>
          <span>69898</span>
        </div>
        <chart :id="chartId" class="chart__bar" height="400px" width="100%" :options="chartOptions" />
      </div>
    </TagCard>
    <TagCard style="margin-top: 20px">
      <template #title>
        今日各入口各时段预约情况
        <div class="timePeriod-state">
          <div class="item">空闲</div>
          <div class="item">普通</div>
          <div class="item">拥挤</div>
          <div class="item">繁忙</div>
        </div>
      </template>
      <div class="timePeriod-container">
        <div v-for="(item, index) in entryAppointArr" :key="index" class="item">
          <div class="item_top">
            <span>{{ item.title }}</span>
            <span>已预约 {{ item.num }}</span>
          </div>
          <div class="item_content">
            <div v-for="(pItem, pIndex) in item.timePeriod" :key="pIndex" class="item_content__card">
              <span>{{ pItem.startTime }}~{{ pItem.endTime }}</span>
              <span>已约 {{ pItem.reservation }}</span>
              <span>峰值 {{ pItem.num }}</span>
            </div>
          </div>
        </div>
      </div>
    </TagCard>
  </div>
</template>

<script>
import TagCard from '@/components/TagCard';
import Chart from '@/components/Charts/Keyboard';
export default {
  components: { TagCard, Chart },
  filters: {
    matchNull(str) {
      if (!str) {
        return '未填写';
      } else {
        return str;
      }
    }
  },
  data() {
    return {
      searchDate: new Date(),
      chartId: null,
      chartOptions: {},
      entryAppointArr: [
        {
          title: '兰花街1、2、3',
          num: 13143,
          timePeriod: [
            {
              startTime: '08:00',
              endTime: '10:00',
              num: 20000,
              reservation: 1352
            },
            {
              startTime: '08:00',
              endTime: '10:00',
              num: 20000,
              reservation: 1352
            },
            {
              startTime: '08:00',
              endTime: '10:00',
              num: 20000,
              reservation: 1352
            },
            {
              startTime: '08:00',
              endTime: '10:00',
              num: 20000,
              reservation: 1352
            },
            {
              startTime: '08:00',
              endTime: '10:00',
              num: 20000,
              reservation: 1352
            },
            {
              startTime: '08:00',
              endTime: '10:00',
              num: 20000,
              reservation: 1352
            }
          ]
        },
        {
          title: '洲芳停车场口一号',
          num: 12143
        },
        {
          title: '洲芳停车场口二号',
          num: 11143
        },
        {
          title: '古城口ABC',
          num: 11043
        },
        {
          title: '玉满楼1、2',
          num: 10002
        },
        {
          title: '接风楼',
          num: 9901
        },
        {
          title: '老派出所门口',
          num: 9852
        },
        {
          title: '独立营上口1、2',
          num: 9502
        },
        {
          title: '独立营下口',
          num: 9312
        },
        {
          title: '市一中正门',
          num: 9120
        },
        {
          title: '下八河',
          num: 8912
        },
        {
          title: '南门',
          num: 8426
        },
        {
          title: '邦恒路口',
          num: 7995
        },
        {
          title: '和府酒店',
          num: 7806
        },
        {
          title: '忠义市场1、2',
          num: 7410
        },
        {
          title: '橡树园',
          num: 7302
        },
        {
          title: '滇菌王酒店',
          num: 7210
        }
      ]
    };
  },
  created() {
    this.chartId = 'XXX';
    const xAxisData = [];
    const seriesData = [];
    this.entryAppointArr.forEach(item => {
      xAxisData.push(item.title);
      seriesData.push(item.num);
    });
    this.chartOptions = {
      grid: {
        left: '80px',
        right: '40px'
        // bottom: '0'
      },
      xAxis: {
        type: 'category',
        interval: 0,
        data: xAxisData,
        axisLabel: {
          color: '#304156',
          rotate: 20
        },
        axisTick: { //  刻度线
          show: false
        },
        axisLine: { // 坐标轴线
          show: false
        },
        splitLine: { // 分割线
          show: false
        }
      },
      yAxis: {
        type: 'value',
        axisLabel: {
          color: '#C3CCDE'
        },
        axisTick: { //  刻度线
          show: false
        },
        axisLine: { // 坐标轴线
          show: false
        },
        splitLine: { // 分割线
          show: false
        }
      },
      series: [
        {
          data: seriesData,
          type: 'bar',
          barWidth: '6px',
          itemStyle: {
            normal: {
              color: '#409EFF',
              barBorderRadius: [8, 8, 8, 8],
              label: {
                show: true, // 关键点开启显示
                position: 'top', // top上方;left左侧;right右方显示
                textStyle: { // 数值样式
                  color: '#77A0DD',
                  fontSize: 14
                }
              }
            }
          }
        }
      ]
    };
  },
  methods: {
  }
};
</script>

<style lang="scss" scoped>
.chart-container {
  box-shadow: 0px 4px 16px 0px #3326AE0A;
  border: 1px solid #F3F6FF;
  background: #FFFFFF;
  min-width: 1000px;
  height: 500px;
  padding: 20px;
  border-radius: 12px;
  position: relative;
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  margin-top: 10px;

  .chart__title {
    display: flex;
    background: #E3EBFF57;
    width: 700px;
    height: 80px;
    line-height: 80px;
    border-radius: 12px;
    justify-content: center;
    span {
      &:first-child{
        color: #333333;
        font-size: 24px;
        font-weight: 700;
        margin-right: 20px;
      }
      &:last-child{
        color: #1588FF;
        font-size: 40px;
        font-weight: 700;
      }
    }
  }

  .chart__bar {
    position: absolute;
    bottom: 0;
  }
}

.timePeriod-state {
  display: flex;
  flex-direction: row;
  justify-content: center;
  margin-left: 40px;

  .item {
    width: 60px;
    position: relative;
    height: 20px;
    line-height: 20px;
    margin-left: 10px;
    color: #858DA5;
    font-size: 14px;
    font-weight: 500;
    &:before {
      text-align: center;
      position: absolute;
      content: "";
      top: calc(50% - 6px);
      left: -22px;
      width: 12px;
      height: 12px;
      border-radius: 50%;
    }
    &:nth-child(1){
      &:before {
        background: #7AE3FA;
      }
    }
    &:nth-child(2){
      &:before {
        background: #6DC2FF;
      }
    }
    &:nth-child(3){
      &:before {
        background: #FFD19B;
      }
    }
    &:nth-child(4){
      &:before {
        background: #FFBCDC;
      }
    }
  }
}

.timePeriod-container {
  display: flex;
  flex-direction: row;
  flex-wrap: wrap;
  margin-top: 10px;

  .item {
    width: calc((100% - 40px) / 3);
    height: 250px;
    box-shadow: 0px 4px 16px 0px #3326AE0A;
    border: 1px solid #F3F6FF;
    padding: 20px;
    border-radius: 12px;

    &_content {
      display: flex;
      flex-direction: row;
      flex-wrap: wrap;
      margin-top: 10px;
      &__card {
        background: #F6F8FC;
        width: calc((100% - 24px) / 4);
        height: 75px;
        border-radius: 6px;
        padding: 6px;
        display: flex;
        flex-direction: column;
        justify-content: space-between;
        align-items: center;
        span {
          height: 20px;
          line-height: 20px;
          font-size: 13px;
          &:nth-child(1) {
            color: #304156;
          }
          &:nth-child(2) {
            color: #636B85;
          }
          &:nth-child(3) {
            color: #6DC2FF;
          }
        }

        &:nth-child(n + 5){
          margin-top: 8px;
        }

        &:not(:nth-child(4n)){
          margin-right: 8px;
        }
      }
    }

    &_top {
      display: flex;
      flex-direction: row;
      justify-content: space-between;
      align-items: center;
      span {
        height: 40px;
        line-height: 40px;

        &:first-child {
          color: #304156;
          font-size: 20px;
          font-weight: bold;
        }

        &:last-child {
          color: #409EFF;
          font-size: 16px;
        }
      }
    }

    &:nth-child(n + 4){
      margin-top: 20px;
    }

    &:not(:nth-child(3n)){
      margin-right: 20px;
    }
  }
}
</style>
