<template>
  <div class="details">
    <div class="head">
      <img :src="cover.coverImg" width="100%" />
    </div>

    <div class="contanier st">
      <h1 style>{{current.caseTitle}}</h1>

      <p style>
        客户：
        <img :src="current.caseLogoImg" alt />
        &nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 所属行业：{{current.caseIndustry}}
      </p>

      <div class="border-top" v-html="current.content"></div>

      <div class="row" style="margin:0">
        <div class="col-xs-6 col-md-6" style="padding 0;">
          <div class="pull-left" @click="postLike">
            <span role="button" class="iconfont icon-zan"></span>
            <span>赞 | {{current.likeNum || 0}}</span>
          </div>
        </div>
        <div class="col-xs-6 col-md-6" style="padding 0;">
          <div class="pull-right">
            分享：
            <a class="btn-default" href="#" role="button">
              <img src="../assets/image/case2/微信icon.png" alt />
            </a>
            <a class="btn-default" href="#" role="button">
              <img src="../assets/image/case2/微博icon.png" alt />
            </a>
          </div>
        </div>
      </div>
    </div>
    <div class="contanier center-block next-prev">
      <div class="row case-2">
        <div class="col-xs-4 col-md-4 case-3">
          <div class="btn1 btn-link pull-left case-3 button-hover prev-page" v-if="brothers[0].id">
            <router-link :to="{name: 'details', params: { id: brothers[0].id }}">
              上一个案例
            </router-link>
          </div>
        </div>
        <div class="col-xs-4 col-md-4 case-3">
          <button type="button" class="btn btn-default button-hover" @click="() => $router.go(-1)">返回</button>
        </div>
        <div class="col-xs-4 col-md-4 case-3">
          <div class="btn1 btn-link pull-right case-3 button-hover next-page" v-if="brothers[1].id">
            <router-link :to="{name: 'details', params: { id: brothers[1].id }}">
              下一个案例
            </router-link>
          </div>
        </div>
      </div>
    </div>

    <div class="center-block" style="width: 80%">
      <h2>更多好案例</h2>

      <div class="row home-case" style="padding:0;width: 100%;">
        <div class="col-xs-6 col-md-3 home-case" style="margin:0" v-for="(item,index) in recommends" :key="index">
          <router-link :to="{name: 'details', params: { id: item.id }}">
            <div class="st4" :style="{background: `url(${item.caseCoverImg})`}">
              <div class="casetitle">
                <p>{{item.caseTitle}}</p>
              </div>
            </div>
          </router-link>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
// @ is an alias to /src
import request from '../../utils/request'
import apis from '../config/api';

export default {
  name: 'CaseDetails',

  data () {
    return {
      detail: {},
    }
  },
  computed: {
    cover() {
      return this.detail.cover || {}
    },
    current() {
      return this.detail.current || {}
    },
    brothers() {
      let b = this.detail.brothers
      if (!b || !b.length) {
        b = [{}, {}]
      } else if (b.length === 1) {
        if (b[0].id > this.$route.params.id) {
          b = [{}].concat(b)
        } else {
          b.push({})
        }
      }

      return b
    },
    recommends() {
      return (this.detail.recommends || []).slice(0, 4)
    },
  },
  components: {

  },
  created () {
    this.getDetail(this.$route.params.id)
  },
  beforeRouteUpdate (to, from, next) {
    this.getDetail(to.params.id)
    next()
  },
  methods: {
    getDetail (id) {
      request({
        ...apis.case.get,
        urlData: { id },
      }).then(res => {
        this.detail = res || {}
      })
    },

    postLike () {
      const id = this.$route.params.id;

      request({
        ...apis.case.like,
        urlData: { id },
      }).then(res => {
        this.detail = {
          ...this.detail,
          current: {
            ...this.current,
            likeNum: res || 0,
          }
        }

        this.$message({
          message: res == this.current.likeNum ? '已赞' : '赞 +1',
          type: res == this.current.likeNum ? 'warning' : 'success'
        });
      })
    },

  },

}
</script>

<style lang="less" scoped>
@media (min-width: 992px) {
  .pull-left {
    font-size: 3.6rem;
    .iconfont {
      font-size: 3.6rem;
    }
  }
  .pull-right {
    font-size: 3.6rem;
  }
  .head {
    img {
      width: 100%;
      height: 600px;
    }
  }
  .st {
    h1 {
      font-size: 4.8rem;
    }
    p {
      font-size: 2.4rem;
      color: #3e3a39;
    }
    .border-top {
      padding-top: 50px;

      border-top: 1px solid #aaa;
    }
  }
  .button-hover:hover {
    color: #e03723;
    border: 1px solid #e03723;
  }
  .btn1 {
    font-size: 2.4rem !important;
    color: black !important;
    border: none !important;
  }
  .btn1:hover {
    color: red !important;
    text-decoration: none;
  }
  .btn {
    width: 195px;
    height: 49px;
    font-size: 2.4rem;
    background-color: #fff;
    border: 1px solid #aaaaaa;
    border-radius: 0px;
  }
  .next-prev {
    width: 80%;
    border-bottom: 1px solid #aaa;
    .case2 {
      .case3 {
      }
    }
  }
  h2 {
    margin-top: 64px;
    margin-bottom: 30px;
  }
}

@media (max-width: 992px) {
  .btn1 {
    font-size: 1.2rem !important;
    color: black !important;
    border: none !important;
  }
  .btn1:hover {
    color: red !important;
    text-decoration: none;
  }
  .btn {
    width: 100px;
    padding: 3px;
    font-size: 1.2rem;
    background-color: #fff;
    border: 1px solid #aaaaaa;
    border-radius: 0px;
  }
  .pull-left {
    .iconfont {
      font-size: 2.4rem;
    }
  }
  .pull-right {
  }
  .st {
    h1 {
      font-size: 2rem;
      img {
        width: 192px;
        height: 95px;
      }
    }
    p {
      font-size: 1.4rem;
      img {
        width: 35%;
      }
    }
    .border-top {
      padding-top: 20px;

      border-top: 1px solid #aaa;
    }
  }

  .next-prev {
    width: 100%;
    padding-bottom: 20px;
    border-bottom: 1px solid #aaa;
    .case2 {
      margin: 0;
      .case3 {
      }
    }
  }
  h2{
    font-size: 2rem;
  }
}
</style>

<style scoped>
@media (min-width: 992px) {
  .details {
    margin-top: 116px;
  }

  .coverimg {
    width: 100%;

    padding-bottom: 35%;
    background-size: 100% 100% !important;
    position: relative;

    margin: 0;
  }
  .case {
    padding-top: 116px;
  }

  .st {
    width: 80%;
    padding: 50px;
    margin-top: -120px;
    background-color: #fff;
    display: inline-block;
    border-radius: 0;
    border: 2px solid #bcbcbc;
  }

  .case-2 {
    margin: 70px 0;
    padding: 0;
  }
  .case-3 {
    margin: 0;
    padding: 0;
  }
  /* .btn {
    font-size: 24px;
    margin-top: 88px;
    padding: 12px 150px;
    border-radius: 0px;
    color: #000;
    background-color: #fff;
    border: 1px solid #aaaaaa;
  }
  .btn:hover {
    color: #e03723;
    border: 1px solid #e03723;
  } */

  .home-case {
    padding: 0;
    margin: 0;
    border: none;
  }
  .st4 {
    width: 100%;

    padding-bottom: 100%;
    background-size: 100% 100% !important;
    position: relative;

    margin: 0;
  }
  .st4 .casetitle {
    display: none;
  }

  .st4:hover .casetitle {
    position: absolute;
    width: 100%;
    height: 100%;
    float: left;
    padding: 0 auto;
    background: rgba(0, 0, 0, 0.7);
    align-items: center;
    display: -webkit-flex;
    display: flex;

    text-align: center;
  }
  .st4:hover .casetitle p {
    text-align: center;
    display: block;
    color: #fff;
    width: 100%;
  }
}
</style>