Component({
  props: {
    componentData: {},
  },
  data: {
    isReady: false,
    pluginAppId: '',
    pluginComponent: '',
    pluginVersion: '',

    pid: '',
    shopId: '',
    wrap: 'N',
  },

  didMount() {
    const {
      componentData: { componentExtInfo },
    } = this.props;
    // const { query } = my.getLaunchOptionsSync() || {};
    const {
      plgId,
      plgComp,
      plgVer,
      pid,
      shopId,
      wrap,
      wrapTitle,
    } = componentExtInfo;
    this.setData({
      pluginAppId: plgId,
      pluginComponent: plgComp,
      pluginVersion: plgVer,

      pid,
      shopId,
      wrap,
      wrapTitle,
    });
    this.loadPlugin();
  },

  methods: {
    loadPlugin() {
      const { pluginVersion, pluginAppId, pluginComponent } = this.data;

      const {
        componentData: { componentType },
      } = this.props;
      console.log(
        `加载插件, 开始 ${pluginAppId}, ${componentType} ${pluginComponent}`,
      );
      try {
        my.loadPlugin({
          plugin: `${pluginAppId}@${pluginVersion}`,
          success: () => {
            this.setData({
              isReady: true,
            });
          },
          fail: () => {
            console.log(
              `加载插件失败, id: ${pluginAppId}, type: ${componentType}`,
            );
          },
        });
      } catch (e) {
        throw new Error(
          'plugin must be pluginAppId and pluginVersion, please configure on AB saas！',
        );
      }
    },
  },
});
