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'; import { message } from 'antd'; const error = (msg) => { message.error({ content: msg, }); }; const success = (msg) => { message.success(msg); }; //获得公司详情 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, }); } } //改变input值 export const changeInputValue = (parameter) => { return (dispatch) => { dispatch({ type: constants.CHANGE_INPUT_VALUE, data: parameter, }); } } //更新公司详情 export const modifyCompany = (parameter) => { return (dispatch) => { let data = {...parameter}; axios.post(config.CLD2API + '/contact/modifyCompany', qs.stringify(data)).then((res) => { const data = res.data; if (data.code === 200) { if(parameter.field==='district'){ let result = parameter.lable.map(item => { return item.label; }) success(`"${parameter.title}"已保存为"${result.join(',')}"`); }else{ success(`"${parameter.title}"已保存为"${parameter.value}"`); } } else { error(`更新${parameter.title}失败`); } }).catch((e) => { error(`更新${parameter.title}失败`); }) } }