<script>
import Vue from 'vue'
import { getMyExpoInfo } from '@/api/expo'
export default Vue.extend({
  name: 'ExpoPopover',
  props: {
    expoId: String,
    placement: String,
    trigger: String
  },
  data() {
    return {
      popover_data: {},
      ossUrl: process.env.VUE_APP_OSS_DOMAIN
    }
  },
  methods: {
    goto(url) {
      window.open(url, '_blank')
    },
    getDetail(id) {
      getMyExpoInfo(id).then(res => {
        this.popover_data = res.data
        this.popover_data.images = JSON.parse(res.data.images)
        this.popover_data.social_links = JSON.parse(res.data.social_links)
        if (this.popover_data.social_links.facebook === '' || this.popover_data.social_links.twitter === '' || this.popover_data.social_links.linkedin === '') {
          this.popover_data.social_links = false
        }
      })
    },
    copyUrl() {
      const rootPath = window.location.origin
      navigator.clipboard.writeText(rootPath + '/register/' + this.popover_data.urla)
      this.$message.success('复制成功')
    }
  }
})
</script>

<template>
  <el-popover popper-class="popover" :trigger="trigger" :placement="placement" width="600" @show="popover_data={}" @after-enter="getDetail(expoId)">
    <div class="expo-info">
      <div class="cover loading">
        <img v-if="popover_data.images" :src="ossUrl+popover_data.images[0]">
        <div v-if="popover_data.form_template_id && popover_data.urla" v-permission="'exhibitor.copyLink'" class="button" @click="copyUrl()">复制表单地址</div>
      </div>
      <div class="info-body">
        <div class="avatar-name">
          <div class="avatar loading">
            <img v-if="popover_data.logo" :src="ossUrl+popover_data.logo">
          </div>
          <div class="name-cont">
            <div :class="['name',popover_data.expo_name!==undefined?'':'loading']">{{ popover_data.expo_name }}</div>
            <div :class="['sub-name',popover_data.organizer!==undefined?'':'loading']">{{ popover_data.organizer }}</div>
            <div class="contact">
              <div class="phone">
                <i class="icon el-icon-mobile-phone" />
                <div :class="['phone-num link',popover_data.contact_phone!==undefined?'':'loading']" @click="goto('tel:'+popover_data.contact_phone)">{{ popover_data.contact_phone }}</div>
              </div>
              <div class="email">
                <i class="icon el-icon-message" />
                <div :class="['email-addr link',popover_data.contact_email!==undefined?'':'loading']" @click="goto('mailto:'+popover_data.contact_email)">{{ popover_data.contact_email }}</div>
              </div>
              <div class="date">
                <i class="icon el-icon-date" />
                <div :class="['date-range',popover_data.start_date!==undefined?'':'loading']">{{ popover_data.start_date }} - {{ popover_data.end_date }}</div>
              </div>
            </div>
          </div>
        </div>
        <div v-html="popover_data.content" :class="['desc',popover_data.content!==undefined?'':'loading']">
        </div>
        <div v-if="popover_data.social_links" class="social_links">
          <div class="social-title">社交媒体</div>
          <div v-if="popover_data.social_links.facebook" class="social-item">
            <span>facebook：</span><span class="link" @click="goto(popover_data.social_links.facebook)">{{ popover_data.social_links.facebook }}</span>
          </div>
          <div v-if="popover_data.social_links.twitter" class="social-item">
            <span>twitter：</span><span class="link" @click="goto(popover_data.social_links.twitter)">{{ popover_data.social_links.twitter }}</span>
          </div>
          <div v-if="popover_data.social_links.linkedin" class="social-item">
            <span>linkedin：</span><span class="link" @click="goto(popover_data.social_links.linkedin)">{{ popover_data.social_links.linkedin }}</span>
          </div>
        </div>
      </div>
    </div>
    <span slot="reference" class="button">
      <slot />
    </span>
  </el-popover>
</template>

<style>
.popover{
  overflow: hidden;
  padding: 0;
  .expo-info{
    position: relative;
    width: 100%;
    .link{
      cursor: pointer;
      text-decoration: underline;
    }
    .info-body{
      padding: 16px;
      .social_links{
        margin-top: 12px;
        .social-title{
          font-weight: bold;
        }
        .social-item{

        }
      }
      .desc{
        max-height: 36vh;
        overflow: hidden;
        overflow-y: auto;
        white-space: pre-wrap;
        margin-top: 12px;
        p{
          margin: 0;
        }
        &.loading{
          height: 60px;
          width: 100%;
        }
      }
      .avatar-name{
        display: flex;
        grid-gap: 8px;
        .name-cont{
          flex: 1;
          .name{
            font-size: 20px;
            font-weight: bold;
            &.loading{
              height: 26px;
              width: 120px;
            }
          }
          .sub-name{
            color: gray;
            &.loading{
              margin-top: 8px;
              margin-bottom: 8px;
              height: 20px;
              width: 160px;
            }
          }
          .contact{
            flex-wrap: wrap;
            display: flex;
            grid-gap: 0 12px;
            .phone,.email,.date{
              display: flex;
              align-items: center;
              grid-gap: 4px;
              div{
                &.loading{
                  height: 16px;
                  width: 120px;
                }
              }
            }
          }
        }
        .avatar{
          width: 70px;
          height: 70px;
          border-radius: 50%;
          overflow: hidden;
          img{
            display: block;
            object-fit: cover;
            width: 100%;
            height: 100%;
          }
        }
      }
    }
    .cover{
      position: relative;
      width: 100%;
      aspect-ratio: 3/1;
      .button{
        cursor: pointer;
        background: #00000044;
        padding: 4px 12px;
        border-radius: 24px;
        border: 2px solid white;
        color: white;
        position: absolute;
        right: 16px;
        top: 16px;
      }
      img{
        display: block;
        object-fit: cover;
        width: 100%;
        height: 100%;
      }
    }
  }
}
</style>
