import { requests } from '@/service/api/index';

import store from '@/store/index';
export default config => {
  const { createApp } = config;
  (function() {
    // 获取用户企业id
    const getUserInfo = requests('/api-auth/get-login-user-info', { requestProject: 'gic-web', f: 1 }).then(data => {
      const result = data.result || {};
      store.commit('updateEnterpriseId', result.enterpriseId); // 更新企业id
      store.commit('updateLimitCodeList', result.limitCodeList);
      store.commit('updateSuperAdmin', result.superAdmin);
      store.commit('updateDepartAuth', result.departAuth);
      store.commit('updateUserId', result.userId);
      store.commit('updateStoreCardAuth', result.enterpriseDTO.brandType == 2);
    });
    const getCouponEnable = requests('/api-marketing/opt-coupon-enable', { requestProject: 'marketing' }).then(data => {
      store.commit('updateAppletEnable', data.result || false); // result:   true,能改 false不能
    });
    Promise.all([getUserInfo, getCouponEnable]).finally(() => {
      createApp();
    });
  })();
};
