// 注意事项
import React from 'react';
import { $http } from "containers/config/https";
import { List, Toast } from 'antd-mobile';
import './style/visitRecords.less';
import zljlNodata from 'assets/images/zljl-nodata.png'
// import registrationNo from "../../assets/images/registration-no.png";
import { Modal, Button, } from 'antd-mobile';

const Item = List.Item;

export default class Precautions extends React.Component {
    constructor({ history }) {
        super();
        let userData = localStorage.getItem("userData") ? JSON.parse(localStorage.getItem("userData")) : {};
        this.state = {
            userData,
            visitRecordsListData: [],
            PrecautionsData: {},
            visible: false
        }
        this.history = history;
    }

    componentDidMount() {
        this.getVisitRecordsListData();
    }

    componentWillUnmount() {
        // 组件销毁前将静止让setState修改state的状态
        this.setState = (state, callback) => { return; }
    }

    handleShowGuide = (v) => {
        this.setState({ visible: true, PrecautionsData: v })
    }

    // 关闭指引弹出
    handleClose = () => {
        this.setState({ visible: false })
    }
    // 获取就诊记录
    getVisitRecordsListData = () => {
        Toast.loading('数据加载中...', 30);
        let { userData } = this.state;
        let data = {
            params: [{
                hospCode: userData.hisHospID,
                userCode: "ZYCPJS",
                patNO: userData.hisPatNo
            }]
        }
        $http.post("urlS", this, {
            code: "130983",
            data: data,
            namespace: "UPP",
            success: function (res) {
                Toast.hide()
                if (+res.errorCode === 0) {
                    for (var i = 0; i < res.result.length; i++) {
                        if (res.result[i].matters.length > 0) {
                            for (var k = 0; k < res.result[i].matters.length; k++) {

                                res.result[i].matters[k].data = res.result[i].matters[k].value.split('$c(2)');
                                // res.result[i].matters[k].data=res.result[i].matters[k].value.replace(/$c(2)/g,'\n')
                            }
                        }
                    }
                    this.setState({ visitRecordsListData: res.result });
                } else {
                    this.setState({ visitRecordsListData: [] });
                }
            },
            error: function () {
                Toast.hide()
            }
        });
    }

    render() {
        let { visitRecordsListData, visible, PrecautionsData, userData } = this.state;
        // let detailData = visitRecordsListData && visitRecordsListData.length > 0 ? visitRecordsListData[0] : {};
        return (
            <div className="visit-records">
                <List className="visit-records-list">
                    {visitRecordsListData.length > 0 && visitRecordsListData.map((item, index) => {
                        return <Item key={index} multipleLine>
                            <div className="visit-records-list-item">
                                <p className='tit'>
                                    {item.patName} {userData.hisPatNo} {item.admReasonDesc}
                                </p>
                                <p className='tit-D'>
                                    {item.admLoc} {item.admDoctor} {item.admDate + item.admTime}
                                </p>
                                {/*<p>*/}
                                {/*<span className="visit-records-list-item-key">出院小结：</span>{item.admEPRData ? item.admEPRData : <span style={{color: "#999"}}>暂无记录</span>}*/}
                                {/*</p>*/}
                            </div>
                            <div className='matters'>
                                {item.matters.length > 0 && item.matters.map((v, key) => {
                                    return <p key={key} onClick={() => { this.handleShowGuide(v) }}>{key + 1}、{v.matters}</p>
                                })}
                            </div>
                        </Item>
                    })}
                </List>
                <div style={{ display: visitRecordsListData.length > 0 ? 'none' : 'block', width: '100%', textAlign: 'center', color: '#999' }}>
                    <img style={{ width: '100%' }} src={zljlNodata} alt="" />
                    暂无记录
                </div>
                <Modal
                    visible={visible}
                    onClose={this.handleClose}
                    className="precautions-modal"
                    transparent
                >
                    <div className="precautions-modal-content">
                        <h3>{PrecautionsData.matters}</h3>
                        <p style={{ height: 'calc(100vh/2 + 2.5rem)' }}>
                            {PrecautionsData.data && PrecautionsData.data.length > 0 && PrecautionsData.data.map((item, v) => {
                                return <div key={v} style={{ textAlign: 'left' }}>{item}</div>
                            })}
                        </p>
                    </div>
                    <Button type="primary" onClick={this.handleClose} className="bottom-mat">确定</Button>
                </Modal>
            </div>
        )
    }
}
