import React,{Component} from 'react'; import {Button, DatePicker, Form, Input, message, Modal, Select, Spin, InputNumber} from "antd"; import { cuiJieDian } from '@/dataDic.js' import moment from "moment"; import PropTypes from 'prop-types'; import $ from "jquery"; const formItemLayout = { labelCol: { span: 8 }, wrapperCol: { span: 14 }, } class OperationPayNode extends Component{ constructor(props) { super(props); this.state={ loading: false, thirdCompanyName: '', //供应商名称 paySubject: [], paySubjectName: '', //可简化 } } componentDidMount() { this.getCsortData() } //保存付款节点 savePayNode() { let api if (this.props.thirdId) { //修改 api = '/api/admin/company/updatePaymentNode' } else { //新增 api = '/api/admin/company/addPaymentNode' } let customerId=0; this.props.supplierList.some((value)=>{ if(value.companyName === this.state.thirdCompanyName){ customerId = value.id return true; } }); if(!this.state.thirdCompanyName){ message.error('请选择供应商名称'); return; } if(!this.state.paySubjectName){ message.error('请选择付款科目'); return; } if(!this.state.payNodeQuantity){ message.error('请输入数量'); return; } let data = { id: this.props.thirdId, //id tid: this.state.tid, //订单编号 cid: customerId,//对应的第三方信息 companyName: this.state.thirdCompanyName.split('-')[0], //第三方名称 quantity: this.state.payNodeQuantity, //数量 dunType: this.state.dunType, //催款节点 projectType: this.state.cSort, //项目分类 } if(this.state.paySubjectName === '0'){ if(!this.state.partyTimes){ message.error('请选择付款时间'); return; } data.partyTimes = this.state.partyTimes //付款时间 } if(this.props.projectType !== 2){ //其他类型 0正常 1专利 2软著 3审计 data.totalAmount = this.state.currentTotalPrice //总价 data.unitPrice = this.state.thirdUnitPrice //单价 } 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.props.onCancel(); } else { message.warning(data.error[0].message) } }.bind(this) ) } // 付款节点自动计算总金额 payNodeCalculatedAmount(num) { let currentTotalPrice,quantity,unitPrice; //获取当前供应商名称对应的单价并更新 this.props.thirdInfoList.forEach((item) => { if (item.companyName === this.state.thirdCompanyName) { currentTotalPrice = num ? item.unitPrice * num : item.quantity * item.unitPrice; currentTotalPrice = currentTotalPrice.toFixed(6); quantity = num ? num : item.quantity; unitPrice = item.unitPrice; } }) this.props.from.setFieldsValue({ quantity :num ? num : quantity }) if(this.props.projectType !== 2){ this.setState({ currentTotalPrice: currentTotalPrice, thirdUnitPrice: unitPrice }) } } // 获取csort下的数据 getCsortData() { cuiJieDian.map((item) => { if (item.value == localStorage.getItem('cSort')) { this.setState({ paySubject: item.children, }) } }) } render() { const { getFieldDecorator } = this.props.form; const { payNodeInfor } = this.props; return (
{getFieldDecorator('companyName', { initialValue: payNodeInfor.companyName, rules: [{ required: true, message: '请选择供应商' }], })( )}
{getFieldDecorator('dunType', { initialValue: payNodeInfor.dunType, rules: [{ required: true, message: '请选择付款科目' }], })( )}
{parseInt(this.state.paySubjectName) === 0 ? {getFieldDecorator('partyTimes', { initialValue: payNodeInfor.partyTimes, rules: [{ required: true, message: '请选择付款时间' }], })( { // this.setState({ partyTimes: dataString }) // }} style={{ width: '220px' }} /> )} :
}
{getFieldDecorator('quantity', { initialValue: payNodeInfor.quantity, rules: [{ required: true, message: '请输入数量' }], })( { this.payNodeCalculatedAmount(e) }} style={{ width: '220px' }} /> )}
{this.props.projectType !== 2 ?
{getFieldDecorator('quantity', { initialValue: payNodeInfor.quantity, rules: [{ required: true, message: '请输入数量' }], })( this.setState({ currentTotalPrice: e.target.value, }) } style={{ width: '220px' }} /> )}
:
}
) } } OperationPayNode.propTypes = { visible : PropTypes.bool.isRequired, //控制组件是否显示 onCancel : PropTypes.func.isRequired, //取消方法 thirdId : PropTypes.number.isRequired, //供应商ID thirdInfoList: PropTypes.array.isRequired, //第三方信息列表 supplierList: PropTypes.array.isRequired, //第三方信息列表已存在的供应商名字和id信息 用于添加付款节点时的选择对应供应商 payNodeInfor: PropTypes.object.isRequired, //选择的支付节点信息(来自支付节点列表) projectType: PropTypes.number.isRequired, //项目类型 0正常 1专利 2软著 3审计 } OperationPayNode.defaultProps = { visible : false, onCancel: ()=>{}, thirdInfoList: [], supplierList: [], payNodeInfor: {}, } const WrappedNormalLoginForm = Form.create()(OperationPayNode); export default WrappedNormalLoginForm;