<script lang="ts">
import Vue from 'vue'
import { getMyExpoInfo } from '@/api/expo'
export default Vue.extend({
  name: "expoPopover",
  data() {
    return {
      popover_data: {},
      ossUrl: process.env.VUE_APP_OSS_DOMAIN
    }
  },
  props: {
    expoId: String,
    placement: String,
    trigger: String,
  },
  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)
      })
    },
    copyUrl() {
      let rootPath = window.location.origin
      navigator.clipboard.writeText(rootPath+'/user/form/'+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-permission="'exhibitor.copyLink'" v-if="popover_data.form_template_id && popover_data.urla" @click="copyUrl()" class="button">复制表单地址</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 :class="['desc',popover_data.content!==undefined?'':'loading']">
          {{ popover_data.content }}
        </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></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{
        margin-top: 12px;
        &.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>
