<template>
  <div id="index">
    <el-row>
      <el-col :span="24" class="main">
        <div class="w_1200">
          <el-col :span="24" class="common one">
            <el-col :span="12" class="left">
              <top topText="通知通告" @more="more('0')"></top>
              <list type="1" :list="oneList" @detail="detail"></list>
            </el-col>
            <el-col :span="12" class="left">
              <top topText="政务动态" @more="more('1')"></top>
              <list type="2" :list="twoList" @detail="detail"></list>
            </el-col>
          </el-col>
          <el-col :span="24" class="common two">
            <el-col :span="12" class="left">
              <top topText="科技新闻" @more="more('2')"></top>
              <list type="3" :list="thrList" @detail="detail"></list>
            </el-col>
            <el-col :span="12" class="left">
              <top topText="媒体聚焦" @more="more('3')"></top>
              <list type="4" :list="fourList" @detail="detail"></list>
            </el-col>
          </el-col>
          <!-- <el-col :span="24" class="common thr">
            <el-col :span="24" class="left">
              <top topText="信息公开" @more="more('4')"></top>
              <list type="5" :list="fiveList" @detail="detail"></list>
            </el-col>
          </el-col> -->
        </div>
      </el-col>
    </el-row>
  </div>
</template>

<script>
import top from './parts/top.vue';
import list from './parts/list.vue';
const { newsColumn } = require('@common/dict/index');
import { mapState, createNamespacedHelpers } from 'vuex';
const { mapActions: news } = createNamespacedHelpers('news');
export default {
  name: 'index',
  props: {},
  components: { top, list },
  data: function () {
    return {
      // 通知通告
      oneList: [],
      // 政务动态
      twoList: [],
      // 科技新闻
      thrList: [],
      // 媒体聚焦
      fourList: [],
      // 信息公开
      fiveList: [],
      column: newsColumn,
    };
  },
  async created() {
    await this.search();
  },
  methods: {
    ...news(['query']),
    async search({ skip = 0, limit = 10, ...info } = {}) {
      for (const val of this.column) {
        if (val == '通知通告') {
          let res = await this.query({ skip, limit: 11, column_name: val, ...info });
          if (this.$checkRes(res)) this.$set(this, `oneList`, res.data);
        } else if (val == '政务动态') {
          let res = await this.query({ skip, limit: 11, column_name: val, ...info });
          if (this.$checkRes(res)) this.$set(this, `twoList`, res.data);
        } else if (val == '科技新闻') {
          let res = await this.query({ skip, limit: 4, column_name: val, ...info });
          if (this.$checkRes(res)) this.$set(this, `thrList`, res.data);
        } else if (val == '媒体聚焦') {
          let res = await this.query({ skip, limit: 11, column_name: val, ...info });
          if (this.$checkRes(res)) this.$set(this, `fourList`, res.data);
        } else if (val == '信息公开') {
          let res = await this.query({ skip, limit: 12, column_name: val, ...info });
          if (this.$checkRes(res)) this.$set(this, `fiveList`, res.data);
        }
      }
    },
    // 更多
    more(index) {
      this.$router.push({ path: '/news/list', query: { index: index } });
    },
    // 详情
    detail({ id, index }) {
      this.$router.push({ path: '/news/list', query: { id: id, index: index } });
    },
  },
  computed: {
    ...mapState(['user']),
  },
  metaInfo() {
    return { title: this.$route.meta.title };
  },
  watch: {
    test: {
      deep: true,
      immediate: true,
      handler(val) {},
    },
  },
};
</script>

<style lang="less" scoped>
.main {
  min-height: 500px;
  margin: 10px 0 0 0;
  .common {
    margin: 0 0 10px 0;
    .left {
      width: 49.5%;
      height: 500px;
      overflow: hidden;
      box-shadow: 0 0 4px #409eff;
      border-radius: 10px;
      margin: 0 10px 10px 0;
      padding: 10px;
    }
    .left:nth-child(2n) {
      margin: 0 0 10px 0;
    }
  }
  .thr {
    .left {
      width: 100%;
      margin: 0;
      height: 300px;
    }
  }
}
</style>
