import * as constants from './constants';
import { fromJS } from 'immutable';
import * as config from '../../../common/config.js';
import axios from '../../../common/axios_auth.js';
import qs from 'qs';

//获得公司详情
export const getCompanyDetail = (key,error) => {
    return (dispatch) => {
        axios.get(config.CLD2API + '/contact/companyDetail/'+key).then((res) => {
            const data = res.data;
            if (data.code === 200) {
                dispatch({
                    type: constants.CHANGE_COMPANY_DETAIL,
                    data: data.data,
                });
            } else {
                error('公司详情请求失败');
            }
        }).catch((e) => {
            error('公司详情请求失败');
        })
    }
};
//loading
export const changeLoading = () => {
    return (dispatch) => {
        dispatch({
            type: constants.CHANGE_COMPANYDETAIL_LOADING,
            data: true,
        });
    }
}
//
export const modifyCompany = (name,value,error) => {
    return (dispatch) => {

        let data = {
            'field':name,
            'value': value,
        };
        
        axios.post(config.CLD2API + '/contact/modifyCompany', qs.stringify(data)).then((res) => {
            const data = res.data;
            if (data.code === 200) {
                // dispatch({
                //     type: constants.CHANGE_COMPANY_DETAIL,
                //     data: data.data,
                // });
            } else {
                error('公司详情更新失败2');
            }
        }).catch((e) => {
            error('公司详情更新失败3');
        })
    }
}



