<template>
  <wx-open-launch-weapp
    class="launch-btn"
    username="gh_a976018bfb9e"
    :path="jumpUrl"
    @launch="launch"
    @error="launchError"
  >
    <script type="text/wxtag-template">
      <style>.btn {height: 96px}</style>
      <div class="btn">打开小程序</div>
    </script>
  </wx-open-launch-weapp>
</template>
<script>
import wx from 'weixin-js-sdk';
import groupBuy from '@/api/groupBuy';
export default {
  name: 'Weapp',
  props: {
    registeredObj: {
      type: Object,
      default: () => ({
        key: '',
        value: {}
      })
    },
    jumpUrl: String
  },
  data() {
    return {};
  },
  created() {
    this.wxConfig();
  },
  methods: {
    async wxConfig() {
      const [res] = await groupBuy.getWxConfig();
      wx.config({
        debug: false,
        jsApiList: ['onMenuShareTimeline', 'onMenuShareAppMessage'], // 必填，需要使用的JS接口列表
        openTagList: ['wx-open-launch-weapp'],
        ...res
      });
    },
    launch() {
      console.log('launch');
    },
    launchError() {
      console.log('launchError');
    }
  }
};
</script>
<style lang="less">
.launch-btn {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 100%;
  opacity: 0;
  z-index: 100;
  left: 0;
}
</style>
