myClientDesc.jsx 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  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.companyNamet.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: values.companyNamet,
  36. contactMobile: values.telnum,
  37. depatrment:this.state.depatrments,
  38. position:this.state.positions,
  39. wechat:this.state.wechats,
  40. qq:this.state.qqs,
  41. email:this.state.emails,
  42. type:'0'
  43. }
  44. }).done(function (data) {
  45. this.setState({
  46. loading: false
  47. });
  48. if (!data.error.length) {
  49. message.success('保存成功!');
  50. this.props.handleOk();
  51. } else {
  52. message.warning(data.error[0].message);
  53. }
  54. }.bind(this));
  55. }
  56. });
  57. },
  58. //去完善
  59. addContent(){
  60. let telnum=this.state.telnum;
  61. let companyName=this.state.companyNamet;
  62. let content=this.state.content;
  63. if(!telnum||!companyName||!content){
  64. message.warning('此3项都要填');
  65. }else{
  66. this.props.newmodal(true);
  67. this.props.closeDesc(false);
  68. }
  69. },
  70. componentWillMount() {
  71. this.state.companyNamet='';
  72. this.state.telnum='';
  73. },
  74. componentWillReceiveProps(nextProps) {
  75. if (!this.props.visible && nextProps.visible) {
  76. this.state.companyNamet='';
  77. this.state.telnum='';
  78. this.props.form.resetFields();
  79. };
  80. },
  81. render() {
  82. const theData = this.state.data || {};
  83. const { getFieldDecorator } = this.props.form;
  84. const FormItem = Form.Item
  85. const formItemLayout = {
  86. labelCol: { span: 8 },
  87. wrapperCol: { span: 14 },
  88. };
  89. return (
  90. <div>
  91. <Form horizontal onSubmit={this.handleSubmit} id="demand-form">
  92. <Spin spinning={this.state.loading}>
  93. <div className="clearfix">
  94. <FormItem className="half-item"
  95. {...formItemLayout}
  96. label="客户姓名" >
  97. {getFieldDecorator('companyNamet', {
  98. rules: [{ required: true, message: '此项为必填项!' }],
  99. initialValue: this.state.companyNamet
  100. })(
  101. <Input placeholder="客户姓名" />
  102. )}
  103. </FormItem>
  104. <FormItem className="half-item"
  105. {...formItemLayout}
  106. label="联系电话" >
  107. {getFieldDecorator('telnum', {
  108. rules: [{ required: true, message: '此项为必填项!' }],
  109. initialValue: this.state.telnum
  110. })(
  111. <Input placeholder="联系电话" />
  112. )}
  113. </FormItem>
  114. <FormItem className="half-item"
  115. {...formItemLayout}
  116. label="联系人部门" >
  117. <Input value={this.state.depatrments} placeholder="联系人部门"
  118. onChange={(e) => { this.setState({ depatrments: e.target.value }); }} />
  119. </FormItem>
  120. <FormItem className="half-item"
  121. {...formItemLayout}
  122. label="联系人职务" >
  123. <Input value={this.state.positions} placeholder="联系人职务"
  124. onChange={(e) => { this.setState({ positions: e.target.value }); }} />
  125. </FormItem>
  126. <FormItem className="half-item"
  127. {...formItemLayout}
  128. label="微信" >
  129. <Input value={this.state.wechats} placeholder="微信"
  130. onChange={(e) => { this.setState({ wechats: e.target.value }); }} />
  131. </FormItem>
  132. <FormItem className="half-item"
  133. {...formItemLayout}
  134. label="联系人QQ" >
  135. <Input value={this.state.qqs} placeholder="联系人QQ"
  136. onChange={(e) => { this.setState({ qqs: e.target.value }); }} />
  137. </FormItem>
  138. <FormItem className="half-item"
  139. {...formItemLayout}
  140. label="电子邮箱" >
  141. <Input value={this.state.emails} placeholder="电子邮箱"
  142. onChange={(e) => { this.setState({ emails: e.target.value }); }} />
  143. </FormItem>
  144. </div>
  145. <FormItem wrapperCol={{ span: 12, offset: 4 }}>
  146. <Button className="set-submit" type="primary" htmlType="submit">保存</Button>
  147. {/*<Button className="set-submit" type="primary" onClick={(e)=>{this.addContent();this.props.closeDesc}}>去完善</Button>*/}
  148. <Button className="set-submit" type="ghost" onClick={this.props.closeDesc}>取消</Button>
  149. </FormItem>
  150. </Spin>
  151. </Form >
  152. </div>
  153. )
  154. }
  155. }));
  156. const CustomerDetail = React.createClass({
  157. getInitialState() {
  158. return {
  159. visible: false,
  160. tabsKey: 1,
  161. loading: false,
  162. dataSource: [],
  163. };
  164. },
  165. handleCancel(e) {
  166. this.setState({
  167. visible: false,
  168. });
  169. this.props.closeDesc(false);
  170. },
  171. handleOk(e) {
  172. this.setState({
  173. visible: false,
  174. });
  175. this.props.closeDesc(false, true);
  176. },
  177. componentWillReceiveProps(nextProps) {
  178. if (!this.state.visible && nextProps.showDesc) {
  179. this.state.tabsKey = "1";
  180. };
  181. this.state.visible = nextProps.showDesc;
  182. },
  183. render() {
  184. return (
  185. <div className="patent-desc">
  186. <Modal maskClosable={false} visible={this.state.visible}
  187. onOk={this.checkPatentProcess} onCancel={this.handleCancel}
  188. width='800px'
  189. title='新建客户'
  190. footer=''
  191. className="admin-desc-content">
  192. <Spin spinning={this.state.loading}>
  193. <AchievementDetailForm
  194. data={this.props.data}
  195. newmodal={this.props.newmodal}
  196. closeDesc={this.handleCancel}
  197. visible={this.state.visible}
  198. handleOk={this.handleOk} />
  199. </Spin>
  200. </Modal>
  201. </div>
  202. );
  203. },
  204. });
  205. export default CustomerDetail;