import { requests } from '@/service/api/index';
import globalConfig from '@/config/index';
import Vue from 'vue';

import store from '@/store/index';
export default config => {
  const { createApp } = config;

  window.onload = async function() {
    try {
      const fullLoading = Vue.prototype.$loading({ lock: true });
      // 获取用户企业id
      let loginUserRes = await requests('/api-auth/get-login-user-info', { requestProject: 'gic-web', f: 1 });
      let enterpriseId = loginUserRes.result.enterpriseId;
      store.commit('updateEnterpriseId', enterpriseId); // 更新企业id
      const couponEnable = await requests('/api-marketing/opt-coupon-enable', { requestProject: 'marketing' });
      store.commit('updateAppletEnable', couponEnable.result || false); // result:   true,能改 false不能
      store.commit('updateLimitCodeList', loginUserRes.result.limitCodeList);
      createApp();
      fullLoading.close();
    } catch (error) {
      // 未登录
      window.location.href = globalConfig.api + 'gic-web/';
    }
  };
};
