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

//显示隐藏列
export const toggleColumns = (index) => {
    return (dispatch) => {
        dispatch({
            type: constants.TOGGLE_COLUMNS,
            data: index,
        });
    }
};
export const toggleColumnsAll = (dt) => {
    return (dispatch) => {
        dispatch({
            type: constants.TOGGLE_COLUMNS_ALL,
        });
    }
};

//获得数据
export const changeSortField = (sortField) => {
    return (dispatch) => {
        dispatch({
            type: constants.CHANGE_COMPANY_SORTFIELD,
            data: sortField,
        });
    }
}
export const changeSort = (sort) => {
    return (dispatch) => {
        dispatch({
            type: constants.CHANGE_COMPANY_SORT,
            data: sort,
        });
    }
}
export const changeLoading = () => {
    return (dispatch) => {
        dispatch({
            type: constants.CHANGE_COMPANY_LOADING,
            data: true,
        });
    }
}
export const getCompanyLIst = (pagination, props, sorter) => {
    return (dispatch) => {

        // changeList(pagination,props,dispatch);
        let sortField = props.sortField;
        let sort = props.sort;
        if (typeof (sorter) !== 'undefined') {
            sortField = sorter.sortField;
            sort = sorter.sort;
        }
        axios.get(config.CLD2API + '/contact/company', {
            params: {
                current: pagination.current,
                pageSize: pagination.pageSize,
                sortField: sortField,
                sort: sort,
            },
        }).then((res) => {
            const data = res.data;
            if (data.code === 200) {
                //let d2=JSON.parse(data.list);
                //dispatch(changeList(JSON.parse(d2)));
                dispatch({
                    type: constants.CHANGE_COMPANY_DATA,
                    data: data,
                    pagination: pagination,
                    props: props
                });
            } else {
                console.log(data);
            }
        }).catch((e) => {
            console.log(e);
            console.log('error');
        })

    }
};


// const changeList = (pagination,props,dispatch) => {
//     const { sortField, sort } = props;
//     axios.get(config.CLD2API + '/contact/company', {
//         params: {
//             current: pagination.current,
//             pageSize: pagination.pageSize,
//             sortField: sortField,
//             sort: sort,
//         },
//     }).then((res) => {
//         const data = res.data;
//         if (data.code === 200) {
//             dispatch({
//                 type: constants.CHANGE_COMPANY_DATA,
//                 data: data,
//                 pagination: pagination,
//                 props: props
//             });
//         } else {
//             console.log(data);
//         }
//     }).catch((e) => {
//         console.log(e);
//         console.log('error');
//     })
// }






