myClientDesc.jsx 8.1 KB

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