
import React from 'react';
import {Icon,Upload,Modal} from 'antd';
import ImgList from "../../common/imgList";

const PicturesWall = React.createClass({
    getInitialState() {
        return {
            previewVisible: false,
            previewImage: '',
            fileList: [],
        }
    },
    handleCancel() {
        this.setState({ previewVisible: false })
    },
    handlePreview(file) {
        this.setState({
            previewImage: file.url || file.thumbUrl,
            previewVisible: true,
        });
    },
    handleChange(info) {
        console.log(info)
        let fileList = info.fileList;
        this.setState({ fileList });
        this.props.fileList(fileList);
    },
    componentWillReceiveProps(nextProps) {
        this.state.fileList = nextProps.pictureUrl;
    },
    render() {
        const { previewVisible, previewImage, fileList } = this.state;
        const uploadButton = (
            <div>
                <Icon type="plus" />
                <div className="ant-upload-text">点击上传</div>
            </div>
        );
        return (
            <div className="clearfix">
                <ImgList
                    domId={this.props.domId}
                    uploadConfig={{
                        action:globalConfig.context + this.props.data.url,
                        data:{ 'sign': this.props.data.sign },
                        listType:"picture-card",
                        multiple:true,
                    }}
                    onChange={(infor)=>{
                        this.handleChange(infor)
                    }}
                    fileList={fileList}
                />
                {/*<Upload*/}
                {/*    action={globalConfig.context + this.props.data.url}*/}
                {/*    data={{ 'sign': this.props.data.sign }}*/}
                {/*    listType="picture-card"*/}
                {/*    fileList={fileList}*/}
                {/*    multiple={true}*/}
                {/*    onPreview={this.handlePreview}*/}
                {/*    onChange={this.handleChange} >*/}
                {/*    {uploadButton}*/}
                {/*</Upload>*/}
                {/*<Modal maskClosable={false} visible={previewVisible} footer={null} onCancel={this.handleCancel}>*/}
                {/*    <img alt="example" style={{ width: '100%' }} src={previewImage} />*/}
                {/*</Modal>*/}
            </div>
        );
    }
});
 
export default PicturesWall;