<template>
  <div class="tv-list" :style="'font-size:' + fontSize + 'px'">
    <div class="content">
      <img
        src="@/assets/image/top.png"
        alt=""
        style="
          width: 79vw;
          max-width: 527px;
          display: block;
          margin: 3.6vh auto 0 auto;
        "
      />
      <div
        class="group"
        v-for="(item, index) in dataOne"
        :key="item.title + index"
      >
        <p class="headTitle" v-text="item.title"></p>

        <!-- 月历主页 -->
        <div class="monthlyCalendar">
          <div class="title" v-text="item.Month"></div>

          <div class="CalenMain">
            <div class="CalenRow CalenHead">
              <div class="CalenCol">MON</div>
              <div class="CalenCol">TUE</div>
              <div class="CalenCol">WED</div>
              <div class="CalenCol">THU</div>
              <div class="CalenCol">FRI</div>
              <div class="CalenCol">SAT</div>
              <div class="CalenCol">SUN</div>
            </div>
            <div
              class="CalenRow CalenBody"
              v-for="(v, i) in item.data"
              :key="i"
            >
              <div v-for="(son, o) in v" :key="o" class="CalenCol">
                <div v-if="son">
                  <div class="dayDate">
                    <div class="dayDate_son">{{ son.day }}</div>
                  </div>

                  <div class="text" v-text="son.value"></div>
                </div>
              </div>
            </div>
          </div>
        </div>
      </div>
      <img
        src="@/assets/image/logo.png"
        style="
          width: 18.8vw;
          max-width: 125px;
          margin: 1em auto;
          display: block;
        "
        alt=""
      />
    </div>
    <div class="bottom content">
      本数据由“陕西广电融媒体集团大数据平台”提供。
      <p>
        技术支持 <span style="white-space: nowrap">白帆13325452244;</span
        ><span style="white-space: nowrap">陈科18629350958。</span>
      </p>
    </div>
  </div>
</template>

<script>
// @ is an alias to /src
import watermark from "watermark-package";
import DayJs from "dayjs";
// import {} from "../utils/tool";
import { jsonCalendarOne } from "../../../api/index";

// import echarts from "../../../utils/echarts";

export default {
  name: "Calendar",
  data() {
    return {
      fontSize: 17,
      dataOne: [],
      weeks: {
        MON: 1,
        TUE: 2,
        WED: 3,
        THU: 4,
        FRI: 5,
        SAT: 6,
        SUN: 7,
      },
    };
  },
  watch: {},
  mounted() {
    if (
      this.$route.query.auto !==
      "06fd56cdf5a6cfc3a2139cc8514d05aa0439ee8c1fb4d81145bc9647"
    )
      return;
    this.fontSize = (document.body.offsetWidth / 24).toFixed(2) - 0;
    if (document.body.offsetWidth > 677) this.fontSize = 22;
    watermark.setWaterMark({
      w_texts: ["陕西新媒体大数据"],
      w_options: {
        w_opacity: "0.1",
      },
    });
    jsonCalendarOne({
      date: this.$route.params.date,
      time: Date.now(),
    }).then(res => {
      let dataOne = res || [];
      for (let i = 0; i < dataOne.length; i++) {
        const li = [];
        const v = dataOne[i];
        // 判断第一天是周几，不是周一向前补到周一，最后一天不是周日补到周日
        const Month = JSON.parse(JSON.stringify(v.data || []));
        v.Month = this.getMonth(v.data[0].dt);
        for (let o = 0; o < Month.length; o++) {
          const item = Month[o];
          const dt = new DayJs(item.dt);
          Month[o].week = dt.format("ddd").toLocaleUpperCase();
          Month[o].weekNum = dt.format("d") === 0 ? 7 : dt.format("d");
          Month[o].day = dt.format("D");
          if (o % 7 === 0) li.push([]);
          const li_index = li.length ? li.length - 1 : 0;
          li[li_index].push(Month[o]);
        }
        if (Month[0].weekNum !== 1)
          li[0].unshift(...new Array(Month[0].weekNum - 1));
        const li_out_index = li.length ? li.length - 1 : 0;
        if (Month.reverse()[0].weekNum !== 7)
          li[li_out_index].push(...new Array(7 - Month[0].weekNum));
        v.data = li;
      }
      console.log(dataOne);
      this.dataOne = dataOne;
    });
  },
  computed: {},
  methods: {
    getMonth(date) {
      if (!date) return "";
      let out = new DayJs(date);
      return out.format("YYYY年MM月");
    },
  },
  beforeUnmount() {},
  components: {
  },
};
</script>

<style scoped>
.tv-list {
  background-color: #f5b379;
  padding: 5px;
  height: 100%;
  overflow-y: auto;
  box-sizing: border-box;
}
.bottom {
  border: 4px solid #0983a8;
  margin-top: 1em;
  padding: 10px;
  font-size: 0.9rem;
  padding-left: 5px;
  font-weight: 600;
  overflow: hidden;
}
.content {
  margin: 0 auto;
  max-width: 667px;
}

.group {
  margin-bottom: 2em;
}

.headTitle {
  font-size: 1.5rem;
  text-align: center;
  font-family: SourceHanSansCN;
  font-weight: bold;
  color: #be651a;
  line-height: 30px;
  text-shadow: 0 0 10px #fff,0 0 20px #fff,0 0 30px #fff;
}

.headSubTitle {
  text-align: center;
  font-size: 1.2rem;
  font-family: SourceHanSansCN;
  font-weight: 400;
  color: #a22626;
  line-height: 30px;
}

.monthlyCalendar {
  background-image: url("../../../assets/image/C_bg.png");
  background-size: 100% 100%;
  width: 100%;
  padding: 2em 1px 0 1px;
  max-width: 614px;
  margin: 0 auto;
  /* width: 92vw;
    height: 117vw; */
}

.title {
  font-size: 1.5rem;
  font-family: STHupo;
  font-weight: 400;
  line-height: 30px;
  padding: 5px;
}

.CalenRow {
  display: flex;
  overflow: hidden;
}
.CalenCol {
  flex: 1;
  text-align: center;
}
.CalenHead {
  font-size: 1.01rem;
  height: 1.5em;
  line-height: 1.5em;
  font-weight: 400;
  color: #fff;
  background-color: #dc721a;
  border-radius: 2em;
}

.dayDate {
  padding: 0 5px;
  box-sizing: border-box;
  width: 1.5em;
  height: 1.5em;
  line-height: 1.5em;
  font-size: 1.3rem;
  font-family: Adobe Heiti Std;
  font-weight: normal;
  color: #c31212;
  background-color: #f4f4f4;
  transform: rotate(45deg);
  margin: 0 auto;
}

.dayDate_son {
  width: 100%;
  height: 100%;
  transform: rotate(-45deg);
}

.CalenBody .CalenCol {
  padding: 10px 0;
}
.text {
  background-image: url("../../../assets/image/text.png");
  background-size: 100% 100%;
  margin: 0.5em 3px 0 3px;
  height: 1.3em;
  line-height: 1.3em;
  padding: 0 3px;
  color: #c31212;
  font-size: 0.8rem;
}
</style>
<style></style>
