myClientDesc.jsx 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. import React from 'react';
  2. import { Icon, Modal, message, Spin, Input, Select, Button, Form } from 'antd';
  3. import './myClient.less';
  4. import ajax from 'jquery/src/ajax/xhr.js';
  5. import $ from 'jquery/src/ajax';
  6. import {socialAttribute} from '../../../dataDic.js';
  7. const AchievementDetailForm = Form.create()(React.createClass({
  8. getInitialState() {
  9. return {
  10. loading: false,
  11. data: {},
  12. };
  13. },
  14. handleSubmit(e) {
  15. e.preventDefault();
  16. this.props.form.validateFields((err, values) => {
  17. if (!err) {
  18. this.setState({
  19. loading: true
  20. });
  21. $.ajax({
  22. method: "POST",
  23. dataType: "json",
  24. crossDomain: false,
  25. url: globalConfig.context + '/api/admin/customer/addCu',
  26. data: {
  27. name: this.state.companyNamet,
  28. contactMobile: this.state.telnum,
  29. type:'0'
  30. }
  31. }).done(function (data) {
  32. this.setState({
  33. loading: false
  34. });
  35. if (!data.error.length) {
  36. message.success('保存成功!');
  37. this.props.handleOk();
  38. } else {
  39. message.warning(data.error[0].message);
  40. }
  41. }.bind(this));
  42. }
  43. });
  44. },
  45. //去完善
  46. addContent(){
  47. let telnum=this.state.telnum;
  48. let companyName=this.state.companyNamet;
  49. let content=this.state.content;
  50. if(!telnum||!companyName||!content){
  51. message.warning('此3项都要填');
  52. }else{
  53. this.props.newmodal(true);
  54. this.props.closeDesc(false);
  55. }
  56. },
  57. componentWillMount() {
  58. this.state.companyNamet='';
  59. this.state.telnum='';
  60. },
  61. componentWillReceiveProps(nextProps) {
  62. if (!this.props.visible && nextProps.visible) {
  63. this.state.companyNamet='';
  64. this.state.telnum='';
  65. this.props.form.resetFields();
  66. };
  67. },
  68. render() {
  69. const theData = this.state.data || {};
  70. const { getFieldDecorator } = this.props.form;
  71. const FormItem = Form.Item
  72. const formItemLayout = {
  73. labelCol: { span: 8 },
  74. wrapperCol: { span: 14 },
  75. };
  76. return (
  77. <div>
  78. <Form horizontal onSubmit={this.handleSubmit} id="demand-form">
  79. <Spin spinning={this.state.loading}>
  80. <div className="clearfix">
  81. <FormItem className="half-item"
  82. {...formItemLayout}
  83. label="客户名称" >
  84. <Input value={this.state.companyNamet} placeholder="公司名称"
  85. onChange={(e) => { this.setState({ companyNamet: e.target.value }); }} required="required"/>
  86. </FormItem>
  87. </div>
  88. <div className="clearfix">
  89. <FormItem className="half-item"
  90. {...formItemLayout}
  91. label="联系电话" >
  92. <Input value={this.state.telnum} placeholder="联系电话"
  93. onChange={(e) => { this.setState({ telnum: e.target.value }); }} required="required"/>
  94. </FormItem>
  95. </div>
  96. <FormItem wrapperCol={{ span: 12, offset: 4 }}>
  97. <Button className="set-submit" type="primary" htmlType="submit">保存</Button>
  98. {/*<Button className="set-submit" type="primary" onClick={(e)=>{this.addContent();this.props.closeDesc}}>去完善</Button>*/}
  99. <Button className="set-submit" type="ghost" onClick={this.props.closeDesc}>取消</Button>
  100. </FormItem>
  101. </Spin>
  102. </Form >
  103. </div>
  104. )
  105. }
  106. }));
  107. const CustomerDetail = React.createClass({
  108. getInitialState() {
  109. return {
  110. visible: false,
  111. tabsKey: 1,
  112. loading: false,
  113. dataSource: [],
  114. };
  115. },
  116. handleCancel(e) {
  117. this.setState({
  118. visible: false,
  119. });
  120. this.props.closeDesc(false);
  121. },
  122. handleOk(e) {
  123. this.setState({
  124. visible: false,
  125. });
  126. this.props.closeDesc(false, true);
  127. },
  128. componentWillReceiveProps(nextProps) {
  129. if (!this.state.visible && nextProps.showDesc) {
  130. this.state.tabsKey = "1";
  131. };
  132. this.state.visible = nextProps.showDesc;
  133. },
  134. render() {
  135. return (
  136. <div className="patent-desc">
  137. <Modal maskClosable={false} visible={this.state.visible}
  138. onOk={this.checkPatentProcess} onCancel={this.handleCancel}
  139. width='800px'
  140. title='新建客户'
  141. footer=''
  142. className="admin-desc-content">
  143. <Spin spinning={this.state.loading}>
  144. <AchievementDetailForm
  145. data={this.props.data}
  146. newmodal={this.props.newmodal}
  147. closeDesc={this.handleCancel}
  148. visible={this.state.visible}
  149. handleOk={this.handleOk} />
  150. </Spin>
  151. </Modal>
  152. </div>
  153. );
  154. },
  155. });
  156. export default CustomerDetail;