import Vue from 'vue';
import Vuex from 'vuex';
import _ from 'lodash';
Vue.use(Vuex);
const api = {
  corpBase: corpid => `/api/corp/corps/${corpid}`,
  corpInfo: corpid => `/api/corp/corps/${corpid}/info`,
  corpIdentity: corpid => `/api/corp/corps/${corpid}/identity`,
};
export const state = () => ({});
export const mutations = {};
export const actions = {
  async getCorp({ state }, { type, data }) {
    let result;
    if (type === 'search') {
      let { corpid } = data;
      result = await this.$axios.$get(api.corpInfo(corpid));
    }
    if (type === 'component') {
      let { corpid } = data;
      let base = await this.$axios.$get(api.corpBase(corpid));
      let info = await this.$axios.$get(api.corpInfo(corpid));
      let identity = await this.$axios.$get(api.corpIdentity(corpid));
      result = {
        data: { ...info.data, ...identity.data, ...base.data },
        errcode: `${info.errcode}` === '0' && `${identity.errcode}` === '0' && `${base.errcode}` === '0' ? '0' : '1',
      };
    }
    return result;
  },
};
