<template>
  <div class="calendar" :style="'font-size:' + fontSize + 'px'">
    <div
      :class="{ group: true, content: 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-html="item.title"></p>
        <p class="subTitle" v-text="item.subTitle"></p>
        <div
          v-if="item.data.length"
          class="monthlyCalendar"
          style="position: relative"
        >
          <img
            src="../../../assets/image/C_bg.png"
            style="
              width: 100%;
              float: left;
              position: absolute;
              z-index: 0;
              top: 0;
            "
            alt=""
          />
          <div v-for="(v1, i1) in item.data" :key="i1">
            <!-- 月历主页 -->
            <div style="margin-bottom: 1em; position: relative; z-index: 1">
              <div style="display: flex">
                <div class="title" style="flex: 1" v-text="v1.month"></div>
                <div
                  class="title"
                  style="
                    flex: 1;
                    text-align: right;
                    font-size: 0.9rem;
                    color: #383636;
                  "
                  v-html="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">
                      <div class="dayDate">
                        <div
                          class="dayDate_son"
                          :style="son.is_curr !== 0 ? 'color: #000' : ''"
                        >
                          {{ son.day }}
                        </div>
                      </div>
                      <div
                        v-if="son.value"
                        class="text"
                        v-html="son.value"
                        :style="son.is_curr !== 0 ? 'color: #383636' : ''"
                      ></div>
                      <div v-if="!son.value" style="1em"></div>
                    </div>
                  </div>
                </div>
              </div>
            </div>

            <p
              style="
                text-align: left;
                margin: 0 auto;
                width: 82.5%;
                max-width: 614px;
                padding: 3px;
                font-size: 0.8rem;
              "
              v-html="item.buttomText"
            ></p>
          </div>
        </div>
      </div>
    </div>
    <div class="bottom content">
      本数据由<span style="color: red">“陕西广电融媒体集团大数据平台”</span
      >提供。
      <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 { jsonCalendarOne } from "../../../api/index";

import report from "../mixin/index.js";

export default {
  name: "Calendar",
  data() {
    return {
      fontSize: 17,
      dataOne: [],
    };
  },
  watch: {},
  mixins: [report],
  computed: {},
  methods: {
    init() {
      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",
        },
      });
      let D = this.$route.params.date == 'auto' ? this.lastTimeDate.calendar : this.$route.params.date;
      jsonCalendarOne({
        date: D,
        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;
      });
    },
    isQDXW(t) {
      return /起点新闻/g.test(t);
    },
  },
  beforeUnmount() {},
  components: {},
};
</script>

<style scoped>
.calendar {
  height: 100%;
  overflow-y: auto;
  box-sizing: border-box;
  color: #000;
}
.content {
  margin: 0 auto;
  max-width: 667px;
}
.bottom {
  border: 4px solid #0983a8;
  background-color: #cdcdcd;
  color: #000;
  padding: 10px;
  font-size: 0.85rem;
  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;
  line-height: 30px;
}

.subTitle {
  font-size: 1.2rem;
  text-align: center;
  font-family: SourceHanSansCN;
  line-height: 30px;
}

.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%; */
  background-color: #fff;
  overflow: hidden;
  width: 83.6%;
  height: calc((82.5% - 10px) * 1.5);
  padding: 1.5em 1px 0 1px;
  max-width: 614px;
  margin: 0 auto;
  margin-top: 1.5em;
}

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

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

.CalenRow {
  display: flex;
  overflow: hidden;
}
.CalenCol {
  flex: 1;
  flex-shrink: 0;
  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: #84868c;
  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;
  border-left: 1px solid #eee;
  border-bottom: 1px solid #eee;
}
.text {
  margin: 0.5em 1px 0 1px;
  padding: 1px 0;
  font-size: 0.8rem;
  height: 1.3em;
  color: #84868c;
  line-height: 1.3em;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}
</style>
<style></style>
