import React from "react"; import { Spin, Button, Tabs, Table, message, Modal, Input, Tag, Popconfirm } from "antd"; import img from "./example.png" import $ from "jquery/src/ajax"; const ResolutionPro = React.createClass({ getInitialState() { return { visible: false, proArr: [ { name: "子项目1", number: 0 }, { name: "子项目2", number: 0 }, { name: "子项目3", number: 0 }, ], inputArr: [] }; }, componentWillReceiveProps(nextProps) { this.setState({ visible: nextProps.resolutionVisible }); const arr = [ { name: "子项目1", number: 0 }, { name: "子项目2", number: 0 }, { name: "子项目3", number: 0 } ]; this.setState({ proArr: arr }); }, handleOk() { const arr = [ { name: "子项目1", number: 0 }, { name: "子项目2", number: 0 }, { name: "子项目3", number: 0 } ]; this.setState({ visible: false, proArr: arr }); }, addPro() { const obj = { name: "子项目" + (this.state.proArr.length + 1), number: 0 } this.state.proArr.push(obj) this.setState({ proArr: this.state.proArr }) }, deletePro() { if(this.state.proArr.length == 2) { message.warning("不能继续删除子项目!") return } this.state.proArr.splice(this.state.proArr.length - 1, 1) this.setState({ proArr: this.state.proArr }) }, submit() { const arr = this.state.proArr const numArr = [] arr.forEach(item => { let num = +item.number if(num != 0) { numArr.push(num); } }); let sum = 0 numArr.forEach( item => { sum += item }) if(sum != this.props.number) { message.warning("拆分数量总和与原项目数量不匹配,请重新填写数量!") return } let str = numArr.join(",") this.setState({ loading: true }); $.ajax({ method: "post", dataType: "json", crossDomain: false, url: globalConfig.context + "/api/admin/orderProject/addSplitProject", data: { tid: this.props.id, splitList: str }, success: function(data) { let thedata = data.data; if (!thedata) { if (data.error && data.error.length) { message.warning(data.error[0].message); } thedata = {}; } else { message.success("拆分成功!") this.props.cancel() this.props.loadData() } }.bind(this) }).always( function() { this.setState({ loading: false }); }.bind(this) ); }, changeNum() { let sum = 0 this.state.proArr.forEach(item => { sum += (+item.number) }) return sum }, render() { return (
各子项目相加需等于当前项目数量!