import React, { Component } from 'react'; import { AutoComplete, Button, Form, Input, message, Modal, InputNumber, Select, Spin } from "antd"; import { getMaterialStatus, getUrgentStatus, } from '@/tools' import $ from "jquery"; const { Option } = Select const { TextArea } = Input const formItemLayout = { labelCol: { span: 8 }, wrapperCol: { span: 14 }, } class NewSupplier extends Component { constructor(props) { super(props); this.state = { thirdCompanyName: props.thirdCompanyName && props.thirdCompanyName.split('-')[0], thirdUnitPrice: props.thirdUnitPrice || 0, thirdQuantity: props.thirdQuantity || 0, thirdRemarks: props.thirdRemarks, thirdMaterial: props.thirdMaterial, thirdUrgent: props.thirdUrgent, patentType: props.patentType, audit: props.audit, assets: props.assets, income: props.income, customerArr: [], loading: false, officialCost: "", //是否有官费 costReduction: "", //是否有费减 } this.calculatedAmount = this.calculatedAmount.bind(this); } componentDidMount() { if (this.props.ThirdId) { this.supervisor(this.state.thirdCompanyName) } } //服务值改变时请求供应商名称 httpChange(e) { if (e.length >= 1) { this.supervisor(e) } this.props.otherOperations && this.props.otherOperations({ thirdMaterial: this.state.thirdMaterial, thirdUrgent: this.state.thirdUrgent, customerArr: this.state.customerArr, thirdCompanyName: e, }); this.setState({ thirdCompanyName: e, }) } //加载(自动补全) supervisor(e) { $.ajax({ method: 'get', dataType: 'json', crossDomain: false, url: globalConfig.context + '/api/admin/company/selectVague', data: { name: e, //0软著用 1其他用 2专利申请用 type: this.props.projectType === 2 ? 0 : (this.props.projectType === 1 && this.props.patentType === 0) ? 2 : 1 //this.props.projectType 0正常 1专利 2软著 3审计 this.props.patentType 0:专利申请/变更/转让 1:专利买卖 }, success: function (data) { let thedata = data.data if (!thedata) { if (data.error && data.error.length) { message.warning(data.error[0].message) } thedata = {} } this.setState({ customerArr: thedata, }) this.props.otherOperations && this.props.otherOperations({ thirdMaterial: this.state.thirdMaterial, thirdUrgent: this.state.thirdUrgent, customerArr: thedata, thirdCompanyName: this.state.thirdCompanyName, }); }.bind(this), }).always( function () { this.setState({ loading: false, }) }.bind(this) ) } // 第三方信息自动计算总金额 calculatedAmount() { let currentTotalPrice currentTotalPrice = (this.state.thirdQuantity * 1000000) * (this.state.thirdUnitPrice * 1000000) / 1000000 / 1000000 currentTotalPrice = currentTotalPrice.toFixed(4) this.setState({ currentTotalPrice: currentTotalPrice, }) } // 保存供应商信息 handleCancelq() { let api if (this.props.ThirdId) { //修改 api = '/api/admin/company/updateCompany' } else { //新增 api = '/api/admin/company/addCompany' } if (!this.state.thirdCompanyName) { message.warning('请输入供应商名称') return; } if (!this.state.thirdUnitPrice && this.props.projectType !== 2 && !(this.props.projectType === 1 && this.props.patentType === 0)) { message.warning('请输入正确的单价') return; } if (!this.state.thirdQuantity) { message.warning('请输入数量') return; } let customerId = 0; let isHave = this.state.customerArr.some((value) => { if (value.companyName === this.state.thirdCompanyName) { customerId = value.id return true; } }); //软著 必须要使用查询出来第三方名称和对应id if (!isHave && this.props.projectType === 2) { //projectType 0正常 1专利 2软著 3审计 message.warning('请输入正确的供应商名称') return; } //专利 必须要使用查询出来第三方名称和对应id if (!isHave && this.props.projectType === 1 && this.props.patentType === 0) { //projectType 0正常 1专利 2软著 3审计 patentType 0:专利申请/变更/转让 1:专利买卖 message.warning('请输入正确的供应商名称') return; } let data = { id: this.props.ThirdId, //id tid: this.props.tid, //订单编号 companyName: this.state.thirdCompanyName, //第三方名称 quantity: this.state.thirdQuantity, //数量 remarks: this.state.thirdRemarks, //备注 } if (isHave) { data.cid = customerId //公司id 只有软著类要传cid,其他类型都是非必填的 } if (this.props.projectType === 2) { data.material = this.state.thirdMaterial; //方案 data.urgent = this.state.thirdUrgent; //加急 data.calculation = 1; //0 其他 1软著 2专利 } else { //非软著类需要传总金额 data.totalAmount = (this.state.thirdQuantity * 1000000) * (this.state.thirdUnitPrice * 1000000) / 1000000 / 1000000; data.calculation = 0; //0 其他 1软著 2专利 } if (this.props.projectType === 1 && this.props.patentType === 0) { data.calculation = 2; //0 其他 1软著 2专利 } // data.type = this.props.realProjectType === 1 ? (this.props.patentType === 0 ? 1 : 2) : 0 //0其他 1专利申请 2专利买卖 if (this.props.realProjectType === 1) { //专利 data.patentType = this.props.patentType === 0 ? 0 : 1; //专利类型 data.patentNameType = this.props.patentNameType; //专利名称 } data.startType = this.props.startType; //项目类型 0外包 1供应商 if (this.props.projectType === 3) { if (!this.state.audit) { message.warning("请选择审计!"); return false; } if (!this.state.assets) { message.warning("请输入公司资产!"); return false; } if (!this.state.income) { message.warning("请输入收入!"); return false; } } //projectType 0正常 1专利 2软著 3审计 //软著不需要传 单价 if (this.props.projectType !== 2) { data.unitPrice = this.state.thirdUnitPrice; //单价 } if (this.props.projectType === 3) { //审计 data.assets = this.state.assets; //资产 data.audit = this.state.audit; //0无审计 1年审 2专审 data.income = this.state.income; //收入 } //已经发起的供应商项目新增第三方时需要传type=1 if (this.props.isLaunch && !this.props.ThirdId && this.props.startType === 1) { data.type = 1; //在发起供应商后,新增第三方需要加上type=1,因为在发起供应商会计算成本,这个新增的需要单独去计算 } this.setState({ loading: true, }) $.ajax({ url: globalConfig.context + api, method: 'post', dataType: 'json', crossDomain: false, data: data, }).done( function (data) { this.setState({ loading: false, }) if (!data.error.length) { message.success('保存成功!') this.setState({ thirdCompanyName: '', //第三方名称 thirdUnitPrice: 0, //单价 thirdQuantity: 0, //数量 currentTotalPrice: 0, //总价 thirdRemarks: '', thirdUrgent: 0, }) !!this.props.payNodeTable && this.props.payNodeTable(); this.props.onCancel(); } else { message.warning(data.error[0].message) } }.bind(this) ) } render() { return (
{/* projectType 0正常 1专利 2软著 3审计 patentType 0:专利申请/变更/转让 1:专利买卖 */} ( {group.companyName} ))} placeholder="请输入供应商名称" value={this.state.thirdCompanyName} onChange={(e) => { this.httpChange(e) }} filterOption={true} required="required" /> *
{/*projectType 0正常 1专利 2软著 3审计*/} {this.props.projectType !== 2 && !(this.props.projectType === 1 && this.props.patentType === 0) ?
{ this.setState({ thirdUnitPrice: value, }) }} dropdownStyle={{ width: 220 }} style={{ width: '220px', }} /> *
:
}
{ this.setState({ thirdQuantity: value, }) }} style={{ width: '220px' }} /> *
{/*专利 的专利申请 和 软著没有总价*/} {this.props.projectType !== 2 && this.props.patentType !== 0 ?
{ ((this.state.thirdQuantity || 0) * 1000000) * ((this.state.thirdUnitPrice || 0) * 1000000) / 1000000 / 1000000 }
:
} {this.props.projectType === 2 ?
*
*
:
} {/*{*/} {/* this.props.patentType === 0 ?
*/} {/*
*/} {/* */} {/* */} {/* **/} {/* */} {/* {*/} {/* this.setState({ officialCost: e.target.value });*/} {/* }}*/} {/* >*/} {/* 含官费*/} {/* 不含官费*/} {/* */} {/* */} {/*
*/} {/*
*/} {/* */} {/* */} {/* **/} {/* */} {/* {*/} {/* this.setState({ costReduction: e.target.value });*/} {/* }}*/} {/* >*/} {/* 有费减*/} {/* 无费减*/} {/* */} {/* */} {/*
*/} {/*
:
*/} {/*}*/} { this.props.projectType === 3 ?
*
{ this.setState({ assets: value, }) }} style={{ width: '220px' }} /> *
{ this.setState({ income: value, }) }} style={{ width: '220px' }} /> *
:
}