<template>
  <van-popup
    v-model:show="showPopup"
    round
    :style="{ width: '8rem', background: 'none' }"
  >
    <div class="cover">
      <img :src="detail.imgUrl" alt="" srcset="" />
      <p>{{ detail.startTime }}</p>
    </div>
    <div class="content">
      <h4>{{ detail.title }}</h4>
      <div class="user-name">
        <img :src="detail.advisorBasic?.avatar" alt="" srcset="" />
        <span>{{ detail.advisorBasic?.name }}</span>
      </div>
      <div class="footer">
        <p>
          风险提示：投资顾问提供的观点和投资建议仅供参考，市场有风险，投资谨慎
        </p>
        <img :src="qrCodeData" alt="" srcset="" />
      </div>
    </div>
    <ul class="opt">
      <li @click="shareFn">
        <img src="@/assets/images/poster/save.png" alt="" srcset="" />
        <p>保存相册</p>
      </li>
      <li @click="shareFn">
        <img src="@/assets/images/poster/pengyouquan.png" srcset="" />
        <p>朋友圈</p>
      </li>
      <li @click="shareFn">
        <img src="@/assets/images/poster/weixin.png" srcset="" />
        <p>微信好友</p>
      </li>
    </ul>
    <i class="close" @click="showPopup = !showPopup"></i>
  </van-popup>
</template>

<script setup>
import { ref, defineExpose, defineProps } from "vue";
import qrcode from "qrcode";
import { showToast } from "vant";

defineProps({
  detail: {
    type: Object,
    default: () => ({}),
  },
});

const qrCodeData = ref();
qrcode.toDataURL(location.href, (err, url) => {
  if (err) {
    console.error(err);
  } else {
    qrCodeData.value = url;
  }
});

const shareFn = () => {
  showToast("Demo版本暂不支持");
};

const showPopup = ref(false);

defineExpose({
  showPopup,
});
</script>
<style scoped lang="scss">
.cover {
  position: relative;
  border-radius: 16px 16px 0 0;
  img {
    width: 600px;
    height: 500px;
  }
  p {
    position: absolute;
    bottom: 0;
    width: 100%;
    height: 546px;
    display: flex;
    align-items: flex-end;
    justify-content: flex-end;
    box-sizing: border-box;
    padding: 0 24px 16px 0;
    color: rgb(255, 255, 255);
    font-size: 24px;
    font-weight: 400;
    line-height: 36px;
    background: linear-gradient(
      180deg,
      rgba(0, 0, 0, 0) 0%,
      rgba(0, 0, 0, 0) 38.44%,
      rgba(0, 0, 0, 0) 58.55%,
      rgba(0, 0, 0, 0.9) 100%
    );
  }
}
.content {
  padding: 32px 32px 32px 24px;
  text-align: left;
  background: #fff;
  border-radius: 0 0 16px 16px;
  h4 {
    color: rgb(51, 51, 51);
    font-size: 32px;
    font-weight: 500;
    line-height: 48px;
    margin-bottom: 16px;
  }
  .user-name {
    display: flex;
    align-items: center;
    color: rgb(96, 104, 119);
    font-size: 24px;
    font-style: normal;
    font-weight: 400;
    line-height: 32px;
    margin-bottom: 32px;
    img {
      width: 32px;
      height: 32px;
      border-radius: 50%;
      margin-right: 8px;
    }
  }
  .footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    p {
      flex: 1;
      color: rgb(153, 153, 153);
      font-size: 24px;
      font-style: normal;
      font-weight: 400;
      line-height: 36px;
      margin-right: 32px;
    }
    img {
      width: 102px;
      height: 102px;
    }
  }
}
.opt {
  display: flex;
  justify-content: space-between;
  padding: 0 40px;
  margin-top: 48px;
  img {
    width: 96px;
    height: 96px;
    margin-bottom: 16px;
  }
  p {
    color: rgb(255, 255, 255);
    text-align: center;
    font-size: 28px;
    font-style: normal;
    font-weight: 400;
    line-height: 32px;
  }
}

.close {
  display: block;
  width: 64px;
  height: 64px;
  background: url(../../../assets/images/close-icon1.png) no-repeat center;
  background-size: cover;
  margin: 100px auto 0;
}
</style>
