<template>
  <div id="index">
    <el-row>
      <el-col :span="24" class="main animate__animated animate__zoomInDown">
        <el-col :span="24" class="zero one">
          <el-col :span="16" class="one_1">
            <el-carousel height="500px">
              <el-carousel-item v-for="(item, index) in bannerList" :key="index" @click.native="toView(item, 'banner')">
                <el-image class="image" :src="item.img_url && item.img_url.length > 0 ? item.img_url[0].url : ''"></el-image>
              </el-carousel-item>
            </el-carousel>
          </el-col>
          <el-col :span="8" class="one_2">
            <el-col :span="24" class="newsList" v-for="(item, index) in newsList" :key="index" @click.native="toView(item, 'news')">
              <el-col :span="24" class="title textOver">{{ item.title }}</el-col>
              <el-col :span="24" class="date">{{ item.create_time }}</el-col>
              <el-col :span="24" class="brief">{{ item.brief }}</el-col>
            </el-col>
          </el-col>
        </el-col>
        <el-col :span="24" class="zero two">
          <el-col :span="24" class="common_1">
            <span>解决方案</span>
            <span></span>
            <span></span>
          </el-col>
          <el-col :span="24" class="two_2">
            <el-col :span="8" class="twoList" v-for="(item, index) in siteInfo.programme" :key="index">
              <el-image class="image" :src="item.img_url && item.img_url.length > 0 ? item.img_url[0].uri : ''"></el-image>
              <el-col :span="24" class="other">
                <el-col :span="24" class="title textOver">
                  <span>{{ item.name }}</span>
                </el-col>
                <el-col :span="24" class="brief">
                  {{ item.brief }}
                </el-col>
              </el-col>
            </el-col>
          </el-col>
        </el-col>
        <el-col :span="24" class="zero thr">
          <el-col :span="24" class="common_1">
            <span>案例展示</span>
            <span></span>
            <span></span>
          </el-col>
          <el-col :span="24" class="thr_2">
            <el-col :span="8" class="thrList" v-for="(item, index) in thrList" :key="index" @click.native="toView(item, 'cases')">
              <el-image class="image" :src="item.img_url && item.img_url.length > 0 ? item.img_url[0].url : ''"></el-image>
              <el-col :span="24" class="title textOver">{{ item.title }}</el-col>
            </el-col>
          </el-col>
        </el-col>
      </el-col>
    </el-row>
  </div>
</template>

<script>
import { mapState, createNamespacedHelpers } from 'vuex';
const { mapActions: banner } = createNamespacedHelpers('banner');
const { mapActions: news } = createNamespacedHelpers('news');
const { mapActions: cases } = createNamespacedHelpers('cases');

export default {
  name: 'index',
  props: {},
  components: {},
  data: function () {
    return {
      // 基本信息
      siteInfo: {},
      // 轮播图
      bannerList: [],
      // 新闻
      newsList: [],
      // 案例
      thrList: [],
    };
  },
  created() {
    this.search();
  },
  methods: {
    ...banner({ bQuery: 'query' }),
    ...news({ nQuery: 'query' }),
    ...cases({ cQuery: 'query' }),
    async search() {
      let res;
      let companyInfo = sessionStorage.getItem('companyInfo');
      this.$set(this, `siteInfo`, JSON.parse(companyInfo));
      // 轮播图
      res = await this.bQuery({ skip: 0, limit: 6, is_use: '0', place: this.$route.meta.place });
      if (this.$checkRes(res)) {
        this.$set(this, `bannerList`, res.data);
      }
      // 新闻
      res = await this.nQuery({ skip: 0, limit: 6, is_use: '0', place: this.$route.meta.place });
      if (this.$checkRes(res)) {
        this.$set(this, `newsList`, res.data);
      }
      // 案例
      res = await this.cQuery({ skip: 0, limit: 6, is_use: '0' });
      if (this.$checkRes(res)) {
        this.$set(this, `thrList`, res.data);
      }
    },
    // 详细信息
    toView(e, type) {
      this.$router.push({ path: '/detail/index', query: { id: e._id, type: type } });
    },
  },
  computed: {
    ...mapState(['user']),
  },
  metaInfo() {
    return { title: this.$route.meta.title };
  },
  watch: {
    test: {
      deep: true,
      immediate: true,
      handler(val) {},
    },
  },
};
</script>

<style lang="less" scoped>
.main {
  .zero {
    margin: 0 0 2vw 0;
    .common_1 {
      margin: 0 0 20px 0;
      span:nth-child(1) {
        color: #ffc001;
        font-size: 18px;
      }
      span:nth-child(2) {
        display: inline-block;
        width: 8px;
        height: 10px;
        background-color: #ffc001;
        margin: 0 10px;
      }
      span:nth-child(3) {
        display: inline-block;
        width: 91%;
        height: 10px;
        background-color: #f1f1f1;
      }
    }
  }
  .one {
    .one_1 {
      .image {
        width: 100%;
        height: 100%;
      }
    }
    .one_2 {
      padding: 0 10px;
      .newsList {
        margin: 0 0 20px 0;
        padding: 0 0 20px 0;
        border-bottom: 1px dashed #353535;
        .title {
          font-size: 20px;
          margin: 0 0 5px 0;
          font-weight: bold;
          font-family: cursive;
        }
        .date {
          font-size: 14px;
          margin: 0 0 5px 0;
        }
        .brief {
          font-size: 14px;
          color: #7e7e7e;
          line-height: 1.5;
          overflow: hidden;
          text-overflow: ellipsis;
          -webkit-line-clamp: 2;
          word-break: break-all;
          display: -webkit-box;
          -webkit-box-orient: vertical;
        }
      }
      .newsList:last-child {
        border-bottom: none;
        margin: 0;
        padding: 0;
      }
      .newsList:hover {
        cursor: pointer;
        .title {
          color: #ffc001;
        }
        .date {
          color: #ffc001;
        }
      }
    }
  }
  .two {
    .two_2 {
      .twoList {
        width: 29%;
        height: 420px;
        overflow: hidden;
        margin: 0 70px 0 0;
        border: 1px solid #dbdbdb;
        .image {
          width: 100%;
        }
        .other {
          padding: 0 10px;
          .title {
            padding: 1.5vw 0;
            margin: 0 0 5px 0;
            text-align: center;
            border-bottom: 1px solid #dbdbdb;
            font-size: 22px;
            color: #747474;
          }
          .brief {
            padding: 0 10px;
            font-size: 14px;
            line-height: 1.5;
            color: #747474;
            letter-spacing: 2px;
            overflow: hidden;
            text-overflow: ellipsis;
            -webkit-line-clamp: 5;
            word-break: break-all;
            display: -webkit-box;
            -webkit-box-orient: vertical;
          }
        }
      }
      .twoList:last-child {
        margin: 0;
      }
    }
  }
  .thr {
    .thr_2 {
      .thrList {
        padding: 20px;
        .image {
          width: 100%;
          height: 200px;
          overflow: hidden;
        }
        .title {
          text-align: center;
          padding: 5px 0;
          font-size: 14px;
          color: #747474;
        }
      }
    }
  }
}
</style>
