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,
            dt:dt
        });
    }
};










export const getClientLIst = () => {
    return (dispatch) => {
        
        axios.get(config.CLD2API+'/contact/client').then((res) => {
            const data = res.data;
            
            if(data.code===200){

                //let d2=JSON.parse(data.list);
console.log(data.data);
dispatch(changeList(data.data));
                //dispatch(changeList(JSON.parse(data.list)));
                // dispatch({
                //     type: constants.CHANGE_CLIENT_DATA,
                //     data: fromJS(d2),
                // });
            }else{
                console.log(data);
            }
        }).catch((e) => {
            console.log(e);
            console.log('error');
        })
    }
};



//actionType
// export const searchFocus = () => ({
//     type: constants.SEARCH_FOCUS
// });

// export const getList = () => {
//     return (dispatch) => {
//         axios.get('/api/submenuList.json').then((res) => {
//             const data = res.data;
//             dispatch(changeList(data.data));
//         }).catch(() => {
//             console.log('error');
//         })
//     }
// };

// export const changeInputValue = (value) => (  {
//     type: constants.CHANGE_INPUTVALUE,
//     data:fromJS(value),
// });

const changeList = (data) => ({
    type: constants.CHANGE_CLIENT_DATA,
    data: fromJS(data),
});



