import {
	inject,
	observer,
} from 'mobx-react'
import {
	toJS
} from 'mobx'
import {
	WeaFormItem,
} from 'ecCom'
import {
	Spin,
} from 'antd'
import {
	WeaSwitch
} from 'comsMobx'

@inject('hrmWorkHour')
@observer
export default class SpecialForm extends React.Component {
	constructor(props) {
		super(props);
	}

	getForm() {
		const {
			hrmWorkHour
		} = this.props, {
			formInfo,
		} = hrmWorkHour, {
			form,
			conditions,
			selectedScopeValue,
			selectedNumberValue,
		} = formInfo, {
			isFormInit,
		} = form;

		let arr = [];
		isFormInit && conditions.map(c => {
			c.items.map((field, index) => {
				const key = field.domkey[0];
				if (selectedScopeValue == '3' && key == 'relatedId') {
					return
				}
				if (selectedNumberValue == '1' && key == 'signStartTime') {
					return
				}
				arr.push(<WeaFormItem ecId={`${this && this.props && this.props.ecId || ''}_WeaFormItem@mhcv9v@${index}`}
                            label={`${field.label}`}
                            labelCol={{span: 6, offset: 3}}
                            error={form.getError(field)}
                            tipPosition={'top'}
                            wrapperCol={{span: 12}}
                        >
                                <WeaSwitch ecId={`${this && this.props && this.props.ecId || ''}_WeaSwitch@oe2u2p@${index}`} fieldConfig={field} form={form} formParams={form.getFormParams()} onChange={callbackInfo => this.handleChange(callbackInfo)}/>
                        </WeaFormItem>)
			})
		})
		return <div className='wea-form-item-group'>{arr}</div>
	}

	handleChange = (callbackInfo) => {
		const {
			hrmWorkHour
		} = this.props, {
			exportSelectedValue,
			changeSignForm,
			mainDialog,
			formInfo,
		} = hrmWorkHour, {
			contentType
		} = mainDialog;

		if (Object.keys(callbackInfo)[0] == 'scheduleType') {
			const val = callbackInfo.scheduleType.value;
			exportSelectedValue(val, 'scope');
			contentType == 'edit' && changeSignForm();

			val == '3' && formInfo.form.updateFields({
				relatedId: {
					value: '',
				}
			});
		}
		if (Object.keys(callbackInfo)[0] == 'signType') {
			exportSelectedValue(callbackInfo.signType.value, 'number')
		}
		if (Object.keys(callbackInfo)[0] == 'signStartTime') {
			exportSelectedValue(callbackInfo.signStartTime.value, 'time')
		}
	}

	render() {
		const {
			hrmWorkHour
		} = this.props, {
			formInfo,
			date,
		} = hrmWorkHour, {
			loading,
		} = formInfo;

		return this.getForm()

	}
}