123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574 |
- import React from 'react';
- import { Icon, Modal, Button, Form, message, AutoComplete,Input, Spin, Select, Checkbox, InputNumber, DatePicker } from 'antd';
- import './contract.less';
- import { companySearch } from '../../../tools.js';
- import ajax from 'jquery/src/ajax/xhr.js'
- import $ from 'jquery/src/ajax';
- const Option = AutoComplete.Option;
- const ContractAddFrom = Form.create()(React.createClass({
- getContactsList(theUid) {
- $.ajax({
- method: "get",
- dataType: "json",
- crossDomain: false,
- url: globalConfig.context + "/api/admin/customer/findAllContacts",
- data: {
- uid: theUid
- },
- success: function (data) {
- let theOption = [];
- if (!data.data) {
- if (data.error && data.error.length) {
- message.warning(data.error[0].message);
- return;
- };
- };
- for (let item in data.data) {
- let theData = data.data[item];
- theOption.push(
- <Select.Option value={item} key={theData.name}>{theData.name}</Select.Option>
- );
- };
- this.setState({
- //orderStatusOption:data.data,
- //contactsOption: theOption
- });
- }.bind(this),
- });
- },
- getInitialState() {
- return {
- loading: false,
- companyOption: [],
- accelerated: 0,
- acceleratedDate: 0,
- visible: "visible"
- };
- },
- loadData(id) {
- this.setState({
- loading: true
- });
- $.ajax({
- method: "get",
- dataType: "json",
- crossDomain: false,
- cache: false,
- url: globalConfig.context + "/api/admin/contract/detail",
- data: {
- id: id || this.props.data.id
- }
- }).done((data) => {
- if (!data.data) {
- if (data.error && data.error.length) {
- message.warning(data.error[0].message);
- };
- } else {
- this.setState({
- data: data.data,
- patentCheck: data.data.patentNum ? true : false,
- copyrightCheck: data.data.copyrightNum ? true : false,
- highTechCheck: data.data.cognizanceYear ? true : false,
- techProjectCheck: data.data.techProjectNum ? true : false,
- });
- };
- }).always(function () {
- this.setState({
- loading: false
- });
- }.bind(this));
- },
- componentWillMount() {
- let d = new Date(), _me = this, theArr = [];
- d = d.getFullYear() - 1;
- for (let i = d; i < d + 20; i++) {
- theArr.push(
- <Select.Option value={i.toString()} key={i}>{i}</Select.Option>
- )
- };
- this.state.yearOption = theArr;
- if (this.props.data && this.props.data.uid && this.props.data.id) {
- this.getNewWoman(this.props.data.uid);
- this.loadData(this.props.data.id);
- } else {
- this.state.data = {};
- this.state.patentCheck = false;
- this.state.copyrightCheck = false;
- this.state.highTechCheck = false;
- this.state.techProjectCheck = false;
- };
- },
- componentWillReceiveProps(nextProps) {
- if (!this.props.visible && nextProps.visible) {
- if (nextProps.data && nextProps.data.uid && nextProps.data.id) {
- this.getNewWoman(nextProps.data.uid);
- this.loadData(nextProps.data.id);
- } else {
- this.state.data = {};
- this.state.patentCheck = false;
- this.state.copyrightCheck = false;
- this.state.highTechCheck = false;
- this.state.techProjectCheck = false;
- };
- this.props.form.resetFields();
- };
- },
- //获取联系人下拉框
- getNewWoman(ids) {
- this.state.data = []
- $.ajax({
- method: "get",
- dataType: "json",
- crossDomain: false,
- url: globalConfig.context + "/api/admin/customer/findAllContacts",
- data:{
- uid:ids,
- },
- success: function (data) {
- let theArr = [];
- let thedata=data.data;
- if (!thedata) {
- if (data.error && data.error.length) {
- message.warning(data.error[0].message);
- };
- thedata = {};
- };
- var contactIds=[];
- for (let item in data.data) {
- let theData = data.data[item];
- theArr.push(
- <Select.Option value={item} key={theData.name}>{theData.name}</Select.Option>
- );
- };
- this.setState({
- contactsOption: theArr,
- orderStatusOptions:data.data,
- });
- }.bind(this),
- }).always(function () {
- this.setState({
- loading: false
- });
- }.bind(this));
- },
- handleSave(e) {
- e.preventDefault();
- this.props.form.validateFields((err, values) => {
- if (!err) {
- if (!(this.state.data.uid || this.state.khId) || !this.state.contacts) {
- message.warning('请选择一个公司和联系人!');
- return;
- }
- if (!values.patentNum && !values.copyrightNum && !values.cognizanceYear && !values.techProjectNum) {
- message.warning('请至少选择一个申报项目!');
- return;
- };
-
- this.props.spinState(true);
- $.ajax({
- method: "POST",
- dataType: "json",
- crossDomain: false,
- url: globalConfig.context + "/api/admin/contract/apply",
- data: {
- "uid": this.state.data.uid || this.state.khId,
- "id": this.state.data.id,
- "contacts": this.state.contacts, //联系人
- "type": values.type, //合同类型
- "depict": values.depict, // "合同描述",
- "patentNum": this.state.patentCheck ? values.patentNum : 0,
- "copyrightNum": this.state.copyrightCheck ? values.copyrightNum : 0,
- "cognizanceYear": this.state.highTechCheck ? values.cognizanceYear : undefined,
- "techProjectNum": this.state.techProjectCheck ? values.techProjectNum : 0,
- "previousFee": values.previousFee,
- "comment": values.comment //"备注"
- }
- }).done(function (data) {
- if (!data.error.length) {
- message.success('保存成功!');
- this.props.okClick();
- this.props.closeModal();
- this.props.form.resetFields();
- } else {
- message.warning(data.error[0].message);
- }
- }.bind(this)).always(function () {
- this.props.spinState(false);
- }.bind(this));
- }
- });
- },
- handleSubmit() {
- this.props.form.validateFields((err, values) => {
- if (!err) {
- if (!values.principals || !values.recordTime) {
- message.warning('请填写审核信息!');
- return;
- };
- if(this.state.contacts==undefined){
- message.warning('请选择联系人')
- return false;
- }
- this.props.spinState(true);
- $.ajax({
- method: "POST",
- dataType: "json",
- crossDomain: false,
- url: globalConfig.context + "/api/admin/contract/submit",
- data: {
- "uid": this.state.data.uid || this.state.khId,
- "id": this.state.data.id,
- "contacts": this.state.contacts, //联系人
- "type": values.type, //合同类型
- "depict": values.depict, // "合同描述",
- "patentNum": this.state.patentCheck ? values.patentNum : 0,
- "copyrightNum": this.state.copyrightCheck ? values.copyrightNum : 0,
- "cognizanceYear": this.state.highTechCheck ? values.cognizanceYear : undefined,
- "techProjectNum": this.state.techProjectCheck ? values.techProjectNum : 0,
- "principals": values.principals,
- "previousFee": values.previousFee,
- "signDateFormattedDate": values.recordTime ? values.recordTime.format("YYYY-MM-DD HH:mm:ss") : undefined,
- "comment": values.comment //"备注"
- }
- }).done(function (data) {
- if (!data.error.length) {
- message.success('提交成功!');
- this.props.okClick();
- this.props.closeModal();
- this.props.form.resetFields();
- } else {
- message.warning(data.error[0].message);
- }
- }.bind(this)).always(function () {
- this.props.spinState(false);
- }.bind(this));
- }
- });
- },
- //客户名称初始加载
- customerList(e){
- $.ajax({
- method: "get",
- dataType: "json",
- crossDomain: false,
- url: globalConfig.context + "/api/admin/customer/findCustomerByName",
- data:{
- name: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({
- customerArr:thedata,
- });
- }.bind(this),
- }).always(function () {
- this.setState({
- loading: false
- });
- }.bind(this));
- },
- //值改变时请求客户名称
- httpChange(e){
- if(e.length>=2){
- this.customerList(e);
- return;
- }
- },
-
- //客户输入框失去焦点是判断客户是否存在
- blurChange(e){
- let theType='';
- let contactLists=this.state.customerArr||[];
- if (e) {
- contactLists.map(function (item) {
- if (item.name == e.toString()) {
- theType = item.id;
- }
- });
- }
- if(!theType){
- return message.warning('当前客户名不存在')
- };
- this.setState({
- khId:theType
- })
- },
- //选择值时值匹配及联系人函数加载
- autoChange(e){
- let theType='';
- let contactLists=this.state.customerArr||[];
- if (e) {
- contactLists.map(function (item) {
- if (item.name == e.toString()) {
- theType = item.id;
- }
- });
- }
- this.getNewWoman(theType)
- },
- render() {
- const FormItem = Form.Item;
- const { getFieldDecorator } = this.props.form;
- const theData = this.state.data || {};
- const formItemLayout = {
- labelCol: { span: 6 },
- wrapperCol: { span: 14 },
- };
- const dataSources=this.state.customerArr || [];
- const options = dataSources.map((group) =>
- <Option key={group.id} value={group.name}>{group.name}</Option>
- );
- const _me = this;
- return (
- <Form horizontal onSubmit={this.handleSave} id="CopyrightDesc-form">
- <div className="clearfix">
- {theData.uid ? <FormItem className="half-item"
- {...formItemLayout}
- label="公司名称" >
- <span>{theData.unitName}</span>
- </FormItem> : <FormItem className="half-item"
- {...formItemLayout}
- label="公司名称" >
- <AutoComplete
- className="certain-category-search"
- dropdownClassName="certain-category-search-dropdown"
- dropdownMatchSelectWidth={false}
- dropdownStyle={{ width: 300 }}
- size="large"
- style={{ width: '100%' }}
- dataSource={options}
- placeholder="输入名称"
- optionLabelProp="value"
- onChange={this.httpChange}
- onSelect={this.autoChange}
- filterOption={true}
- onBlur={this.blurChange}
- >
- <Input />
- </AutoComplete>
- </FormItem>
- }
- <FormItem className="half-item"
- {...formItemLayout}
- label="联系人" >
- <Select placeholder="请选择联系人" value={this.state.contacts} onChange={(e)=>{this.setState({contacts:e})}}
- style={{ width: 260 }}
- notFoundContent="未获取到联系人列表">
- {this.state.contactsOption}
- </Select>
- </FormItem>
- <FormItem className="half-item"
- {...formItemLayout}
- label="合同类型" >
- {getFieldDecorator('type', {
- initialValue: theData.type
- })(
- <Select placeholder="请选择合同类型"
- style={{ width: 260 }}>
- {this.props.typeOption}
- </Select>
- )}
- </FormItem>
- <FormItem className="half-item"
- {...formItemLayout}
- label="前期费用" >
- {getFieldDecorator('previousFee', {
- initialValue: theData.previousFee
- })(
- <InputNumber min={0} max={999999} step={0.01} style={{ width: '80px', marginRight: '20px' }} />
- )}
- <span>万元</span>
- </FormItem>
- </div>
- <FormItem
- labelCol={{ span: 3 }}
- wrapperCol={{ span: 19 }}
- label="合同描述" >
- {getFieldDecorator('depict', {
- initialValue: theData.depict
- })(
- <Input type="textarea"
- placeholder="多行输入"
- rows={4} />
- )}
- </FormItem>
- <div className="clearfix">
- <span style={{ float: "left", lineHeight: '32px', marginLeft: '50px' }}>
- <Checkbox checked={this.state.highTechCheck} onChange={(e) => {
- this.setState({ highTechCheck: e.target.checked });
- }}></Checkbox>
- </span>
- <FormItem className="half-item"
- {...formItemLayout}
- label={"高企申请"} >
- {getFieldDecorator('cognizanceYear', {
- initialValue: theData.cognizanceYear ? String(theData.cognizanceYear) : null
- })(
- <Select placeholder="请选择年份"
- style={{ width: 120 }}
- onSelect={(e, n) => { this.setState({ year: e }); }}>
- {this.state.yearOption}
- </Select>
- )}
- </FormItem>
- </div>
- <div className="clearfix">
- <span style={{ float: "left", lineHeight: '32px', marginLeft: '50px' }}>
- <Checkbox checked={this.state.patentCheck} onChange={(e) => {
- this.setState({ patentCheck: e.target.checked });
- }}></Checkbox>
- </span>
- <FormItem className="half-item"
- {...formItemLayout}
- label={"专利申请"} >
- {getFieldDecorator('patentNum', {
- initialValue: theData.patentNum
- })(
- <InputNumber />
- )}
- </FormItem>
- </div>
- <div className="clearfix">
- <span style={{ float: "left", lineHeight: '32px', marginLeft: '50px' }}>
- <Checkbox checked={this.state.copyrightCheck} onChange={(e) => {
- this.setState({ copyrightCheck: e.target.checked });
- }}></Checkbox>
- </span>
- <FormItem className="half-item"
- {...formItemLayout}
- label={"软著申请"} >
- {getFieldDecorator('copyrightNum', {
- initialValue: theData.copyrightNum
- })(
- <InputNumber />
- )}
- </FormItem>
- </div>
- <div className="clearfix">
- <span style={{ float: "left", lineHeight: '32px', marginLeft: '50px' }}>
- <Checkbox checked={this.state.techProjectCheck} onChange={(e) => {
- this.setState({ techProjectCheck: e.target.checked });
- }}></Checkbox>
- </span>
- <FormItem className="half-item"
- {...formItemLayout}
- label={"科技项目申请"} >
- {getFieldDecorator('techProjectNum', {
- initialValue: theData.techProjectNum
- })(
- <InputNumber />
- )}
- </FormItem>
- </div>
- <div className="clearfix">
- <FormItem className="half-item"
- {...formItemLayout}
- label={"审核人"} >
- {getFieldDecorator('principals')(
- <Select
- placeholder="请选择审核人"
- notFoundContent="未找到"
- style={{ width: 260 }}
- showSearch
- multiple
- filterOption={companySearch} >
- {this.props.authorOption}
- </Select>
- )}
- </FormItem>
- <FormItem className="half-item"
- {...formItemLayout}
- label="处理时间"
- >
- {getFieldDecorator('recordTime')(
- <DatePicker />
- )}
- </FormItem>
- </div>
- <FormItem
- labelCol={{ span: 3 }}
- wrapperCol={{ span: 19 }}
- label="备注" >
- {getFieldDecorator('comment', {
- initialValue: theData.comment
- })(
- <Input type="textarea"
- placeholder="多行输入"
- rows={2} />
- )}
- </FormItem>
- <p style={{ color: '#ea0862', paddingLeft: '40px', marginBottom: '20px' }}>合同提交以后无法修改,请确认提交内容的正确性!</p>
- <FormItem style={{ paddingLeft: '40px' }}>
- <Button className="set-submit" type="primary" htmlType="submit">保存草稿</Button>
- <Button onClick={this.handleSubmit} type="ghost" style={{ marginLeft: '20px' }}>提交</Button>
- <Button type="ghost" style={{ marginLeft: '20px' }} onClick={this.props.closeModal}>取消</Button>
- </FormItem>
- </Form >
- );
- },
- }));
- const ContractAdd = React.createClass({
- getInitialState() {
- return {
- visible: false,
- loading: false
- };
- },
- showModal() {
- this.setState({
- visible: true,
- data: {}
- });
- },
- handleCancel(e) {
- this.setState({
- visible: false,
- });
- this.props.closeAdd(false);
- },
- componentWillReceiveProps(nextProps) {
- if (nextProps.showAdd && nextProps.data) {
- this.state.data = nextProps.data;
- };
- this.state.visible = nextProps.showAdd;
- },
- spinChange(e) {
- this.setState({
- loading: e
- });
- },
- render() {
- return (
- <div className="patent-addNew">
- <Button className="patent-addNew" type="primary" onClick={this.showModal}>申请合同<Icon type="plus" /></Button>
- <Modal maskClosable={false} title="合同详情"
- visible={this.state.visible}
- onCancel={this.handleCancel}
- width='800px'
- footer='' >
- <Spin spinning={this.state.loading} className='spin-box'>
- <ContractAddFrom
- spinState={this.spinChange}
- closeModal={this.handleCancel}
- visible={this.state.visible}
- data={this.state.data}
- okClick={() => { this.props.closeAdd(false, true) }}
- companyOption={this.props.companyOption}
- authorOption={this.props.authorOption}
- typeOption={this.props.typeOption} />
- </Spin>
- </Modal>
- </div>
- );
- },
- });
- export default ContractAdd;
|