myClientDesc.jsx 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  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(values.name.length>64){
  18. message.warning('客户名称字数不超过64个')
  19. return false;
  20. };
  21. if(values.content.length>32){
  22. message.warning('联系人字数不超过32个')
  23. return false;
  24. };
  25. if(values.length>13){
  26. message.warning('电话号码字数不超过13个')
  27. return false;
  28. };
  29. if (!err) {
  30. this.setState({
  31. loading: true
  32. });
  33. $.ajax({
  34. method: "POST",
  35. dataType: "json",
  36. crossDomain: false,
  37. url: globalConfig.context + '/api/admin/customer/addCustomer',
  38. data: {
  39. name: values.name,
  40. contacts:values.content,
  41. contactMobile:values.telnum,
  42. societyTag:values.societyTagt,
  43. type:'1'
  44. }
  45. }).done(function (data) {
  46. this.setState({
  47. loading: false
  48. });
  49. if (!data.error.length) {
  50. message.success('保存成功!');
  51. this.props.handleOk();
  52. } else {
  53. message.warning(data.error[0].message);
  54. }
  55. }.bind(this));
  56. }
  57. });
  58. },
  59. //去完善
  60. addContent(){
  61. let telnum=this.state.telnum;
  62. let companyName=this.state.companyNamet;
  63. let content=this.state.content;
  64. if(!telnum||!companyName||!content){
  65. message.warning('此3项都要填');
  66. }else{
  67. this.props.newmodal(true);
  68. this.props.closeDesc(false);
  69. }
  70. },
  71. componentWillMount() {
  72. this.state.name='';
  73. this.state.content='';
  74. this.state.telnum='';
  75. this.state.societyTagt=undefined;
  76. },
  77. componentWillReceiveProps(nextProps) {
  78. if (!this.props.visible && nextProps.visible) {
  79. this.state.name='';
  80. this.state.content='';
  81. this.state.telnum='';
  82. this.state.societyTagt=undefined;
  83. this.props.form.resetFields();
  84. };
  85. },
  86. render() {
  87. const theData = this.state.data || {};
  88. const { getFieldDecorator } = this.props.form;
  89. const FormItem = Form.Item
  90. const formItemLayout = {
  91. labelCol: { span: 8 },
  92. wrapperCol: { span: 14 },
  93. };
  94. return (
  95. <div>
  96. <Form horizontal onSubmit={this.handleSubmit} id="demand-form">
  97. <Spin spinning={this.state.loading}>
  98. <div className="clearfix">
  99. <FormItem className="half-item">
  100. <span className="mandatory" style={{color:'red',marginLeft:'57px'}}>*请录入真实有效的客户信息</span>
  101. </FormItem>
  102. </div>
  103. <div className="clearfix">
  104. <FormItem className="half-item"
  105. {...formItemLayout}
  106. label="公司名称" >
  107. {getFieldDecorator('name', {
  108. rules: [{ required: true, message: '此项为必填项!' }],
  109. initialValue: this.state.name
  110. })(
  111. <Input placeholder="公司名称" />
  112. )}
  113. </FormItem>
  114. </div>
  115. <div className="clearfix">
  116. <FormItem className="half-item"
  117. {...formItemLayout}
  118. label="联系人" >
  119. {getFieldDecorator('content', {
  120. rules: [{ required: true, message: '此项为必填项!' }],
  121. initialValue: this.state.content
  122. })(
  123. <Input placeholder="联系人" />
  124. )}
  125. </FormItem>
  126. </div>
  127. <div className="clearfix">
  128. <FormItem className="half-item"
  129. {...formItemLayout}
  130. label="联系电话" >
  131. {getFieldDecorator('telnum', {
  132. rules: [{ required: true, message: '此项为必填项!' }],
  133. initialValue: this.state.telnum
  134. })(
  135. <Input placeholder="联系电话" />
  136. )}
  137. </FormItem>
  138. </div>
  139. <div className="clearfix">
  140. <FormItem className="half-item"
  141. {...formItemLayout}
  142. label="社会属性"
  143. >
  144. {getFieldDecorator('societyTagt', {
  145. rules: [{ required: true, message: '此项为必填项!' }],
  146. initialValue: this.state.societyTagt
  147. })(
  148. <Select placeholder="客户社会属性">
  149. {
  150. socialAttribute.map(function (item) {
  151. return <Select.Option key={item.value} >{item.key}</Select.Option>
  152. })
  153. }
  154. </Select>
  155. )}
  156. </FormItem>
  157. </div>
  158. <FormItem wrapperCol={{ span: 12, offset: 4 }}>
  159. <Button className="set-submit" type="primary" htmlType="submit">保存</Button>
  160. {/*<Button className="set-submit" type="primary" onClick={(e)=>{this.addContent();this.props.closeDesc}}>去完善</Button>*/}
  161. <Button className="set-submit" type="ghost" onClick={this.props.closeDesc}>取消</Button>
  162. </FormItem>
  163. </Spin>
  164. </Form >
  165. </div>
  166. )
  167. }
  168. }));
  169. const CustomerDetail = React.createClass({
  170. getInitialState() {
  171. return {
  172. visible: false,
  173. tabsKey: 1,
  174. loading: false,
  175. dataSource: [],
  176. };
  177. },
  178. handleCancel(e) {
  179. this.setState({
  180. visible: false,
  181. });
  182. this.props.closeDesc(false);
  183. },
  184. handleOk(e) {
  185. this.setState({
  186. visible: false,
  187. });
  188. this.props.closeDesc(false, true);
  189. },
  190. componentWillReceiveProps(nextProps) {
  191. if (!this.state.visible && nextProps.showDesc) {
  192. this.state.tabsKey = "1";
  193. };
  194. this.state.visible = nextProps.showDesc;
  195. },
  196. render() {
  197. return (
  198. <div className="patent-desc">
  199. <Modal maskClosable={false} visible={this.state.visible}
  200. onOk={this.checkPatentProcess} onCancel={this.handleCancel}
  201. width='800px'
  202. title='新建客户'
  203. footer=''
  204. className="admin-desc-content">
  205. <Spin spinning={this.state.loading}>
  206. <AchievementDetailForm
  207. data={this.props.data}
  208. newmodal={this.props.newmodal}
  209. closeDesc={this.handleCancel}
  210. visible={this.state.visible}
  211. handleOk={this.handleOk} />
  212. </Spin>
  213. </Modal>
  214. </div>
  215. );
  216. },
  217. });
  218. export default CustomerDetail;