<template>
  <div class="share">
    <cr-share
      v-model="showShare"
      :types="types"
      @close="shareCloseChange"
      @click-share-item="bundleShareClickItem"
    />
  </div>
</template>
<script>
import MpBridge from '@/service/mp';
import { mapState } from 'vuex';
import { registeredEvents } from '@/service/sa.service';
import { EventBus } from '@/service/utils.service';
export default {
  name: 'GroupShare',
  components: {},
  props: {},
  data() {
    return {
      showFlag: false,
      shareOptions: null,
      nativeBridge: null,
      types: [
        { value: 'weixin', disabled: false },
        { value: 'pic', disabled: false }
      ]
    };
  },
  computed: {
    ...mapState({
      shareInfo: state => state.pay.shareInfo
    }),
    showShare: {
      get() {
        return this.$store.state.pay.showShare;
      },
      set() {
        this.$store.dispatch('goods_share_close');
      }
    }
  },
  watch: {},
  created() {
    // 如果是小程序直接调用postMessage像小程序派发事件监听
    this.nativeBridge = new MpBridge();
  },
  methods: {
    shareCloseChange() {},
    bundleShareClickItem(ev) {
      if (ev === 'weixin') {
        this.shareDialogConfirm();
      }
      const nativeBridge = this.nativeBridge;
      console.log('派发事件！');
      EventBus.$emit('shareClickItem', { ev, nativeBridge });
      registeredEvents('H5_GroupZeroYuanPurchaseActivityPageSharePopupWindowBtnClick', {
        sku_no: '',
        buttons_name: '', // 按钮名称
        activity_id: '',
        page_title: '',
        leader_user_id: '' //团长user_id
      });
    },
    shareDialogConfirm() {
      this.$store.dispatch('goods_share_close');
      this.$dialog({
        message: '请点击小程序右上角更多进行分享~',
        showCancelButton: false,
        confirmButtonText: '我知道了哦～',
        onConfirm: () => {}
      });
    }
    // shareAppChange() {}
  }
};
</script>
<style lang="less"></style>
