/**
 * 添加医保目录
 */

import React from 'react';
import {
	Form, Row, Col, Input, Select, Drawer, Switch, Upload, Button, Icon, message, Collapse, Modal
} from 'antd';
import { $http } from 'containers/config/https';

// 组件const
const { Option } = Select;
class AddMedicalInsuranceDirectory extends React.Component {
	constructor(props) {
		super(props)
		this.state = {
			visible: false,
		}
	}
	componentDidMount() {
		this.props.onRef(this);
		this.loadProconfigure()
	}
	componentWillUnmount() {
		this.setState = (state, callback) => {
			return
		}
	}
	// 保存配置信息
	handleSubmit = (e) => {
		e.preventDefault();
		let user = window.sessionStorage.userData ? JSON.parse(window.sessionStorage.userData) : {};
		this.props.form.validateFields((err, values) => {
			if (!err) {  //!err
				let data = {
					"params": [{
						ID: this.props.configInfo.ID || '',
						userID: user.userID,    //用户ID
						yBAreaID: values.yBAreaID || '',  //医保地域
						provinceCode: values.provinceCode || '',     //省项目编码
						insuCode: values.insuCode || '',     //社保目录编码
						insuDesc: values.insuDesc || '',    //社保目录名称
						catalogCategory: values.catalogCategory || '',  //  目录类别
						classCode: values.classCode || '', //分类编码
						generic: values.generic || '',    // 通用名
						bitCode: values.bitCode || '',      //  药品本位码
						englishName: values.englishName || '', //英文名称
						alias: values.alias || '',    //别名
						pinyinCode: values.pinyinCode || '',   // 拼音简码
						largeCode: values.largeCode || '',     //大类代码
						jZChannel: values.jZChannel || '',   //记账途径
						specifications: values.specifications,   //规格
						unit: values.unit || '',  //计价单位
						unitTime: values.unitTime || '',   //单位时间
						formulation: values.formulation || '',         //剂型
						itemGrade: values.itemGrade || '',  //收费项目等级
						accountingMark: values.accountingMark || '',   //记账标志
						drugsClass: values.drugsClass || '',   //药品类别
						prescriptionLogo: values.prescriptionLogo === true ? "1" : "0",  //处方药标志
						additionalSign: values.additionalSign || '',   //加收项目标识
						projectConnotation: values.projectConnotation || '',  //项目内涵
						exceptions: values.exceptions || '',  //除外内容
						selfPercent: values.selfPercent || '', //自付比例
						outSelfPercent: values.outSelfPercent || '', //门诊自付比例
						hosSelfPercent: values.hosSelfPercent || '', //住院自付比例
						maxPrice: values.maxPrice || ''		//最高限价
					}]
				};
				// console.log(this.data);
				$http.post('urlADS', this, {
					code: "05100293",
					data: data,
					success: function (res) {
						let errorCode = res.errorCode;
						if (errorCode === '0') {
							message.success("保存成功!");
							this.onClose();
							this.props.handelThis.handleQuery();
						}
					}
				});
			}
		});
	}

	// 关闭抽屉
	onClose = () => {
		this.setState({
			visible: false,
		}, () => {
			// 如果为编辑，则关闭后清除表单
			this.props.handelThis.resetConfigInfo();
			this.resetFields()

		});
	};
	// 打开抽屉
	showDrawer = () => {
		this.setState({
			visible: true,
		});
	};

	// 重置表单
	resetFields() {
		this.props.form.resetFields();
	}

	//获取医保地域
	loadProconfigure() {
		var params = {
			params: [{}]
		}
		$http.post('urlDeault', this, {
			code: "05100291",
			data: params,
			success: function (res) {
				if (res.errorCode == '0') {
					this.setState({
						ProconfigureArr: res.data,
					})
				}
			}
		});
	}

	render() {
		const { getFieldDecorator } = this.props.form;
		let configInfo = this.props.configInfo ? this.props.configInfo : {};
		//医保地域
		let ProconfigureOption = []
		this.state.ProconfigureArr && this.state.ProconfigureArr.map(item => {
			ProconfigureOption.push(<Option key={item.id} value={item.id}>{item.descripts}</Option>)
		})
		return (
			<Drawer
				title={this.props.title + "医保目录"}
				width={720}
				onClose={this.onClose}
				visible={this.state.visible}
				style={{
					overflow: 'auto',
					height: 'calc(100% - 108px)',
					paddingBottom: '108px',
				}}
			>
				<Form layout="vertical" onSubmit={this.handleSubmit}  >
					{/* 第一行 */}
					<Row>
						<Col span={7}>
							<Form.Item label="医保地域">
								{getFieldDecorator('yBAreaID', {
									initialValue: configInfo.yBAreaID,
									rules: [{ required: true }]
								})(
									<Select
										allowClear={true}
										placeholder="请选择医保地域" >
										{ProconfigureOption}
									</Select>
								)}
							</Form.Item>
						</Col>
						<Col span={7} offset={1}>
							<Form.Item label="省项目编码">
								{getFieldDecorator('provinceCode', {
									initialValue: configInfo.provinceCode,
									rules: [{ required: true, message: '请输入项目编码' }]
								})(
									<Input placeholder="请输入项目编码" className='input' />
								)}
							</Form.Item>
						</Col>
						<Col span={7} offset={1}>
							<Form.Item label="社保目录编码">
								{getFieldDecorator('insuCode', {
									initialValue: configInfo.insuCode,
									rules: [{ required: true, message: '请输入社保目录编码' }],
								})(
									<Input placeholder="请输入社保目录编码" className='input' />
								)}
							</Form.Item>
						</Col>
					</Row>
					{/* 第二行 */}
					<Row>
						<Col span={7} >
							<Form.Item label="社保目录名称">
								{getFieldDecorator('insuDesc', {
									initialValue: configInfo.insuDesc,
									rules: [{ required: true, message: '请输入社保目录名称' }],
								})(
									<Input placeholder="请输入社保目录名称" className='input' />
								)}
							</Form.Item>
						</Col>
						<Col span={7} offset={1}>
							<Form.Item label="目录类别">
								{getFieldDecorator('catalogCategory', {
									initialValue: configInfo.catalogCategory,
								})(
									<Input placeholder="请输入目录类别" className='input' />
								)}
							</Form.Item>
						</Col>
						<Col span={7} offset={1}>
							<Form.Item label="分类编码">
								{getFieldDecorator('classCode', {
									initialValue: configInfo.classCode,
								})(
									<Input placeholder="请输入分类编码" className='input' />
								)}
							</Form.Item>
						</Col>
					</Row>
					{/* 第三行 */}
					<Row>
						<Col span={7}  >
							<Form.Item label="通用名">
								{getFieldDecorator('generic', {
									initialValue: configInfo.generic,
								})(
									<Input placeholder="请输入通用名" className='input' />
								)}
							</Form.Item>
						</Col>
						<Col span={7} offset={1}>
							<Form.Item label="药品本位码">
								{getFieldDecorator('bitCode', {
									initialValue: configInfo.bitCode,
									rules: [{ required: true, message: '请输入药品本位码' }],
								})(
									<Input placeholder="请输入药品本位码" className='input' />
								)}
							</Form.Item>
						</Col>
						<Col span={7} offset={1}>
							<Form.Item label="英文名称">
								{getFieldDecorator('englishName', {
									initialValue: configInfo.englishName
								})(
									<Input placeholder="请输入英文名称" className='input' />
								)}
							</Form.Item>
						</Col>
					</Row>
					{/* 第四行 */}
					<Row>
						<Col span={7}  >
							<Form.Item label="别名（简称）">
								{getFieldDecorator('Alias', {
									initialValue: configInfo.alias,
								})(
									<Input placeholder="请输入别名（简称）" className='input' />
								)}
							</Form.Item>
						</Col>
						<Col span={7} offset={1}>
							<Form.Item label="拼音简码">
								{getFieldDecorator('pinyinCode', {
									initialValue: configInfo.pinyinCode,
								})(
									<Input placeholder="请输入拼音简码" className='input' />
								)}
							</Form.Item>
						</Col>
						<Col span={7} offset={1}>
							<Form.Item label="大类代码">
								{getFieldDecorator('largeCode', {
									initialValue: configInfo.largeCode,
								})(
									<Input placeholder="请输入大类代码" className='input' />
								)}
							</Form.Item>
						</Col>
					</Row>
					{/* 第五行 */}
					<Row>
						<Col span={7} >
							<Form.Item label="记账途径">
								{getFieldDecorator('jZChannel', {
									initialValue: configInfo.jZChannel,
								})(
									<Input placeholder="请输入记账途径" className='input' />
								)}
							</Form.Item>
						</Col>
						<Col span={7} offset={1}>
							<Form.Item label="规格">
								{getFieldDecorator('specifications', {
									initialValue: configInfo.specifications,
								})(
									<Input placeholder="请输入规格" className='input' />
								)}
							</Form.Item>
						</Col>
						<Col span={7} offset={1}>
							<Form.Item label="计价单位">
								{getFieldDecorator('unit', {
									initialValue: configInfo.unit,
								})(
									<Input placeholder="请输入计价单位" className='input' />
								)}
							</Form.Item>
						</Col>
					</Row>
					{/* 第六行 */}
					<Row>
						<Col span={7} >
							<Form.Item label="单位时间">
								{getFieldDecorator('unitTime', {
									initialValue: configInfo.unitTime,
								})(
									<Input placeholder="请输入单位时间" className='input' />
								)}
							</Form.Item>
						</Col>
						<Col span={7} offset={1}>
							<Form.Item label="剂型">
								{getFieldDecorator('formulation', {
									initialValue: configInfo.formulation,
								})(
									<Input placeholder="请输入剂型" className='input' />
								)}
							</Form.Item>
						</Col>
						<Col span={7} offset={1}>
							<Form.Item label="收费项目等级">
								{getFieldDecorator('itemGrade', {
									initialValue: configInfo.itemGrade,
								})(
									<Input placeholder="收费项目等级" className='input' />
								)}
							</Form.Item>
						</Col>
					</Row>
					{/* 第七行 */}
					<Row>
						<Col span={7}>
							<Form.Item label="记账标志">
								{getFieldDecorator('accountingMark', {
									initialValue: configInfo.accountingMark,
								})(
									<Input placeholder="请输入记账标志" className='input' />
								)}
							</Form.Item>
						</Col>
						<Col span={7} offset={1}>
							<Form.Item label="药品类别">
								{getFieldDecorator('drugsClass', {
									initialValue: configInfo.drugsClass,
								})(
									<Input placeholder="请输入药品类别" className='input' />
								)}
							</Form.Item>
						</Col>
						<Col span={7} offset={1}>
							<Form.Item label="处方药标志">
								{getFieldDecorator('prescriptionLogo', {
									valuePropName: 'checked',
									initialValue: configInfo.prescriptionLogo === "1" ? true : false,
								})(
									<Switch checkedChildren="是" unCheckedChildren="否" className='input' />
								)}
							</Form.Item>
						</Col>
					</Row>
					{/* 第八行 */}
					<Row>
						<Col span={7} >
							<Form.Item label="加收项目标识">
								{getFieldDecorator('additionalSign', {
									initialValue: configInfo.additionalSign,
								})(
									<Input placeholder="加收项目标识" className='input' />
								)}
							</Form.Item>
						</Col>
						<Col span={7} offset={1}>
							<Form.Item label="项目内涵">
								{getFieldDecorator('projectConnotation', {
									initialValue: configInfo.projectConnotation,
								})(
									<Input placeholder="项目内涵" className='input' />
								)}
							</Form.Item>
						</Col>
						<Col span={7} offset={1}>
							<Form.Item label="除外内容">
								{getFieldDecorator('exceptions', {
									initialValue: configInfo.exceptions,
								})(
									<Input placeholder="除外内容" className='input' />
								)}
							</Form.Item>
						</Col>
					</Row>

					{/* 第九行 */}
					<Row>
						<Col span={7} >
							<Form.Item label="自付比例">
								{getFieldDecorator('selfPercent', {
									initialValue: configInfo?.selfPercent,
								})(
									<Input placeholder="自付比例" className='input' />
								)}
							</Form.Item>
						</Col>
						<Col span={7} offset={1}>
							<Form.Item label="门诊自付比例">
								{getFieldDecorator('outSelfPercent', {
									initialValue: configInfo?.outSelfPercent,
								})(
									<Input placeholder="门诊自付比例" className='input' />
								)}
							</Form.Item>
						</Col>
						<Col span={7} offset={1}>
							<Form.Item label="住院自付比例">
								{getFieldDecorator('hosSelfPercent', {
									initialValue: configInfo?.hosSelfPercent,
								})(
									<Input placeholder="住院自付比例" className='input' />
								)}
							</Form.Item>
						</Col>
					</Row>

					{/* 第十行 */}
					<Row>
						<Col span={7} >
							<Form.Item label="最高限价">
								{getFieldDecorator('maxPrice', {
									initialValue: configInfo?.maxPrice,
								})(
									<Input placeholder="最高限价" className='input' />
								)}
							</Form.Item>
						</Col>
					</Row>


					<Row style={{ width: '100%', textAlign: 'center', marginTop: "30px" }}>
						<Button onClick={this.handleSubmit.bind(this)} style={{ marginRight: '15px', background: 'rgba(66,185,131,1)', color: '#fff' }}>保存</Button>
					</Row>
				</Form>
			</Drawer>
		)

	}
}
const AddMedicalInsuranceDirectoryFrom = Form.create()(AddMedicalInsuranceDirectory);

export default AddMedicalInsuranceDirectoryFrom;
