/*
 * Creator:     TQ
 * CreatDate:   2020-04-20
 * descripts：IC卡信息
 * */
import React from 'react';
import { Select, Row, Col, Button, Radio, message, Table, Input } from 'antd';
import '../css/error.less';
import { $http } from '../../../containers/config/https';
import ReadCard from '../../../components/readcard/ReadCard';

// 组件const
const { Option } = Select;




export default class ICCardInformationModal extends React.Component {
	constructor(props) {
		super(props)
		this.state = {
            userInfo: {},
			visible: false,
			transBody: [],
			outputlist1: [],
			outputlist2: [],
			outputlist3: [],
			personalData: "",
			transBodyTransAdm: [],
			transReason: "",  														//原因
			transOrgCode: "", 														//机构代码
			transOrgDesc: "",														//机构名称
			transRecodeClass: "",   													//转诊登记类别
			transClass: "",       													//转诊类别
			transType: "1"															//转诊类型
		};
		// 添加分组table
		this.columns = [
			{
				title: '险种类型',
				dataIndex: 'aae140',
				key: '1',
				align: "center",
			},
			{
				title: '单位名称',
				dataIndex: 'aab004',
				key: '2',
				align: "center",
			},
			{
				title: '开始日期',
				dataIndex: 'aae030',
				key: '3',
				align: "center",
			},
			{
				title: '截止日期',
				dataIndex: 'aae031',
				key: '4',
				align: "center",
			},
			{
				title: '缴费人员类型',
				dataIndex: 'bcc334',
				key: '5',
				align: "center",
			},
			{
				title: '缴费状态',
				dataIndex: 'aac031',
				key: '6',
				align: "center",
			}
		]
	}

	componentDidMount() {
        this.props.onRef(this)
        this.setState({
			userInfo: this.props.userInfo
        }, () => {
            this.onSelectQuery()
		})
	}

	//数据显示
	onSelectQuery = () => {
		let data = {}
		data = {
			params: [{
				userID: JSON.parse(window.sessionStorage.userData).userID,
				hospID: JSON.parse(window.sessionStorage.userData).hospID,
				groupID: JSON.parse(window.sessionStorage.userData).groupID,
				locID: JSON.parse(window.sessionStorage.userData).locID,
				ybCardnumber: "",
				password: "",
				jobInJuryNumber: "",
				readCardData: "",
				personalData: this.state.userInfo,
				transType: "XX002"
			}]
		}
		$http.post('urls', this, {
			code: '05210038',
			data: data,
			success: function (res) {
				if (+res.errorCode === 0) {
					this.setState({ transBody: res.transBody, outputlist1: res.transBody.outputlist1, outputlist2: res.transBody.outputlist2, outputlist3: res.transBody.outputlist3, loading: false })
				} else {
					this.setState({ transBody: [], outputlist1: [], outputlist2: [], outputlist3: [], loading: false })
				}
			}
		})
	}


	//转诊
	onSelectTransAdm = () => {
		let data = {}
		this.readCard.PayByCard('', (json) => {
			console.log(json)
			if (json.errorCode === '0') {
				this.setState({
					personalData: json.value || ''
				}, () => {
					console.log(this.state.personalData)
				})
			} else {
				message.error(json.errorMessage)
				this.handleCancel()  // 关闭弹框
				return false
			}
		})
		data = {
			params: [{
				userID: JSON.parse(window.sessionStorage.userData).userID,									//收费员
				groupID: JSON.parse(window.sessionStorage.userData).groupID,								//登录安全组
				locID: JSON.parse(window.sessionStorage.userData).locID,									//登录科室
				hospID: JSON.parse(window.sessionStorage.userData).hospID,									//登录医院
				ip: JSON.parse(window.sessionStorage.userData).ip,											//IP
				ybCardnumber: "",																			//医疗证号（44位，像密码串那个）
				password: "",																				//密码
				transChannel: "10",																			//交易渠道 10= HIS刷卡, 20= 微信支付(wxpay), 21= 平安城市服务(pacity), 2A = 平安付(paf), 2B = 平安支付（papay）, 22 = 支付宝支付（alipay）, 23 = 建行(ccbpay), 24 = 银联(unionpay)
				icdCode: "待查",																				//诊断
				personalData: this.state.personalData,
				transReason: this.state.transReason,  														//原因
				transOrgCode: this.state.transOrgCode, 														//机构代码
				transOrgDesc: this.state.transOrgDesc,														//机构名称
				transRecodeClass: this.state.transRecodeClass,   											//转诊登记类别
				transClass: this.state.transClass,       													//转诊类别
				transType: this.state.transType																//转诊类型
			}]
		}
		$http.post('urls', this, {
			code: '05210039',
			data: data,
			success: function (res) {
				if (+res.errorCode === 0) {
					this.setState({ transBodyTransAdm: res.transBody, loading: false })
				} else {
					this.setState({ transBodyTransAdm: [], loading: false })
					message.error(res.errorMessage);
				}
			}
		})
	}

	// 转诊类别
	onChangetransClass = (e) => {
		this.setState({ transClass: e })
	}

	// 转诊原因
	onChangetransReason = (e) => {
		this.setState({ transReason: e.target.value })
	}

	// 转诊登记类别
	onChangetransRecodeClass = (e) => {
		this.setState({ transRecodeClass: e })
	}

	// 转诊机构编码
	onChangetransOrgCode = (e) => {
		this.setState({ transOrgCode: e.target.value })
	}

	// 转诊机构名称
	onChangetransOrgDesc = (e) => {
		this.setState({ transOrgDesc: e.target.value })
	}

	// 从外院到本院/从本院到外院
	onChangetransType = (e) => {
		this.setState({ transType: e.target.value })
	}

	render() {
		let { transBody, outputlist1, outputlist3 } = this.state
		return (
			<div style={{ widht: '100%' }}>
				<ReadCard ref={r => this.readCard = r} />
				<div>
					<Row>
						<Col span={2} style={{ marginTop: '35px', fontWeight: 'bold', textAlign: 'center' }} >基本信息</Col>
						<Col span={22}>
							<Row gutter={[10, 8]}>
								<Col span={8}>姓名：{transBody.aac003}</Col>
								<Col span={8}>性别：{transBody.aac004}</Col>
								<Col span={8}>出生日期：{transBody.aac006}</Col>
								<Col span={8}>身份证号码：{transBody.aac147}</Col>
								<Col span={8}>病人类型：</Col>
								<Col span={8}>电脑号：{transBody.aac999}</Col>
								<Col span={8}>个人编号：</Col>
								<Col span={8}>单位名称：</Col>
								<Col span={8}>账户余（元）：</Col>
							</Row>
						</Col>
					</Row>
				</div>
				<div style={{ widht: '100%', height: '10px', background: '#f0f2f5' }}></div>
				<div style={{ marginTop: '10px' }}>
					<Row>
						<Col span={2} style={{ marginTop: '110px', fontWeight: 'bold', textAlign: 'center' }}>医保信息</Col>
						<Col span={22}>
							<Row gutter={[10, 8]}>
								<Col span={8}>参保群体：{transBody.aac066}</Col>
								<Col span={8}>绑定社康：{transBody.akb021}</Col>
								<Col span={8}>绑定结算医院：{transBody.bkf267}</Col>
								<Col span={8}>家庭统筹医疗可用（元）：</Col>
								<Col span={8}>地补医保基金可用（元）：</Col>
								<Col span={8}>基本医疗基金可用（元）：</Col>
								<Col span={8}>社区门诊统筹可用（元）：</Col>
								<Col span={8}>重疾参保状态：{transBody.bke404}</Col>
								<Col span={22}>转诊单号：</Col>
								<Col span={22}>监护人信息：与参保人关系{outputlist1.aaa060},监护人姓名：{outputlist1.aac042},身份证号：{outputlist1.aac044}</Col>
								<Col span={22}>大病认定信息：大病类别：{outputlist3.cka303},业务年月：{outputlist3.aae002},已用次数：{outputlist3.cke291}，可用次数：{outputlist3.cke292}</Col>
							</Row>
						</Col>
					</Row>
				</div>
				<div style={{ widht: '100%', height: '10px', background: '#f0f2f5' }}></div>
				<div style={{ marginTop: '10px' }}>
					<Row>
						<Col span={2} style={{ marginTop: '60px', fontWeight: 'bold', textAlign: 'center' }}>转诊信息</Col>
						<Col span={22}>
							<Row gutter={[10, 8]}>
								<Col span={8}>转诊诊断：<Input className='Underline' value="待查" disabled /></Col>
								<Col span={8}>转诊原因：<Input className='Underline' value={this.state.transReason} onChange={this.onChangetransReason} /></Col>
								<Col span={8}>转诊机构编码：<Input className='Underline' value={this.state.transOrgCode} onChange={this.onChangetransOrgCode} /></Col>
								<Col span={8}>转入机构名称：<Input className='Underline' value={this.state.transOrgDesc} onChange={this.onChangetransOrgDesc} /></Col>
								<Col span={8}>
									转诊登记类别：
									<Select style={{ width: '150px', height: '30px' }} defaultValue="1" value={this.state.transRecodeClass} onChange={this.onChangetransRecodeClass}>
										<Option value="1">门诊</Option>
										<Option value="2">住院</Option>
									</Select>
								</Col>
								<Col span={8}>
									转诊类别：
									<Select style={{ width: '150px', height: '30px' }} defaultValue="1" value={this.state.transClass} onChange={this.onChangetransClass}>
										<Option value="1">市外转诊</Option>
										<Option value="3">结算医院内</Option>
										<Option value="4">结算医院内</Option>
									</Select>
								</Col>

								<Col span={24}>
									<Radio.Group onChange={this.onChangetransType} value={this.state.transType}>
										<Radio value="1">从外院转入到本院</Radio>
										<Radio value="2" >从本院转出到外院</Radio>
									</Radio.Group></Col>
								<Col span={2}><Button onClick={this.onSelectTransAdm}>转诊</Button></Col>
								<Col span={2}><Button>确定</Button></Col>
							</Row>
						</Col>
					</Row>
				</div>
				<div style={{ widht: '100%', height: '10px', background: '#f0f2f5' }}></div>
				<div style={{ marginTop: '10px' }}>
					<Row >
						<Col span={2} style={{ marginTop: '60px', fontWeight: 'bold', textAlign: 'center' }}>参保信息</Col>
						<Col span={22}>
							<Table columns={this.columns} bordered dataSource={this.state.outputlist2} className='tablevb' pagination={false} style={{ minHeight: '200px', height: '100px' }} />
						</Col>
					</Row>
				</div>
			</div >
		)
	}
}
