<template>
  <div id="partyAffairs" class="app">
    <van-tabs v-model="active" sticky animated swipeable>
      <van-tab v-for="(item, i) in column" :key="i" :title="item.title">
        <div class="partyBody">
          <news-list v-if="!item.type" :comId="item.id" />
          <div v-if="item.type === '1'">
            <div
              v-for="item in special"
              :key="item.id"
              @click="() => toUrlSpecial(item.id, item.title)"
            >
              <list-item-big :item="item" />
            </div>
          </div>
          <!-- 文件通知 -->
          <!-- <div v-if="item.type === '2'">
            <div
              v-for="item in file"
              :key="item.id"
              @click="() => toFile(item)"
            >
              <list-item-big :item="item" />
            </div>
          </div> -->
        </div>
      </van-tab>
    </van-tabs>
  </div>
</template>

<script>
import { categoryList } from "@/api/article/article.js";
import ListItemBig from "../../components/ListItem/ListItemBig";
import NewsList from "../../components/NewsList/NewsList";
import { Tab as vanTab, Tabs as vanTabs } from "vant";
import "vant/lib/tab/style";
import "vant/lib/tabs/style";

export default {
  name: "app",
  data: function() {
    return {
      active: "partyAffairs",
      column: [],
      file: [
        {
          title: "中华魂智慧党建平台",
          publishTime: "2020-12-04 09:25:40"
        }
      ],
      special: [
        {
          id: 9,
          url:
            "https://boot-img.xuexi.cn/image/1020/process/00907fb16fcc48cc8a091d78d7ea9b26.jpg",
          title: "公安心向党"
        },
        {
          id: 10,
          url:
            "https://boot-img.xuexi.cn/op_card/20200525/special_default_banner.png",
          title: "小故事 暖新闻"
        },
        {
          id: 11,
          url:
            "https://boot-img.xuexi.cn/op_card/20190906/30125553741681839_750x280.jpg",
          title: "第七届全国道德模范评选表彰活动"
        }
      ]
    };
  },
  methods: {
    toUrlSpecial(id, title) {
      console.log("跳转专题", id);
      window.parent
        ? (window.parent.location.href =
            "./special.html?id=" + id + "&name=" + title)
        : (location.href = "./special.html?id=" + id + "&name=" + title);
    },
    toFile(item) {
      console.log("跳转专题", item.id);
      window.parent
        ? (window.parent.location.href =
            "./pdfDetail.html?id=" + item.id + "&name=" + item.title)
        : (location.href =
            "./pdfDetail.html?id=" + item.id + "&name=" + item.title);
    }
  },
  mounted() {
    categoryList().then(res => {
      let l = res || [];
      let col = [];
      l.map(v => {
        col.push({
          title: v.name,
          id: v.id
        });
      });
      this.column = col;
    });
  },
  beforeDestroy: function() {},
  components: {
    NewsList,
    ListItemBig,
    vanTab,
    vanTabs
  }
};
</script>
<style lang="scss">
#partyAffairs {
  height: 100%;
  overflow: hidden;
  overflow-y: scroll;
  .partyBody {
    width: 100%;
  }
}
</style>
