<template>
  <div class="share">
    <cr-share
      v-model="showShare"
      :types="types"
      @close="shareCloseChange"
      @click-share-item="bundleShareClickItem"
    />
  </div>
</template>
<script>
import { isWxMp, isApp } from '@/service/validation.service';
export default {
  name: 'GroupShare',
  components: {},
  props: {},
  data() {
    return {
      showShare: false,
      types: [
        { value: 'weixin', disabled: false },
        { value: 'pic', disabled: false }
      ]
    };
  },
  computed: {
    notBwoser() {
      return !isWxMp && !isApp;
    }
  },
  watch: {},
  methods: {
    async open() {
      try {
        // if (this.notBwoser) {
        //   this.$toast('非小程序和App设备!');
        //   return;
        // }
        let options = await this.getShareData();
        console.log(options, isWxMp, isApp);

        // 判断是否时小程序平台
        if (isWxMp) {
          this.showShare = true;
        }
        // 判断是否是App
        if (isApp) {
          this.shareAppChange(options);
          console.log('App');
        }
      } catch (err) {
        this.$toast('调用分享失败!');
      }
    },

    async getShareData() {
      return Promise.resolve(1);
      // await
    },

    shareCloseChange() {
      this.$emit('hideShare', false);
    },
    bundleShareClickItem(ev) {
      console.log(ev);
      console.log(this.nativeBridge);
    },
    shareAppChange({ title, desc, link, imgUrl }) {
      const data = {
        event: 'showShareView',
        data: {
          platform: ['weChat', 'timeLine', 'QQ', 'QQZone', 'CopyLink'], //依次分别是微信、朋友圈、QQ好友、QQ空间、复制链接
          shareDic: {
            title,
            desc,
            link, // 页面地址
            imgUrl // 图片地址
          }
        }
      };
      this.nativeBridge.showShareView(data);
    }
  }
};
</script>
<style lang="less"></style>
