import React,{Component} from "react"; import {AutoComplete, Button, Form, Input, message, Modal, Radio, Select, Spin} from "antd"; import {boutique} from "../../dataDic"; import $ from "jquery"; import {getboutique} from "../../tools"; const FormItem = Form.Item; const formItemLayout = { labelCol: { span: 8 }, wrapperCol: { span: 14 }, }; class ProjectOperation extends Component{ constructor(props) { super(props); this.state={ commodityName:'', commodityQuantity:'', patentType:0, officialCost:'', costReduction:'', commodityPrice:'', main:'', taskComment:'', declarationBatch:'', ifCertificationFee:'', displayFees: "none", customerArr:[], patentTypeList:[], loading:false, patentTransfer:props.dataInfor.patentTransfer } this.onSubmit = this.onSubmit.bind(this); this.httpChange = this.httpChange.bind(this); this.selectAuto = this.selectAuto.bind(this); this.getpatentTypeList = this.getpatentTypeList.bind(this); this.setValue = this.setValue.bind(this); } componentDidMount() { this.getpatentTypeList(); this.setValue(); } setValue(){ const {dataInfor} = this.props; if(!(dataInfor && Object.keys(dataInfor).length > 0)){return;} if (dataInfor.type === 1){ this.setState({ displayFees: "block", costReduction: dataInfor.costReduction, officialCost: dataInfor.officialCost, patentType: dataInfor.patentType ? dataInfor.patentType : 0, }); }else{ this.setState({ displayFees: "none", }); } this.setState({ jid: dataInfor.id, //项目ID kid: dataInfor.commodityId, //商品ID commodityName: dataInfor.commodityName, //项目名称 commodityPrice: dataInfor.commodityPrice, //金额 commodityQuantity: dataInfor.commodityQuantity, //数量 patentTypeName:dataInfor.patentTypeName,//专利类型名称 taskComment: dataInfor.taskComment, //备注 main: dataInfor.main.toString(), //是否为主要 addState: 0, addnextVisible: true, addProjectType: dataInfor.type, declarationBatch: dataInfor.declarationBatch || 1,//申报批次(只有高新有) ifCertificationFee: isNaN(parseInt(dataInfor.ifCertificationFee)) ? '' : dataInfor.ifCertificationFee,//是否包含认证费 isIso: dataInfor.commodityName.indexOf("贯标") !== -1, }); } onSubmit(){ if (this.state.gid === undefined || !this.state.gid) { message.warning("服务名称不匹配!"); return false; } if (this.state.displayFees==='block') { if (this.state.patentType === "" && !this.state.patentTransfer) { message.warning("请选择专利类型!"); return false; } if(this.state.officialCost===''){ message.warning("请选择官费!"); return false; } if (this.state.costReduction === "" && (this.state.patentType === 0 || this.state.patentType === 2) && this.state.officialCost === 1) { message.warning("请选择费减!"); return false; } } if(isNaN(parseFloat(this.state.commodityPrice))){ message.warning("请输入正确的金额!"); return false; } let reg = /^([0]|[1-9][0-9]*)$/; if ( !this.state.commodityQuantity || !reg.test(this.state.commodityQuantity) ) { message.warning("请输入正确商品数量!"); return false; } if (!this.state.main) { message.warning("请选择是否为主要项目!"); return false; } if(this.state.addProjectType === 5 && !this.state.declarationBatch){ message.warning("请选择企业要求申报批次!"); return false; } if(this.state.isIso && !this.state.ifCertificationFee){ message.warning("请选择是否包含认证费用!"); return false; } this.setState({ loading: true, }); let infor = { commodityId: this.state.gid, //商品ID orderNo: this.props.orderNo, //订单编号 commodityName: this.state.commodityName, //商品名称 commodityQuantity: this.state.commodityQuantity, //商品数量 commodityPrice: this.state.commodityPrice, //签单总价 taskComment: this.state.taskComment, //服务说明 main: this.state.main, //是否为主要项目 officialCost: this.state.displayFees==='block' ? this.state.officialCost : '', //是否有官费 costReduction: this.state.displayFees==='block' ? ((this.state.patentType === 0 || this.state.patentType === 2) ? (this.state.officialCost === 1 ? this.state.costReduction : 0) : 0) : '', //是否有费减 patentType: this.state.displayFees==='block' && !this.state.patentTransfer ? this.state.patentType : undefined, // 专利类型 } if(this.state.addProjectType === 5){ infor.declarationBatch = this.state.declarationBatch || 1//申报批次 } if(this.state.isIso){ infor.ifCertificationFee = this.state.ifCertificationFee || undefined;//是否包含认证费用 } $.ajax({ method: "POST", dataType: "json", crossDomain: false, url: globalConfig.context + "/api/admin/newOrder/addOrderTask", data: infor, }).done( function (data) { this.setState({ loading: false, }); if (!data.error.length) { message.success("保存成功!"); this.props.onCancel(); } else { message.warning(data.error[0].message); } }.bind(this) ); } onChange() { if(isNaN(parseFloat(this.state.commodityPrice))){ message.warning("请输入正确的金额!"); return false; } let reg = /^([0]|[1-9][0-9]*)$/; if ( !this.state.commodityQuantity || !reg.test(this.state.commodityQuantity) ) { message.warning("请输入正确商品数量!"); return false; } if (!this.state.main) { message.warning("请选择是否为主要项目!"); return false; } this.setState({ loading: true, }); $.ajax({ method: "POST", dataType: "json", crossDomain: false, url: globalConfig.context + "/api/admin/newOrder/updateOrderTask", data: { id: this.state.jid, //项目ID commodityId: this.state.kid, //商品ID orderNo: this.props.orderNo, //订单编号 main: this.state.main, //是否为主要 commodityPrice: this.state.commodityPrice, //金额 commodityQuantity: this.state.commodityQuantity, //数量 taskComment: this.state.taskComment, //备注 officialCost: this.state.displayFees==='block' ? this.state.officialCost : '', //是否有官费 costReduction: this.state.displayFees==='block' ? ((this.state.patentType === 0 || this.state.patentType === 2) ? (this.state.officialCost === 1 ? this.state.costReduction : 0) : 0) : '', //是否有费减 patentType: this.state.displayFees==='block' ? this.state.patentType : '', //专利类型 declarationBatch: this.state.declarationBatch || undefined,//申报批次 ifCertificationFee: isNaN(parseInt(this.state.ifCertificationFee)) ? undefined : this.state.ifCertificationFee, }, }).done( function (data) { this.setState({ loading: false, }); if (!data.error.length) { message.success("保存成功!"); this.props.onCancel(); } else { message.warning(data.error[0].message); } }.bind(this) ); } httpChange(e) { this.setState({ commodityName: e, }); if (e.length >= 1) { this.supervisor(e, false); } } //加载(自动补全) supervisor(e, state) { //客户名称与服务名称自动补全 let api = state ? "/api/admin/customer/getCustomerByName" : "/api/admin/order/getBusinessProjectByName"; $.ajax({ method: "get", dataType: "json", crossDomain: false, url: globalConfig.context + api, data: state ? { name: e, type: this.state.customType, } : { businessName: e, }, success: function (data) { let thedata = data.data; if (!thedata) { if (data.error && data.error.length) { message.warning(data.error[0].message); } thedata = {}; } this.setState({ states: state, customerArr: thedata, }); }.bind(this), }).always( function () { }.bind(this) ); } //上级主管输入框失去焦点是判断客户是否存在 selectAuto(value) { let kid = {}; let fwList = this.state.customerArr; fwList.map(function (item) { if (value == item.bname) { kid = item; } }); if (kid.type == "1") { this.setState({ displayFees: "block", patentTransfer: kid.patentTransfer, }); } else { this.setState({ displayFees: "none", }); } console.log(value.indexOf("贯标"),'value.indexOf("贯标")') //0通用 1专利 2软著 3审计 4双软 5高新 6商标 this.setState({ commodityName: value, gid: kid.id, addProjectType: kid.type, isIso: value.indexOf("贯标") !== -1,// 是否为贯标项目 }); } getpatentTypeList() { $.ajax({ method: "get", dataType: "json", crossDomain: false, url: globalConfig.context + '/api/admin/orderProject/getPatentType', success: function (data) { if (data.error.length === 0) { this.setState({ patentTypeList:data.data }) }else{ message.warning(data.error[0].message); }; }.bind(this) }); } render() { let options = this.state.states ? this.state.customerArr.map((group) => ( {group.name} )) : this.state.customerArr.map((group, index) => ( {group.bname} )); const {readOnly} = this.props; return ( {this.state.jid ? this.state.commodityName : } * {readOnly ? this.state.commodityQuantity : { this.setState({ commodityQuantity: e.target.value }); }} ref="commodityQuantity" />} * {!this.state.patentTransfer && {readOnly ? this.state.patentTypeName : { this.setState({ patentType: e }); if(e !== 0 && e !== 2){ this.setState({ costReduction: '' }) } }} > {this.state.patentTypeList.map(function (v,k) { return ( {v.name} ); })} } * } {readOnly ? (this.state.officialCost === 1 ? '含官费': this.state.officialCost === 0 ? '不含官费' : '') : { this.setState({ officialCost: e.target.value }); if(e.target.value === 0){ this.setState({ costReduction: '' }) } }} > 含官费 不含官费 } * {/*不含官费或者专利类型不为复审或者申请时置灰*/} {readOnly ? (this.state.costReduction === 1 ? '有费减': this.state.costReduction === 0 ? '无费减' : '') : { this.setState({ costReduction: e.target.value }); }} > 有费减 无费减 } * {readOnly ? this.state.commodityPrice : { this.setState({ commodityPrice: e.target.value }); }} ref="commodityPrice" />} * {readOnly ? getboutique(this.state.main) : { this.setState({ main: e }); }} > {boutique.map(function (item) { return ( {item.key} ); })} } * {readOnly ? this.state.taskComment : { this.setState({ taskComment: e.target.value }); }} />} {/*0通用 1专利 2软著 3审计 4双软 5高新 6商标*/} {this.state.addProjectType === 5 ? {readOnly ? ( this.state.declarationBatch === 1 ? '第一批' : this.state.declarationBatch === 2 ? '第二批' : this.state.declarationBatch === 3 ? '第三批' : this.state.declarationBatch === 4 ? '第四批' : '未知' ) : { this.setState({ declarationBatch: e }); }} > 第一批 第二批 第三批 第四批 } * : null } { this.props.isIso || this.state.isIso? {readOnly ? ( this.state.ifCertificationFee === 1 ? '包含' : this.state.ifCertificationFee === 0 ? '不包含' :'未知' ) : { this.setState({ ifCertificationFee: e }); }} > 否 是 } * : null } {readOnly ? null : { if(this.state.jid){ this.onChange(); }else{ this.onSubmit(); } }} > 保存 取消 } ) } } export default ProjectOperation;