import React from 'react'; import {Input} from 'semantic-ui-react'; import {getRequest} from '../../../../../actions'; class UnitLeone extends React.Component { state = { list: [], data: { id: '', op: '', mode: '', value: '' } } componentDidMount(){ let {showDialog, toggleLoading} = this.props; toggleLoading(1); fetch('/api/system/getselectlist', getRequest({type: 'leone'})) .then(response=>response.json()) .then(json=>{ toggleLoading(0); if(json.status != 1) return showDialog(json.message); this.setState({ list: json.data.record || [] }) }) } componentWillReceiveProps(np) { let data = {...this.state.data}; if(np.data.op != data.op) data.op = np.data.op; if(np.data.value != data.value) data.value = np.data.op; let id = np.data.id.split(',')[0]; let mode = np.data.id.split(',')[1]; if(id != data.id) data.id = id; if(mode != data.mode) data.mode = mode; this.setState({ data: {...data} }) } changeState = (key, value) => { let data = { ...this.state.data } if(key == 'dev') { data.id = value == '' ? '' : `le${value}`; } if(key == 'mode'){ data.mode = value; } if(key == 'op'){ data.op = value; } if(key == 'value') { data.value = value; } this.setState({ data: {...data} }, ()=>{ this.sendUpdate() }); } sendUpdate = () => { let data = {...this.state.data}; data.id = `${data.id},${data.mode}`; delete data.mode; this.props.updateData({...this.props.data, ...data}); } render() { let {ops} = this.props; let id = ''; if(this.state.data.id != '') { let m = this.state.data.id.match(/(\d+)/); if(m != null && m.length > 1){ id = m[1]; } } return (
{this.changeState('value', d.value)}} />
) } } export default UnitLeone;