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

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

      <p >
        客户：
        <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 zan-share" style="margin-left :0; margin-right: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 class="zantext">赞 | {{current.likeNum || 0}}</span>
          </div>
        </div>
        <div class="col-xs-6 col-md-6" style="padding 0;">
          <div class="pull-right" >
            
            <div style=" display: flex;"><span class="sharetext" >分享：</span><share :config="shareConfig"/></div> <div></div>
  
  
          </div>
        </div>
      </div>
    </div>
    <div class="contanier center-block next-prev">
      <div class="row case-2" style="margin-left :0; margin-right:0">
        <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 }}" class="btn1">上一个案例</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 }}" class="btn1">下一个案例</router-link>
          </div>
        </div>
      </div>
    </div>

    <div class="center-block st5" style>
      <h2>更多好案例</h2>

      <div class="row home-case" style="padding:0;width: 100%;margin-left :0; margin-right:0">
        <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">
                <div style="width: 100%">
                  <hr>
                  <p>
                    {{item.caseTitle}}
                  </p>
                </div>
              </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: {},
      // config: {
      //   // url: '', // 网址，默认使用 window.location.href
      //   // source: '', // 来源（QQ空间会用到）, 默认读取head标签：<meta name="site" content="http://overtrue" />
      //   // title: '', // 标题，默认读取 document.title 或者 <meta name="title" content="share.js" />
      //   // description: '', // 描述, 默认读取head标签：<meta name="description" content="PHP弱类型的实现原理分析" />
      //   image: '', // 图片, 默认取网页中第一个img标签
      //   sites: ['weibo', 'wechat'], // 启用的站点
      //   // disabled: ['google', 'facebook', 'twitter'], // 禁用的站点
      //   wechatQrcodeTitle: '微信扫一扫：分享', // 微信二维码提示文字
      //   wechatQrcodeHelper: '<p>微信里点“发现”，扫一下</p><p>二维码便可将本文分享至朋友圈。</p>'
      // }
    }

  },
  computed: {
    shareConfig () {
      return {
        
        url: window.location.href,
        title: this.current.caseTitle,
        image: this.current.caseCoverImg, // 图片, 默认取网页中第一个img标签
        description: this.current.caseSummary,
      }
    },
    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: {
    share: () => import('../components/Share'),
  },
  created () {

// var $config = {
//     title               : '234',
//     description         : '123',
//     sites: ['weibo', 'wechat'], // 启用的站点
//     wechatQrcodeTitle   : "微信扫一扫：分享", // 微信二维码提示文字
//     wechatQrcodeHelper  : '<p>微信里点“发现”，扫一下</p><p>二维码便可将本文分享至朋友圈。</p>',
// };

// socialShare('.social-share-cs', $config);


    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>


.casetitle {
  hr {
    margin-bottom: 20px;
    width: 50px;
    border: 2px solid red;
  }
}

@media (min-width: 992px) {
  .pull-left {
    font-size: 3.6rem;
    .iconfont {
      font-size: 3.6rem;
    }
  }
  .pull-right {
    display: flex;
    font-size: 3.6rem;
  }
  .head {
    img {
      width: 100%;
      height: 600px;
    }
  }
  .st {
    h1 {
      font-size: 4.8rem;
      font-weight: bold;
    }
    p {
      font-size: 2.4rem;
      color: #3e3a39;
      img {
        width: 192px;
        height: 55px;
      }
    }
    .border-top {
      padding-top: 50px;

      border-top: 1px solid #aaa;
    }
    .zan-share {
      margin-top: 80px;
    }
  }
  .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;
  }
  .st5 {
    width: 80%;
  }
}

@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 {
    display: flex;
  }
  .zantext{
    // margin-top: -3px;
    margin-left: 10px;
  }
  .sharetext{
display:inline-block;line-height:42px
  }
  .st {
    h1 {
      font-size: 2rem;
    }
    p {
      font-size: 1.4rem;
      img {
        width: 100px;
        height: 30px;
      }
    }
    .border-top {
      padding-top: 20px;

      border-top: 1px solid #aaa;
    }
    .zan-share {
      margin-top: 30px;
    }
  }

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

  // .share {
  //   width: 10vw;
  // }
  // share{
  //   // margin: -20px;
  // }
  .home-case {
    padding: 0;
  }
  .st4 {
    width: 100%;

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

    margin: 0;
  }
 
}
</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;
  }

  .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 .casetitle p {
    font-size: 2.4rem;
    text-align: center;
    display: block;
    color: #fff;
    width: 100%;
  }
}

</style>

<style lang="less" scoped>

.icon-nobefore {
 &::before {
   content: '' !important;
 } 
}
</style>