myClientDesc.jsx 6.0 KB

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