<template>
  <div class="calendar" :style="'font-size:' + fontSize + 'px'">
    <div
      :class="{ group: true, content: true, bg: true }"
      :style="index == dataOne.length - 1 ? 'margin:0 auto;padding-bottom: 1em;padding-bottom: .5em' : ''"
      v-for="(item, index) in dataOne"
      :key="item.title + index"
    >
      <div style="position: relative; z-index: 1">
        <img
          :src="item.img_url"
          alt=""
          style="
            width: 79vw;
            max-width: 527px;
            display: block;
            margin: 3.6vh auto 0 auto;
          "
        />
        <p class="headTitle" v-text="item.title"></p>
        <div v-if="item.data.length">
          <div v-for="(v1, i1) in item.data" :key="i1">
            <!-- 月历主页 -->
            <div class="monthlyCalendar">
              <div style="display: flex">
                <div class="title" style="flex: 1" v-text="v1.month"></div>
                <div
                  class="title"
                  style="flex: 1; text-align: right"
                  v-text="v1.title"
                ></div>
              </div>

              <div class="CalenMain">
                <div class="CalenRow CalenHead">
                  <div class="CalenCol">
                    <p>一</p>
                    <!-- <p>MON</p> -->
                  </div>
                  <div class="CalenCol">
                    <p>二</p>
                    <!-- <p>TUE</p> -->
                  </div>
                  <div class="CalenCol">
                    <p>三</p>
                    <!-- <p>WED</p> -->
                  </div>
                  <div class="CalenCol">
                    <p>四</p>
                    <!-- <p>THU</p> -->
                  </div>
                  <div class="CalenCol">
                    <p>五</p>
                    <!-- <p>FRI</p> -->
                  </div>
                  <div class="CalenCol">
                    <p>六</p>
                    <!-- <p>SAT</p> -->
                  </div>
                  <div class="CalenCol">
                    <p>日</p>
                    <!-- <p>SUN</p> -->
                  </div>
                </div>
                <div
                  class="CalenRow CalenBody"
                  v-for="(v, i) in v1.list"
                  :key="i"
                >
                  <div v-for="(son, o) in v" :key="o" class="CalenCol">
                    <div v-if="son" style="color: #000">
                      <div class="dayDate">
                        <div
                          class="dayDate_son"
                          :style="
                            son.weeks == 0 || son.weeks == 6
                              ? 'color:#c31212'
                              : ''
                          "
                        >
                          {{ son.day }}
                        </div>
                      </div>
                      <div
                        v-if="son.value"
                        class="text"
                        v-text="son.value"
                      ></div>
                      <div v-if="!son.value" style="1em"></div>
                    </div>
                  </div>
                </div>
              </div>
            </div>
          </div>
        </div>
        <img
          src="@/assets/image/logo.png"
          v-if="index == dataOne.length - 1"
          style="
            width: 18.8vw;
            max-width: 125px;
            margin: 0.3em auto;
            display: block;
            position: relative;
            z-index: 2;
          "
          alt=""
        />
      </div>
    </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: [],
    };
  },
  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 item1 = dataOne[i].data ? dataOne[i].data || [] : [];
        for (let o = 0; o < item1.length; o++) {
          const item2 =
            dataOne[i].data && dataOne[i].data
              ? dataOne[i].data[o] || []
              : undefined;
          if (item2 === undefined) continue;
          const dayjs_Start =
            item2.list[0] && item2.list[0].dt
              ? new DayJs(item2.list[0].dt)
              : undefined;
          const item2_Length = item2.list.length ? item2.list.length - 1 : 0;
          const dayjs_Last = item2.list[item2_Length]
            ? new DayJs(item2.list[item2_Length].dt)
            : undefined;
          let first = dayjs_Start ? dayjs_Start.format("d") : undefined;
          let last = dayjs_Last ? dayjs_Last.format("d") : undefined;
          last && last != 0 && (last = 7 - last);
          first && dataOne[i].data[o].list.unshift(...new Array(first - 1));
          last && dataOne[i].data[o].list.push(...new Array(last - 0));
          let li = [];
          for (let p = 0; p < dataOne[i].data[o].list.length; p++) {
            const item3 = dataOne[i].data[o].list[p] || undefined;
            if (p % 7 === 0) li.push([]);
            let end = li.length ? li.length - 1 : 0;
            if (!item3) {
              li[end].push(undefined);
              continue;
            }
            let dt3 = new DayJs(item3.dt);
            item3.day = dt3.format("D");
            item3.weeks = dt3.format("d");
            li[end].push(item3);
          }
          dataOne[i].data[o].list = li;
        }
      }
      this.dataOne = dataOne;
    });
  },
  computed: {},
  methods: {},
  beforeUnmount() {},
  components: {},
};
</script>

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

.group {
  margin-bottom: 2em;
  position: relative;
}

.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; */

  background: -webkit-linear-gradient(#fff, #fff);
  -webkit-background-clip: text;
  -webkit-text-fill-color: #be651a;
  -webkit-text-stroke: 6px transparent;
}

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

.bg {
  background-image: url("../../../assets/image/bg.png");
  background-size: 100% 100%;
  padding-bottom: 1.5em;
}

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

.bgImg {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 0;
}

.title {
  font-size: 1rem;
  font-family: STHupo;
  font-weight: 600;
  line-height: 30px;
  padding: 0.5em 0.8em;
}

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

.dayDate {
  box-sizing: border-box;
  width: 1.3em;
  height: 1.3em;
  line-height: 1.3em;
  font-size: 1.1rem;
  font-family: Adobe Heiti Std;
  color: #000;
  background-color: #f4f4f4;
  transform: rotate(45deg);
  margin: 0 auto 0.3em auto;
}

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

.CalenBody .CalenCol {
  padding: 10px 0;
  font-weight: bold;
  border-left: 1px solid #eee;
  border-bottom: 1px solid #eee;
}
.text {
  background-image: url("../../../assets/image/text.png");
  background-size: 100% 100%;
  margin: 0.5em 1px 0 1px;
  padding: 1px 0;
  font-size: 0.8rem;
  height: 1.3em;
  line-height: 1.3em;
  color: #c31212;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}
</style>
<style></style>
