import { getDepositDetails, getsubscribeID } from './service';
import { reportApi } from '../../utils/cloudMonitorHelper';
Component({
  data: {
    showSubscrible: true,
    // 是否显示订阅部分
    detail: null,
    // 缴纳详情
    isReady: false
  },

  didMount() {
    const {
      depositId
    } = this.$page.data.query || {};
    this.getDepositDetailsFn(depositId);
    this.subscribeMsg();
    /* 服务办结，押金缴纳完成 */

    reportApi('押金缴纳完成');
  },

  methods: {
    subscribeMsg() {
      const pluginId = 2021001155639035;
      my.loadPlugin({
        plugin: `${pluginId}@*`,
        success: () => {
          this.setData({
            isReady: true
          }); // 储存插件实列
          // eslint-disable-next-line no-undef

          const pluginInstance = requirePlugin(`dynamic-plugin://${pluginId}`);
          this.requestSubscribeMessage = pluginInstance.requestSubscribeMessage;
        }
      });
    },

    showSubscrible() {
      this.setData({
        showSubscrible: false
      });
    },

    // 订阅插件要用时，请放开注释
    requestSubscribeMessageFn(subscribeID) {
      return new Promise(resolve => {
        this.requestSubscribeMessage({
          // 模板id列表，最多3个
          entityIds: [subscribeID],

          callback() {
            resolve(true);
          }

        });
      });
    },

    async gotoSubscrible() {
      try {
        const subscribeID = await getsubscribeID();
        await this.requestSubscribeMessageFn(subscribeID.depositTemplateId);
      } catch (error) {
        console.log(error, 'error');
      }
    },

    // 获取支付详情
    async getDepositDetailsFn(depositId) {
      try {
        const detail = await getDepositDetails({
          depositId
        });
        this.setData({
          detail
        });
      } catch (error) {
        console.log(error, 'error');
      }
    }

  }
});