diff --git a/src/components/form/main.js b/src/components/form/main.js index 22c24090..15612f5b 100644 --- a/src/components/form/main.js +++ b/src/components/form/main.js @@ -1,10 +1,10 @@ -import React from 'react' -import './main.less' -import { Icon } from 'zent' -import _ from 'lodash' -import Menu from '../menu/main.js' -import ReactDom from 'react-dom' -import Bus from '../../assets/eventBus.js' +import React from "react" +import "./main.less" +import { Icon } from "zent" +import _ from "lodash" +import Menu from "../menu/main.js" +import ReactDom from "react-dom" +import Bus from "../../assets/eventBus.js" export default class form extends React.Component { constructor(props) { @@ -22,9 +22,9 @@ export default class form extends React.Component { this.setState({ rules: nextProps.rules }) } componentDidMount() { - Bus.addListener('change', (prop, e) => { + Bus.addListener("change", (prop, e) => { let dom = document.getElementById(prop) - let formCompontent = dom.getElementsByClassName('form-compontent') + let formCompontent = dom.getElementsByClassName("form-compontent") let rules_item = _.get(this.props.rules, prop) let item = formCompontent[0].firstChild @@ -33,7 +33,7 @@ export default class form extends React.Component { } else { setTimeout(() => { this.isRequired( - '', + "", item.className, formCompontent[0], rules_item[0].message @@ -43,9 +43,9 @@ export default class form extends React.Component { }) let self = this - Bus.addListener('input', (prop, e) => { + Bus.addListener("input", (prop, e) => { let dom = document.getElementById(prop) - let formCompontent = dom.getElementsByClassName('form-compontent') + let formCompontent = dom.getElementsByClassName("form-compontent") let rules_item = _.get(this.props.rules, prop) let item = formCompontent[0].firstChild if (!rules_item) { @@ -53,8 +53,8 @@ export default class form extends React.Component { } for (let j = 0; j < rules_item.length; j++) { - if (rules_item[j].type == 'required') { - if (e == '') { + if (rules_item[j].type == "required") { + if (e == "") { self.removeClass(formCompontent[0]) self.isRequired( e, @@ -68,7 +68,7 @@ export default class form extends React.Component { } } - if (rules_item[j].type == 'regExp') { + if (rules_item[j].type == "regExp") { var regu = rules_item[j].reg var re = new RegExp(regu) let s = e @@ -86,14 +86,14 @@ export default class form extends React.Component { } }) - Bus.addListener('close', (prop) => { + Bus.addListener("close", (prop) => { let dom = document.getElementById(prop) - let formCompontent = dom.getElementsByClassName('form-compontent') + let formCompontent = dom.getElementsByClassName("form-compontent") let rules_item = _.get(this.props.rules, prop) let item = formCompontent[0].firstChild setTimeout(() => { this.isRequired( - '', + "", item.className, formCompontent[0], rules_item[0].message @@ -102,7 +102,7 @@ export default class form extends React.Component { }) const dom = ReactDom.findDOMNode(this) - let doms = dom.getElementsByClassName('form-Item') + let doms = dom.getElementsByClassName("form-Item") let props_com = _.filter(this.props.children, (item) => { return item != null @@ -118,23 +118,23 @@ export default class form extends React.Component { if (_.isArray(formItem)) { } else { - let formItem_com = _.get(formItem, 'props.children.props') + let formItem_com = _.get(formItem, "props.children.props") - let input_compontent = com[1].children[0].getElementsByTagName('input') + let input_compontent = com[1].children[0].getElementsByTagName("input") if (input_compontent.length == 0) { - input_compontent = com[1].children[0].getElementsByTagName('textarea') + input_compontent = com[1].children[0].getElementsByTagName("textarea") } let o = com[1].children[0] - let rules_item = '' + let rules_item = "" if (formItem?.props?.prop) { rules_item = _.get(self.props.rules, formItem.props.prop) } if (input_compontent.length > 0 && rules_item) { input_compontent[0].oninput = function (e) { for (let j = 0; j < rules_item.length; j++) { - if (rules_item[j].type == 'required') { - if (e.target.value == '') { + if (rules_item[j].type == "required") { + if (e.target.value == "") { self.removeClass(item) if (formItem_com) { self.isRequired( @@ -150,7 +150,7 @@ export default class form extends React.Component { } } - if (rules_item[j].type == 'regExp') { + if (rules_item[j].type == "regExp") { var regu = rules_item[j].reg var re = new RegExp(regu) let s = e.target.value @@ -172,8 +172,8 @@ export default class form extends React.Component { input_compontent[0].onblur = function (e) { for (let j = 0; j < rules_item.length; j++) { - if (e.target.value == '') { - if (rules_item[j].type == 'required') { + if (e.target.value == "") { + if (rules_item[j].type == "required") { self.removeClass(item) if (formItem_com) { self.isRequired( @@ -185,7 +185,7 @@ export default class form extends React.Component { } } } else { - if (rules_item[j].type == 'regExp') { + if (rules_item[j].type == "regExp") { var regu = rules_item[j].reg var re = new RegExp(regu) let s = e.target.value @@ -213,40 +213,40 @@ export default class form extends React.Component { } removeClass(compontent) { var str = compontent.firstChild.className - let errors = compontent.getElementsByClassName('error-msg') + let errors = compontent.getElementsByClassName("error-msg") while (errors.length > 0) { errors[0].remove() } - let index = str.indexOf('error') + let index = str.indexOf("error") if (index > -1) { - compontent.firstChild.className = str.replace(' error', '') + compontent.firstChild.className = str.replace(" error", "") } } isRequired(value, className, compontent, message) { if ( - compontent.firstChild.className.indexOf('error') < 0 && - compontent.lastChild.className.indexOf('error-msg') < 0 + compontent.firstChild.className.indexOf("error") < 0 && + compontent.lastChild.className.indexOf("error-msg") < 0 ) { - var error = document.createElement('div') - error.className = 'error-msg' - error.innerHTML = '' + message + '' - compontent.firstChild.className += ' error' + var error = document.createElement("div") + error.className = "error-msg" + error.innerHTML = "" + message + "" + compontent.firstChild.className += " error" compontent.appendChild(error) } } componentDidUpdate(prevProps, prevState) { let formItem = this.props.children[0] - let com = _.get(formItem, 'props.children.props') + let com = _.get(formItem, "props.children.props") if (prevState.children != this.state.children) { } } cancel() { - let doms = document.getElementsByClassName('form-Item') + let doms = document.getElementsByClassName("form-Item") let self = this for (let i = 0; i < doms.length; i++) { var com = doms[i].children @@ -254,7 +254,7 @@ export default class form extends React.Component { let formItem = this.props.children[i] let o = com[1].children[0] //formItem对象 - let formItem_com = _.get(formItem, 'props.children.props') + let formItem_com = _.get(formItem, "props.children.props") //对应的验证规则 let rules_item = _.get(this.props.rules, formItem.props.prop) if (rules_item) { @@ -271,7 +271,7 @@ export default class form extends React.Component { validator() { const dom = ReactDom.findDOMNode(this) - let doms = dom.getElementsByClassName('form-Item') + let doms = dom.getElementsByClassName("form-Item") let self = this let validate = true @@ -298,14 +298,14 @@ export default class form extends React.Component { if (_.isArray(formItem)) { let op = 1 for (let k = 0; k < formItem.length; k++) { - let formItem_com = _.get(formItem[k], 'props.children.props') + let formItem_com = _.get(formItem[k], "props.children.props") //对应的验证规则 let rules_item = _.get(this.props.rules, formItem[k].props.prop) if (rules_item) { for (let j = 0; j < rules_item.length; j++) { - if (rules_item[j].type == 'required') { + if (rules_item[j].type == "required") { if ( - formItem_com.value == '' || + formItem_com.value == "" || formItem_com.value == undefined ) { self.removeClass(item) @@ -322,7 +322,7 @@ export default class form extends React.Component { } } - if (rules_item[j].type == 'regExp') { + if (rules_item[j].type == "regExp") { var regu = rules_item[j].reg var re = new RegExp(regu) let s = formItem_com.value @@ -344,28 +344,28 @@ export default class form extends React.Component { } } else { //formItem对象 - let formItem_com = _.get(formItem, 'props.children.props') + let formItem_com = _.get(formItem, "props.children.props") - if (formItem_com && formItem_com.hasOwnProperty('children')) { + if (formItem_com && formItem_com.hasOwnProperty("children")) { if (_.isArray(formItem_com.children)) { formItem_com = formItem_com.children[0].props } // } else { - let coms = _.get(formItem, 'props.children') + let coms = _.get(formItem, "props.children") if (coms && _.isArray(coms)) { formItem_com = coms[0].props } } //对应的验证规则 - let rules_item = _.get(this.props.rules, formItem.props.prop) + let rules_item = _.get(this.props.rules, formItem?.props?.prop) if (rules_item) { for (let j = 0; j < rules_item.length; j++) { - if (rules_item[j].type == 'required') { - if (formItem_com.value == '' || formItem_com.value == undefined) { - let node = item.getElementsByTagName('input') + if (rules_item[j].type == "required") { + if (formItem_com.value == "" || formItem_com.value == undefined) { + let node = item.getElementsByTagName("input") if (node && node.length > 0) { node[0].focus() } @@ -384,7 +384,7 @@ export default class form extends React.Component { } } - if (rules_item[j].type == 'regExp') { + if (rules_item[j].type == "regExp") { var regu = rules_item[j].reg var re = new RegExp(regu) let s = formItem_com.value diff --git a/src/pages/exchangecode/exchangecodeAdd/index.jsx b/src/pages/exchangecode/exchangecodeAdd/index.jsx index a10f4c01..e8e5bd9d 100644 --- a/src/pages/exchangecode/exchangecodeAdd/index.jsx +++ b/src/pages/exchangecode/exchangecodeAdd/index.jsx @@ -1193,7 +1193,7 @@ export default class exchangeAdd extends React.Component {
{this.state.codeInfo.issued}
- +
{this.state.codeInfo.stock}