import Vue from 'vue';
import Vuex from 'vuex';
import _ from 'lodash';
Vue.use(Vuex);
const api = {
  range: `/api/jobs/fairs/date`,
  list: `/api/jobs/fairs`,
  fetch: id => `/api/jobs/fairs/${id}`,
  //双选会企业信息
  fairCorp: '/api/jobs/faircorps',
  fairJobs: id => `/api/jobs/faircorps/${id}/jobs`,
};
export const state = () => ({});
export const mutations = {};
export const actions = {
  async getJobfair({ state }, { type, data }) {
    let { skip = 0, limit } = data;
    let result;
    if (type !== 'fetch') {
      let { schid, date, ...searchInfo } = data;
      result = await this.$axios.$get(_.get(api, type), {
        schid: schid,
        skip: skip,
        limit: limit,
        date: date,
        status: '1',
        ...searchInfo,
      });
    }
    if (type === 'fetch') {
      let { id } = data;
      result = await this.$axios.$get(api.fetch(id));
    }
    return result;
  },
  //招聘会企业信息
  async fairInfoOperation({ state }, { type, data }) {
    let result;
    let { skip, limit } = data;
    if (type === 'searchCorp') {
      let { schid, fairid, corpid, status } = data;
      result = this.$axios.$get(api.fairCorp, { schid: schid, fairid: fairid, corpid: corpid, status: status, skip: skip, limit: limit });
    }
    if (type === 'searchJobs') {
      let { id } = data;
      result = this.$axios.$get(api.fairJobs(id), { skip: skip, limit: limit });
    }
    return result;
  },
};
