<template id="detail">
  <div class="details">
    <div class="top"></div>
    <Navbars></Navbars>
    <div class="head">
      <img :src="current.caseDetailCoverImg" width="100%" />
    </div>

    <div class="contanier st">
      <h1 style>{{current.caseTitle}}</h1>
      <div v-if="type=='分享'" class="row p1 ">
        <div class="movment col-xs-12 col-md-6">分享时间:{{date}}</div>
        <!-- <br v-if="isMobilePhone" /> -->
        <div class="movment col-xs-12 col-md-6">
          <div v-if="!current.caseLink" class>来源:{{current.linkName}}</div>
          <a v-if="current.caseLink" :href="current.caseLink" target="view_window" style="color:#3e3a39">来源:{{current.linkName}}</a>
        </div>
      </div>
      <div v-else class="row p1">
        <p class="col-xs-6 col-md-6 p2">
          客户：
          <img :src="current.caseLogoImg" />
        </p>
        <p class="col-xs-6 col-md-6 p2">所属行业：{{current.caseIndustry}}</p>
      </div>

      <div class="border-top htmlImg" v-html="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 zan" @click="postLike">
            <span role="button" class="iconfont icon-zan" :style="{ color: activeColor}"></span>
            <span class="zantext">&nbsp;赞 | {{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>
              <shares :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" style="color:#000">上一个{{type}}</router-link>
          </div>
        </div>
        <div class="col-xs-4 col-md-4 case-3">
          <button type="button" class="btn button-hover" @click="() => $router.go(-1)" style="color:#000">返回</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" style="color:#000">下一个{{type}}</router-link>
          </div>
        </div>
      </div>
    </div>

    <div class="center-block st5" style>
      <h2>更多好{{type}}</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.caseMoreCoverImg||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'

import { isMobilePhone } from '../../utils'
import moment from 'moment';

export default {
  name: 'Details',

  data () {
    return {
      url: window.location.href,
      type: '',
      detail: {},
      activeColor: '#000',
      isMobilePhone,
      date: moment().format('YYYY年MM月DD日 h:mm'),
      content: ''
    }
  },
  components: {
    shares: () => import('../components/Shares'),
    Navbars: () => import('../components/Navbars'),
  },
  computed: {
    shareConfig () {
      return {
        url: window.location.href,
        title: this.current.caseTitle,
        image: this.current.caseDetailCoverImg, // 图片, 默认取网页中第一个img标签
        description: this.current.caseSummary,
      }
    },
    cover () {
      return this.detail.cover || {}
    },
    current () {
      return this.detail.current || {}
    },
    brothers () {
      let b = this.detail.brothers
      // console.log(b, '111')
      if (!b || !b.length) {
        b = [{}, {}]
      } else if (b.length === 1) {
        if (b[0].id > this.$route.params.id) {
          b = [{}].concat(b)
        } else {
          b.push({})
        }
      }
      // console.log(b, '222')
      return b
    },
    recommends () {
      return (this.detail.recommends || []).slice(0, 4)
    },
  },

  created () {
    //  console.log(moment().format())
    // console.log(moment().format('YYYY年MM月DD日 h:mm'))


    this.getDetail(this.$route.params.id)
    // console.log(this.detail, 'data')


  },
  beforeRouteUpdate (to, from, next) {
    this.getDetail(to.params.id)

    next()
  },
  methods: {

    getDetail (id) {
      request({
        ...apis.case.get,
        urlData: { id },
      }).then(res => {

        // ../uploadimage/
        
        this.detail = res || {}
        
        let content = res.current.content.replace(/\.\.\/uploadimage/g, '/uploadimage')

        this.content = content
        this.type = this.detail.current.type == 'case' ? '案例' : '分享'
        // console.log(this.detail.current, '1234')
      
        this.url = window.location.href
        this.activeColor = '#000'
      })
    },

    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.activeColor = '#e03723'

        // 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 #e03723;
  }
}

// .btn-default {
// }
@media (max-width: 992px) {
  .casetitle {
    display: none;
  }
  .p1 {
    margin-bottom: 0px;
    text-align: left;
    padding-left: 15px;
    margin:0
  }
  .p2 {
    line-height: 30px;
    font-size: 1.2rem !important;
  }
}

@media (min-width: 992px) {
  .button-hover:hover {
    color: #e03723 !important;
  }
  .pull-left {
    // font-size: 3.6rem;
    // line-height: 4.0rem;
    .iconfont {
      font-size: 4rem;
    }
    .zantext {
      font-size: 2.4rem;
      line-height: 4rem;
    }
  }
  .pull-right {
    display: flex;
    font-size: 3.6rem;
  }
  .head {
    img {
      width: 100%;
      height: 600px;
    }
  }
  .st {
    h1 {
      font-size: 4.8rem;
      font-weight: bold;
    }
    div {
      // 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 {
    border: 1px solid #e03723;
    background-color: #fff !important;
    outline: none;
    box-shadow: none;
  }
  .btn1 {
    font-size: 2.4rem !important;
    color: black !important;
    border: none !important;
    text-decoration: none;
  }
  .btn1:hover {
    color: #e03723 !important;
    text-decoration: none;
  }
  .btn {
    width: 195px;
    height: 49px;
    font-size: 2.4rem;
    background-color: #fff;
    border: 1px solid #aaaaaa;
    border-radius: 0px;
    outline: none;
  }
  .btn:hover {
    color: #e03723;
    border: 1px solid #e03723;
    outline: none;
  }
  .btn:active {
    color: #e03723;
    border: 1px solid #e03723;
    box-shadow: none;
  }

  .btn-default:active:focus {
    color: #e03723;
    background-color: #fff;
    border: 1px solid #e03723;
    outline: none;
  }
  .btn:active:focus {
    color: #e03723;
    border: 1px solid #e03723;
  }
  .next-prev {
    width: 80%;
    border-bottom: 1px solid #aaa;
    // .case2 {
    //   .case3 {
    //   }
    // }
  }
  h2 {
    margin-top: 64px;
    margin-bottom: 30px;
    font-size: 2.4rem;
  }
  .st5 {
    width: 80%;
  }
}

@media (max-width: 992px) {
  .details {
    //  margin-top: 47.8px;
    padding-bottom: 3rem;
    // margin-top: 47.8px;
    // margin-bottom: -47.8px;
    // padding-bottom: 47.8px;
  }
  .btn1 {
    line-height: 25px;
    font-size: 1.2rem !important;
    color: black !important;
    border: none !important;
    text-decoration: none;
  }

  .btn {
    width: 100px;
    // padding: 3px;
    font-size: 1.2rem;
    background-color: #fff;
    border: 1px solid #aaaaaa;
    border-radius: 0px;
  }

  .btn:active {
    color: #000;
  }
  .pull-left {
    .iconfont {
      font-size: 1.6rem;
    }
  }
  .iconfont:visited {
    color: red;
  }
  .pull-right {
    display: flex;
  }
  .zan {
    padding-top: 9px;
  }
  .zantext {
    // margin-top: -3px;
    margin-left: 10px;
  }
  .sharetext {
    display: inline-block;
    line-height: 42px;
  }
  .st {
    h1 {
      font-size: 2rem;
    }
    div {
      font-size: 1.4rem;
      img {
        width: 100px;
        height: 30px;
      }
    }
    .border-top {
      padding-top: 20px;
      margin-top: 2px;
      border-top: 1px solid #aaa;
      // width: 90%;
    }
    .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: 1.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;
  }

  .movment {
    font-size: 1.2rem !important;
    margin-bottom: 5px !important;
  }
}
</style>

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

  .coverimg {
    width: 100%;

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

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

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

  .case-2 {
    margin: 70px 0;
    padding: 0;
  }
  .case-3 {
    margin: 0;
    padding: 0;
    line-height: 49px;
  }

  .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%;
  }
  .movment {
    font-size: 2.4rem;
    color: #3e3a39;
    margin-bottom: 10px;
  }
  .p2 {
    line-height: 55px;
    font-size: 2.4rem;
  }
}
</style>

<style lang="less" scoped>
.icon-nobefore {
  &::before {
    content: '' !important;
  }
}

@media (min-width: 992px) and (max-width: 1550px) {
  // .zantext {
  //     font-size: 3rem;
  //     line-height: 3.4rem;
  //   }
  .movment {
    font-size: 1.7rem;
  }
  .st h1 {
    font-size: 3rem;
  }
  .st p {
    font-size: 1.7rem;
  }
  .pull-left {
    font-size: 1.7rem;
    .iconfont {
      font-size: 2.5rem;
    }
    .zantext {
      font-size: 1.7rem;
      line-height: 2.8rem;
    }
  }

  .btn1 {
    font-size: 1.7rem !important;
  }

  .pull-right {
    font-size: 1.7rem;
  }
}
@media (min-width: 992px) and (max-width: 1550px) {
  .sharetext {
    font-size: 2.4rem;
    line-height: 5.8rem;
  }
}
a {
  color: #000;
}
</style>

<style lang="less">
.htmlImg img {
  max-width: 100%;
  min-width: 100px;
  height: auto;
  margin: 0 auto;
  display: block;
}
.htmlImg iframe {
  max-width: 100%;
  min-width: 100px;
  width: 100%;
 width: 1920px;
   height: 1080px;
  margin: 0 auto;
  display: block;
}
.htmlImg video {
  max-width: 100%;
  min-width: 100px;
  height: auto;
  margin: 0 auto;
  display: block;
}
@media (min-width: 1550px) and (max-width: 1980px) {
  .htmlImg iframe {
   width: 1280px;
   height: 720px;
  }
  .htmlImg video {
   width: 1280px;
   height: 720px;
  }
}
@media (min-width: 992px) and (max-width: 1550px) {
  .htmlImg iframe {
   width: 900px;
  height: 550px;
  }
  .htmlImg video {
    width: 900px;
   height: 550px;
  }
}
@media (max-width: 992px) {
  .htmlImg img {
    background-size: contain !important;

    height: auto;
    margin: 0 auto;
    display: block;
    width: 90%;
  }
  .htmlImg iframe {
    max-width: 100% !important;
    min-width: 100px !important;
    min-height: 170px !important;
    height: 170px;
    margin: 0 auto;
    display: block;
    width: 90%;
  }

  .htmlImg video {
    background-size: contain !important;
    max-width: 100% !important;
    min-width: 100px !important;
min-height: 170px !important;
    height: 170px;
    margin: 0 auto;
    display: block;
    width: 90%;
  }
}
</style>