/*
 * @Descripttion: 当前组件信息
 * @version: 1.0.0
 * @Author: 无尘
 * @Date: 2018-10-08 10:45:05
 * @LastEditors: 无尘
 * @LastEditTime: 2020-05-28 20:34:08
 */
import 'babel-polyfill';
import promise from 'es6-promise';
promise.polyfill();
import App from './App';
import router from './router';
import store from './store/store';
/* eslint-disable  */
import '../static/css/index.less';
import '../theme/index.css';

import '../static/css/dialog.css';
import filters from './filters/index.js';

import SvgIcon from "./components/common/svg-icon"
Vue.component("svg-icon", SvgIcon)

import vueOfficeHeader from '@gic-test/vue-office-header';
import vueOfficeAside from '@gic-test/vue-office-aside';
import vueOfficeArea from '@gic-test/vue-office-area';
import vueGicImgPreview from '@gic-test/vue-gic-img-preview';
import vueOfficeUploadImage from '@gic-test/vue-office-upload-image';
import htmlToPdf from '@/components/utils/htmlToPdf';
import VueAMap from 'vue-amap';
import Vue from 'vue';
import { postRequest } from '@/api/api.js';
import errorMsg from '@/common/js/error.js';

// Vue.use(contentmenu);
Vue.use(VueAMap);
VueAMap.initAMapApiLoader({
  key: 'd53a58848be368a7398dc56d5670fe9c',
  plugin: ['Autocomplete', 'PlaceSearch', 'Scale', 'OverView', 'Geocoder', 'ToolBar', 'MapType', 'PolyEditor', 'AMap.CircleEditor'],
  v: '1.4.4'
});
window.ELEMENT.Dialog.props.closeOnClickModal.default = false; // 全局设置点击蒙层不关闭
Vue.use(htmlToPdf);
Vue.use(vueGicImgPreview);
Vue.use(vueOfficeUploadImage);
Vue.use(vueOfficeArea);
Vue.use(vueOfficeAside);
Vue.use(vueOfficeHeader);

Vue.config.productionTip = false;
// Vue.use(ElementUI, { size: 'large' });

// 全局注册过滤器
Object.keys(filters).forEach(key => {
  Vue.filter(key, filters[key]);
});

/*
 * 路由守护
 */
router.beforeEach((to, from, next) => {
  if (window.axiosPromiseArr) {
    axiosPromiseArr.forEach((ele, index) => {
      ele.cancel();
      delete axiosPromiseArr[index];
    });
  }

  let baseUrl;
  let host = window.location.origin;
  if (host.indexOf('localhost') != -1) {
    baseUrl = 'http://www.gicdev.com';
  } else {
    baseUrl = host;
  }
  next();
});
Vue.prototype.$buttonCode = {
  multipleAssign: 'multipleAssign',
  assign: 'assign',
  syncTagLog: 'syncTagLog',
  willSyncTag: 'willSyncTag',
  groupExpire: 'groupExpire',
  syncGroup: 'syncGroup',
  addGroupTemp: 'addGroupTemp',
  editGroupTemp: 'editGroupTemp',
  setStoreArea: 'setStoreArea',
  delGroupTemp: 'delGroupTemp',
  searchSetSave: 'searchSetSave',
  addCard: 'addCard',
  editCard: 'editCard',
  delCard: 'delCard',
  sendCardLog: 'sendCardLog',
  getCardLog: 'getCardLog',
  addText: 'addText',
  editText: 'editText',
  delText: 'delText',
  textAssignStore: 'textAssignStore',
  addImage: 'addImage',
  editImage: 'editImage',
  delImage: 'delImage',
  imageAssignStore: 'imageAssignStore',
  addWeb: 'addWeb',
  editWeb: 'editWeb',
  delWeb: 'delWeb',
  webAssignStore: 'webAssignStore',
  addVideo: 'addVideo',
  editVideo: 'editVideo',
  delVideo: 'delVideo',
  videoAssignStore: 'videoAssignStore',
  addFile: 'addFile',
  editFile: 'editFile',
  delFile: 'delFile',
  fileAssignStore: 'fileAssignStore',
  addApps: 'addApps',
  editApps: 'editApps',
  delApps: 'delApps',
  appsAssignStore: 'appsAssignStore',
  saveGoodsSet: 'saveGoodsSet',
  exportActiveUser: 'exportActiveUser',
  exportLoginUser: 'exportLoginUser',
  exportAreaLoginUser: 'exportAreaLoginUser',
  multipleDelReport: 'multipleDelReport',
  exportReport: 'exportReport',
  reportDetail: 'reportDetail',
  multipleDelReportDetail: 'multipleDelReportDetail',
  delReportDetail: 'delReportDetail',
  showReportDetail: 'showReportDetail',
  multipleExportReport: 'multipleExportReport',
  saveTaskSet: 'saveTaskSet',
  monthTarget: 'monthTarget',
  dayTarget: 'dayTarget',
  exportMonthTask: 'exportMonthTask',
  checkMonthTask: 'checkMonthTask',
  multipleDelTask: 'multipleDelTask',
  delTask: 'delTask',
  exportStoreList: 'exportStoreList',
  checkStoreList: 'checkStoreList',
  exportStoreDetail: 'exportStoreDetail',
  checkStoreDetail: 'checkStoreDetail',
  exportStoreDetailPop: 'exportStoreDetailPop',
  previewStoreDetail: 'previewStoreDetail',
  exportGrTaskList: 'exportGrTaskList',
  checkGrTaskList: 'checkGrTaskList',
  exportTaskRecord: 'exportTaskRecord',
  multipleDelTaskRecord: 'multipleDelTaskRecord',
  checkTaskRecord: 'checkTaskRecord',
  exportTaskDetail: 'exportTaskDetail',
  multipleDelTaskDetail: 'multipleDelTaskDetail',
  delTaskDetail: 'delTaskDetail',
  resolveTaskDetail: 'resolveTaskDetail',
  previewTaskDetail: 'previewTaskDetail',
  exportTaskViewDetail: 'exportTaskViewDetail',
  multipleDelTaskViewDetail: 'multipleDelTaskViewDetail',
  addSalutatory: 'addSalutatory',
  editSalutatory: 'editSalutatory',
  delSalutatory: 'delSalutatory',
  refreshStoreMember: 'refreshStoreMember',
  exportContact: 'exportContact',
  checkContactDetail: 'checkContactDetail',
  checkContactMemberDetail: 'checkContactMemberDetail',
  refreshStoreInfo: 'refreshStoreInfo',
  saveMemberSecret: 'saveMemberSecret',
  addMemberAppsSecret: 'addMemberAppsSecret',
  editMemberAppsSecret: 'editMemberAppsSecret',
  delMemberAppsSecret: 'delMemberAppsSecret',
  addAppsSecret: 'addAppsSecret',
  getAppsSecret: 'getAppsSecret',
  editAppsSecret: 'editAppsSecret',
  delAppsSecret: 'delAppsSecret',
  bindStoreList: 'bindStoreList',
  refreshAdminList: 'refreshAdminList'
}
Vue.prototype.$getButtonLimit = (code) => {
  return !!Vue.prototype.$buttonCode[code];
}

postRequest('/haoban-manage3-web/get-login-info', {}).then(resp => {
  // 正常情况下enterpriseId必定存在
  // superManagerFlag 1：超管
  // 如果enterpriseId不存在，而且不是超管，弹窗报错并且不进入页面
  const { errorCode, result } = resp.data || {};
  if (errorCode != 1) {
    errorMsg.errorMsg(resp.data);
    return;
  }
  sessionStorage.setItem('userInfos', JSON.stringify(result));
  /**
   * 获取好办 企业 id
   */
  if (!!sessionStorage.getItem('userInfos')) {
    let haobanSign = JSON.parse(sessionStorage.getItem('userInfos')).enterpriseId;
    haobanSign ? (Vue.axios.defaults.headers.common['enterpriseId'] = haobanSign) : '';
  }
}).finally(() => {
  /* eslint-disable no-new */
  new Vue({
    el: '#app',
    router,
    store,
    components: { App },
    template: '<App/>'
  });
});
