import React from 'react';
import List from '../../../components/List'
import AdjunctList from '../../../components/Adjunct'


const Adjunct = (props) => {
    const {data, download} = props;
    // const downlaod = (src) => {
    //     const iframe = document.createElement('iframe');
    //     iframe.style.display = 'none';
    //     iframe.src = "javascript: '<script>location.href=\"" + src + "\"<\/script>'";
    //     document.getElementsByTagName('body')[0].appendChild(iframe);
    // }
    const downloadFile = (uuid) => {
        download(uuid, res => {
            console.log(res)
            // try {
            //     var enc = new TextDecoder('utf-8');
            //     var result = JSON.parse(enc.decode(new Uint8Array(res))); //转化成json对象
            //     console.log(result)
            // } catch (error) {
            //     var blob = new Blob([res], {
            //         type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset=utf-8',
            //     });
            //     var downloadElement = document.createElement('a');
            //     var href = window.URL.createObjectURL(blob); //创建下载的链接
            //     downloadElement.href = href;
            //     downloadElement.download = ''; //下载后文件名
            //     document.body.appendChild(downloadElement);
            //     downloadElement.click(); //点击下载
            //     document.body.removeChild(downloadElement); //下载完成移除元素
            //     window.URL.revokeObjectURL(href); //释放掉blob对象
            // }
        })
    }
    const listData = [
        {title: '附件', line: data.length > 0, content:
                <div>
                    {data.length > 0 ? data.map((item, index) => (
                        <AdjunctList key={index} data={item} onClick={() => downloadFile(item.UUID)}/>
                    )) : '无'}
                </div>
        },
    ]
    return (
        <div>
            <List listData={listData}/>
        </div>
    );
};

export default Adjunct;
