import React from 'react'; import {inject, observer} from 'mobx-react'; import {toJS} from 'mobx'; import {Button} from 'antd'; import {WeaSwitch} from 'comsMobx'; import { WeaTools, WeaFormItem, WeaSearchGroup, WeaRightMenu, WeaDialog, WeaNewScroll, WeaAlertPage, WeaLocaleProvider } from 'ecCom'; const getLabel = WeaLocaleProvider.getLabel; @inject('weesoRobotStore') @observer export default class WeesoRobotDialog extends React.Component { constructor (props) { super(props); this.state = { } } componentDidMount () { } getSearchs = (form, datas) => { const {isFormInit} = form; let group = []; const formParams = form.getFormParams(); isFormInit && datas && datas.map((c, _index) =>{ let items = []; c.items.map(fields => { items.push({ com:( ), colSpan:1, hide: form.isHide(fields, (keys, allParams) => { let bool = false; keys[0] === 'url' && allParams.showDiv === '1' && (bool = true); keys[0] === 'width' && allParams.showDiv === '0' && (bool = true); keys[0] === 'height' && allParams.showDiv === '0' && (bool = true); keys[0] === 'iframeUrl' && allParams.showDiv === '0' && (bool = true); return bool; }) }) }); group.push() }); return group; } getRightMenu() { let btnArr = [ { key: 'BTN_SAVE', icon: , content : `${getLabel(86,'保存')}`, onClick : () => this.doSave() } ] return btnArr; } trimSplace = (str) => { return typeof str === 'string' ? str.replace(/(^\s*) \ (\s*$)/g, '') : str; } doSave = () => { const {weesoRobotStore} = this.props; const {createForm, dialogStatus} = weesoRobotStore; let formParams = createForm && createForm.getFormParams(); const func = () => dialogStatus.createOrEdit == 0 ? weesoRobotStore.addRobot({...formParams}) : weesoRobotStore.editRobot({...formParams, id: dialogStatus.editId}); createForm && createForm.validateForm().then(f=>{ if(f.isValid){ func(); }else{ formParams.title = this.trimSplace(formParams.title); formParams.keywords = this.trimSplace(formParams.keywords); formParams.url = this.trimSplace(formParams.url); formParams.width = this.trimSplace(formParams.width); formParams.height = this.trimSplace(formParams.height); if(formParams.title !== '' && formParams.keywords !== '' && formParams.url !== '' && formParams.showDiv === '0'){ func(); }else if(formParams.title !== '' && formParams.keywords !== '' && formParams.iframeUrl !== '' && formParams.width !== '' && formParams.height!== '' && formParams.showDiv === '1'){ func(); }else { f.showErrors(); } } }); } render() { const {weesoRobotStore} = this.props; const {dialogStatus, createForm, status} = weesoRobotStore; const {collectParams} = toJS(status); const {showDialog, createFields, saveLoading} = toJS(dialogStatus); let title=getLabel(82832, '智能指令'); return ( { weesoRobotStore.setDialogState({showDialog : false}); createForm.reset(); }} buttons={[]} moreBtn={{ datas : this.getRightMenu(), collectParams : collectParams }} > {this.getSearchs(createForm, createFields)} ) } }