/*data*/
<template>
  <div class="data">
    <div class="block latest">
      <div class="title">
        <h3><img src="../../../assets/img/latest.png" />最新上传</h3>
        <div class="pagination">
          <i class="el-icon-arrow-left"></i>
          <span>1/4</span>
          <i class="el-icon-arrow-right"></i>
        </div>
      </div>
      <div class="content">
        <div class="list" v-for="(item, index) in latestList" :key="index">
          <div class="image">
            <img :src="item.url" />
          </div>
          <p class="project-name">{{ item.title }}</p>
          <p>{{ item.name }}</p>
          <p>{{ formatTime(item.time) }}</p>
        </div>
      </div>
    </div>
    <div class="block popularity">
      <div class="title">
        <h3><img src="../../../assets/img/popularity.png" />人气榜</h3>
        <div class="pagination">
          <i class="el-icon-arrow-left"></i>
          <span>1/4</span>
          <i class="el-icon-arrow-right"></i>
        </div>
      </div>
      <div class="content">
        <div class="list" v-for="(item, index) in popularityList" :key="index">
          <div class="image">
            <img :src="item.url" />
          </div>
          <p class="project-name">{{ item.title }}</p>
          <p>{{ item.name }}</p>
          <p>{{ formatTime(item.time) }}</p>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { parseTime } from '@/utils/index'
export default {
  name: 'Data',
  components: {},
  data() {
    return {
      latestList: [
        {
          url: require('../../../assets/mode/car.jpg'),
          title: '家用汽车设计',
          name: '小蜗牛',
          time: new Date().getTime() - 1 * 60 * 1000,
        },
        {
          url: require('../../../assets/mode/frame.jpg'),
          title: '货运汽车设计',
          name: '大力霸王',
          time: new Date().getTime() - 4 * 60 * 1000,
        },
        {
          url: require('../../../assets/mode/plane.jpg'),
          title: 'J47战机模型设计',
          name: '奔跑的蚂蚱',
          time: new Date().getTime() - 15 * 60 * 1000,
        },
        {
          url: require('../../../assets/mode/mode.jpg'),
          title: '压铸模型设计',
          name: '烛魔大师',
          time: new Date().getTime() - 43 * 60 * 1000,
        },
        {
          url: require('../../../assets/mode/tank.jpg'),
          title: 'T99坦克模型设计',
          name: '贪了一杯酒',
          time: new Date().getTime() - 69 * 60 * 1000,
        },
        {
          url: require('../../../assets/mode/tyre.jpg'),
          title: '轮胎模型设计',
          name: '轮胎高手',
          time: new Date().getTime() - 128 * 60 * 1000,
        },
      ],
      popularityList: [],
    }
  },
  created() {
    this.getPopularityList()
  },
  methods: {
    getPopularityList() {
      let array = [...this.latestList]
      let lastIndex = array.length
      let randomIndex
      let lastValue
      while (lastIndex) {
        randomIndex = Math.floor(Math.random() * lastIndex--)
        lastValue = array[lastIndex]
        array[lastIndex] = array[randomIndex]
        array[randomIndex] = lastValue
      }
      this.popularityList = array
    },
    formatTime(time) {
      return parseTime(time, '{y}.{m}.{d} {h}:{i}')
    },
  },
}
</script>

<style lang="scss" scoped>
@import '@/styles/variables.scss';
@import '@/styles/mixin.scss';
.data {
  // @include w_h(100%, 100%);
  @include w_h(100%);
  padding: 30px 60px;
  background: #000;
  .block {
    @include w_h();
    .title {
      @include flex();
      h3 {
        @include flex();
        font-size: 18px;
        font-weight: 600;
        line-height: 50px;
        letter-spacing: 2px;
        img {
          @include w_h(18px);
          margin-right: 8px;
        }
      }
      .pagination {
        @include w_h(100px);
        @include flex();
        font-size: 14px;
        line-height: 20px;
        text-align: center;
        color: $color_b;
        i {
          @include w_h(20px, 20px);
          line-height: 20px;
          border-radius: 2px;
          transition: all 0.3s;
          &:hover {
            cursor: pointer;
            background: $color_3;
            color: $color_f;
          }
        }
      }
    }
    .content {
      @include w_h(100%);
      @include flex(flex-start);
      .list {
        @include w_h(15.5%);
        margin: 12px 8px;
        padding: 10px;
        text-align: center;
        background: $color_f;
        .image {
          @include w_h(70%, 130px);
          @include flex(center);
          margin: 20px auto;
          overflow: hidden;
          img {
            margin: 5px 0;
            @include w_h(100%);
            transition: all 0.3s;
          }
        }

        p {
          @include w_h(100%);
          font-size: 12px;
          color: $color_9;
          text-align: left;
          overflow: hidden;
          text-overflow: ellipsis;
          display: -webkit-box;
          -webkit-line-clamp: 1;
          -webkit-box-orient: vertical;
          transition: all 0.3s;
        }
        .project-name {
          @include w_h(100%);
          font-size: 14px;
          line-height: 30px;
          color: $color_3;
        }
        &:hover {
          cursor: pointer;
          p {
            color: #ee6a74;
          }
          img {
            transform: scale(1.2);
          }
        }
      }
    }
  }
  .latest {
    h3 {
      color: #ee6a74;
    }
  }
  .popularity {
    margin-top: 20px;
    h3 {
      color: #db7116;
    }
  }
}
</style>
