Poster.vue 2.8 KB
<template>
  <van-overlay :show="show">
    <!-- z-index="9999999" -->
    <div
      class="wrapper"
      @click.stop
    >
      <div class="img">
        <div
          class="sprite-icon icon-poster-close"
          @click.prevent="close"
        ></div>
        <van-image
          :src="activityData.posterUrl"
          width="100%"
          height="100%"
        >
          <template v-slot:loading>
            <van-loading
              type="spinner"
              size="20"
            />
          </template>
        </van-image>
      </div>
      <div class="btns flex">
        <div
          class="save text-center"
          @click.prevent="save"
        >保存到相册</div>
        <div
          class="share text-center"
          @click.prevent="share"
        >分享</div>
      </div>
    </div>
  </van-overlay>
</template>

<script type='text/ecmascript-6'>
export default {
  name: 'Poster',
  props: ['value', 'apiName', 'currentItem', 'activityData'],
  data() {
    return {
      show: false,
      img: null
    }
  },
  mounted() {},
  watch: {
    value(n) {
      this.show = n
    }
  },
  methods: {
    close() {
      this.show = false
      this.$emit('close')
    },
    save() {
      this.showToast('请长按海报保存')
    },
    share() {
      let { currentItem, apiName, activityData } = this
      let flag = apiName != 'shopmallApi'
      if (currentItem.userId) {
        console.log(activityData)
        window.$wx
          .sendChatMessage({
            msgtype: 'image',
            image: {
              mediaid: activityData.posterMediaId
            },
            enterChat: false
          })
          .then(() => {
            this.showToast('发送成功')
          })
      } else {
        window.$wx
          .shareAppMessage({
            imgUrl: flag ? currentItem.shareImgUrl : currentItem.goodsImage,
            title: flag ? currentItem.name : currentItem.goodsName,
            link: flag ? activityData.pagePath : activityData.url
          })
          .then(res => {
            this.showToast('发送成功')
          })
      }
    }
  }
}
</script>

<style scoped lang='scss'>
.van-overlay {
  position: absolute;
}
.wrapper {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  flex-direction: column;
  .img {
    width: 254px;
    height: 452px;
    position: relative;
    .icon-poster-close {
      position: absolute;
      top: -10px;
      right: -10px;
      z-index: 2;
    }
  }
  .btns {
    width: 254px;
    justify-content: space-between;
    margin-top: 16px;
    .text-center {
      width: 119px;
      height: 32px;
      border-radius: 16px;
      font-size: 14px;
      color: #ffffff;
    }
    .save {
      background: rgba(0, 0, 0, 0.3);
    }
    .share {
      background: var(--themeColor);
    }
  }
}
</style>