actionCreators.js 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. import * as constants from './constants';
  2. import { fromJS } from 'immutable';
  3. import * as config from '../../../common/config.js';
  4. import axios from '../../../common/axios_auth.js';
  5. import qs from 'qs';
  6. import { message } from 'antd';
  7. const error = (msg) => {
  8. message.error({
  9. content: msg,
  10. });
  11. };
  12. const success = (msg) => {
  13. message.success(msg);
  14. };
  15. //获得公司详情
  16. export const getCompanyDetail = (key, error) => {
  17. return (dispatch) => {
  18. axios.get(config.CLD2API + '/contact/companyDetail/' + key).then((res) => {
  19. const data = res.data;
  20. if (data.code === 200) {
  21. dispatch({
  22. type: constants.CHANGE_COMPANY_DETAIL,
  23. data: data.data,
  24. });
  25. } else {
  26. error('公司详情请求失败');
  27. }
  28. }).catch((e) => {
  29. error('公司详情请求失败');
  30. })
  31. }
  32. };
  33. //loading
  34. export const changeLoading = () => {
  35. return (dispatch) => {
  36. dispatch({
  37. type: constants.CHANGE_COMPANYDETAIL_LOADING,
  38. data: true,
  39. });
  40. }
  41. }
  42. //改变input值
  43. export const changeInputValue = (parameter) => {
  44. return (dispatch) => {
  45. dispatch({
  46. type: constants.CHANGE_INPUT_VALUE,
  47. data: parameter,
  48. });
  49. }
  50. }
  51. //更新公司详情
  52. export const modifyCompany = (parameter) => {
  53. return (dispatch) => {
  54. let data = {...parameter};
  55. axios.post(config.CLD2API + '/contact/modifyCompany', qs.stringify(data)).then((res) => {
  56. const data = res.data;
  57. if (data.code === 200) {
  58. if(parameter.field==='district'){
  59. let result = parameter.lable.map(item => { return item.label; })
  60. success(`"${parameter.title}"已保存为"${result.join(',')}"`);
  61. }else{
  62. success(`"${parameter.title}"已保存为"${parameter.value}"`);
  63. }
  64. } else {
  65. error(`更新${parameter.title}失败`);
  66. }
  67. }).catch((e) => {
  68. error(`更新${parameter.title}失败`);
  69. })
  70. }
  71. }