|
@@ -0,0 +1,316 @@
|
|
|
+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,
|
|
|
+ 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){
|
|
|
+ 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
|
|
|
+ })
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ 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 (
|
|
|
+ <Modal
|
|
|
+ visible={this.props.visible}
|
|
|
+ onCancel={this.props.onCancel}
|
|
|
+ width={800}
|
|
|
+ title={this.props.thirdId ? "修改付款节点" : "新增付款节点"}
|
|
|
+ footer=""
|
|
|
+ className="admin-desc-content"
|
|
|
+ >
|
|
|
+ <Form
|
|
|
+ layout="horizontal"
|
|
|
+ style={{ paddingBottom: '40px' }}
|
|
|
+ >
|
|
|
+ <Spin spinning={this.state.loading}>
|
|
|
+ <div className="clearfix">
|
|
|
+ <div className="clearfix">
|
|
|
+ <Form.Item {...formItemLayout} label="供应商名称">
|
|
|
+ {getFieldDecorator('companyName', {
|
|
|
+ initialValue: payNodeInfor.companyName,
|
|
|
+ rules: [{ required: true, message: '请选择供应商' }],
|
|
|
+ })(
|
|
|
+ <Select
|
|
|
+ onChange={(val) => {
|
|
|
+ this.setState(
|
|
|
+ {
|
|
|
+ thirdCompanyName: val,
|
|
|
+ },
|
|
|
+ () => this.payNodeCalculatedAmount()
|
|
|
+ )
|
|
|
+ }}
|
|
|
+ defaultValue="请选择供应商"
|
|
|
+ style={{ width: 220 }}
|
|
|
+ >
|
|
|
+ {this.props.supplierList.map((item, index) => (
|
|
|
+ <Select.Option value={item.companyName} key={index}>
|
|
|
+ {item.companyName}
|
|
|
+ </Select.Option>
|
|
|
+ ))}
|
|
|
+ </Select>
|
|
|
+ )}
|
|
|
+ </Form.Item>
|
|
|
+ </div>
|
|
|
+
|
|
|
+ <div className="clearfix">
|
|
|
+ <Form.Item {...formItemLayout} label="付款科目">
|
|
|
+ {getFieldDecorator('dunType', {
|
|
|
+ initialValue: payNodeInfor.dunType,
|
|
|
+ rules: [{ required: true, message: '请选择付款科目' }],
|
|
|
+ })(
|
|
|
+ <Select
|
|
|
+ onChange={(val) => {
|
|
|
+ this.setState({
|
|
|
+ paySubjectName: val,
|
|
|
+ dunType: val,
|
|
|
+ })
|
|
|
+ }}
|
|
|
+ defaultValue="请选择付款科目"
|
|
|
+ style={{ width: 220 }}
|
|
|
+ >
|
|
|
+ {this.state.paySubject.map((item, index) => (
|
|
|
+ <Select.Option value={item.value} key={index}>
|
|
|
+ {item.key}
|
|
|
+ </Select.Option>
|
|
|
+ ))}
|
|
|
+ <Select.Option key={0} value={0}>
|
|
|
+ 自定义
|
|
|
+ </Select.Option>
|
|
|
+ </Select>)}
|
|
|
+ </Form.Item>
|
|
|
+ </div>
|
|
|
+ <div className="clearfix">
|
|
|
+ {parseInt(this.state.paySubjectName) === 0 ? <Form.Item {...formItemLayout} label="付款时间">
|
|
|
+ {getFieldDecorator('partyTimes', {
|
|
|
+ initialValue: payNodeInfor.partyTimes,
|
|
|
+ rules: [{ required: true, message: '请选择付款时间' }],
|
|
|
+ })(
|
|
|
+ <DatePicker
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ style={{ width: '220px' }}
|
|
|
+ />
|
|
|
+ )}
|
|
|
+ </Form.Item> : <div/>}
|
|
|
+ </div>
|
|
|
+ <div className="clearfix">
|
|
|
+ <Form.Item {...formItemLayout} label="数量">
|
|
|
+ {getFieldDecorator('quantity', {
|
|
|
+ initialValue: payNodeInfor.quantity,
|
|
|
+ rules: [{ required: true, message: '请输入数量' }],
|
|
|
+ })(
|
|
|
+ <InputNumber
|
|
|
+ min={1}
|
|
|
+ precision={0}
|
|
|
+ disabled={payNodeInfor.quantity <= 1}
|
|
|
+ placeholder="请输入数量"
|
|
|
+ onChange={(e) => {
|
|
|
+ this.payNodeCalculatedAmount(e)
|
|
|
+ }}
|
|
|
+ style={{ width: '220px' }}
|
|
|
+ />
|
|
|
+ )}
|
|
|
+ </Form.Item>
|
|
|
+ </div>
|
|
|
+ {this.props.projectType !== 2 ? <div className="clearfix">
|
|
|
+ <Form.Item {...formItemLayout} label="总价(万元)">
|
|
|
+ {getFieldDecorator('quantity', {
|
|
|
+ initialValue: payNodeInfor.quantity,
|
|
|
+ rules: [{ required: true, message: '请输入数量' }],
|
|
|
+ })(
|
|
|
+ <Input
|
|
|
+ type={'number'}
|
|
|
+ value={this.state.currentTotalPrice}
|
|
|
+ placeholder="请输入总价"
|
|
|
+ onChange={(e) =>
|
|
|
+ this.setState({
|
|
|
+ currentTotalPrice: e.target.value,
|
|
|
+ })
|
|
|
+ }
|
|
|
+ style={{ width: '220px' }}
|
|
|
+ />
|
|
|
+ )}
|
|
|
+ </Form.Item>
|
|
|
+ </div> : <div/>}
|
|
|
+ <div className="clearfix">
|
|
|
+ <div className="addSave" style={{ marginTop: '15px' }}>
|
|
|
+ <Button
|
|
|
+ className="cancel"
|
|
|
+ type="primary"
|
|
|
+ onClick={this.savePayNode}
|
|
|
+ style={{ marginLeft: '300px' }}
|
|
|
+ htmlType="submit"
|
|
|
+ >
|
|
|
+ 保存
|
|
|
+ </Button>
|
|
|
+ <Button
|
|
|
+ className="cancel"
|
|
|
+ type="ghost"
|
|
|
+ onClick={this.handleCancelclose}
|
|
|
+ style={{ marginLeft: '50px' }}
|
|
|
+ >
|
|
|
+ 取消
|
|
|
+ </Button>
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+ </Spin>
|
|
|
+ </Form>
|
|
|
+ </Modal>
|
|
|
+ )
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+OperationPayNode.propTypes = {
|
|
|
+ visible : PropTypes.bool.isRequired,
|
|
|
+ onCancel : PropTypes.func.isRequired,
|
|
|
+ thirdId : PropTypes.number.isRequired,
|
|
|
+ thirdInfoList: PropTypes.array.isRequired,
|
|
|
+ supplierList: PropTypes.array.isRequired,
|
|
|
+ payNodeInfor: PropTypes.object.isRequired,
|
|
|
+ projectType: PropTypes.number.isRequired,
|
|
|
+}
|
|
|
+
|
|
|
+OperationPayNode.defaultProps = {
|
|
|
+ visible : false,
|
|
|
+ onCancel: ()=>{},
|
|
|
+ thirdInfoList: [],
|
|
|
+ supplierList: [],
|
|
|
+ payNodeInfor: {},
|
|
|
+}
|
|
|
+
|
|
|
+const WrappedNormalLoginForm = Form.create()(OperationPayNode);
|
|
|
+export default WrappedNormalLoginForm;
|