myClientDesc.jsx 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  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.companyNamet.length>64){
  18. message.warning('联系人字数不超过64个')
  19. return false;
  20. };
  21. if(values.telnum.length>13){
  22. message.warning('电话号码字数不超过13个')
  23. return false;
  24. };
  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. this.state.depatrments='';
  74. this.state.positions='';
  75. this.state.wechats='';
  76. this.state.qqs='';
  77. this.state.emails='';
  78. },
  79. componentWillReceiveProps(nextProps) {
  80. if (!this.props.visible && nextProps.visible) {
  81. this.state.companyNamet='';
  82. this.state.telnum='';
  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. {...formItemLayout}
  101. label="客户姓名" >
  102. {getFieldDecorator('companyNamet', {
  103. rules: [{ required: true, message: '此项为必填项!' }],
  104. initialValue: this.state.companyNamet
  105. })(
  106. <Input placeholder="客户姓名" />
  107. )}
  108. </FormItem>
  109. <FormItem className="half-item"
  110. {...formItemLayout}
  111. label="联系电话" >
  112. {getFieldDecorator('telnum', {
  113. rules: [{ required: true, message: '此项为必填项!' }],
  114. initialValue: this.state.telnum
  115. })(
  116. <Input placeholder="联系电话" />
  117. )}
  118. </FormItem>
  119. <FormItem className="half-item"
  120. {...formItemLayout}
  121. label="联系人部门" >
  122. <Input value={this.state.depatrments} placeholder="联系人部门"
  123. onChange={(e) => { this.setState({ depatrments: e.target.value }); }} />
  124. </FormItem>
  125. <FormItem className="half-item"
  126. {...formItemLayout}
  127. label="联系人职务" >
  128. <Input value={this.state.positions} placeholder="联系人职务"
  129. onChange={(e) => { this.setState({ positions: e.target.value }); }} />
  130. </FormItem>
  131. <FormItem className="half-item"
  132. {...formItemLayout}
  133. label="微信" >
  134. <Input value={this.state.wechats} placeholder="微信"
  135. onChange={(e) => { this.setState({ wechats: e.target.value }); }} />
  136. </FormItem>
  137. <FormItem className="half-item"
  138. {...formItemLayout}
  139. label="联系人QQ" >
  140. <Input value={this.state.qqs} placeholder="联系人QQ"
  141. onChange={(e) => { this.setState({ qqs: e.target.value }); }} />
  142. </FormItem>
  143. <FormItem className="half-item"
  144. {...formItemLayout}
  145. label="电子邮箱" >
  146. <Input value={this.state.emails} placeholder="电子邮箱"
  147. onChange={(e) => { this.setState({ emails: e.target.value }); }} />
  148. </FormItem>
  149. </div>
  150. <FormItem wrapperCol={{ span: 12, offset: 4 }}>
  151. <Button className="set-submit" type="primary" htmlType="submit">保存</Button>
  152. {/*<Button className="set-submit" type="primary" onClick={(e)=>{this.addContent();this.props.closeDesc}}>去完善</Button>*/}
  153. <Button className="set-submit" type="ghost" onClick={this.props.closeDesc}>取消</Button>
  154. </FormItem>
  155. </Spin>
  156. </Form >
  157. </div>
  158. )
  159. }
  160. }));
  161. const CustomerDetail = React.createClass({
  162. getInitialState() {
  163. return {
  164. visible: false,
  165. tabsKey: 1,
  166. loading: false,
  167. dataSource: [],
  168. };
  169. },
  170. handleCancel(e) {
  171. this.setState({
  172. visible: false,
  173. });
  174. this.props.closeDesc(false);
  175. },
  176. handleOk(e) {
  177. this.setState({
  178. visible: false,
  179. });
  180. this.props.closeDesc(false, true);
  181. },
  182. componentWillReceiveProps(nextProps) {
  183. if (!this.state.visible && nextProps.showDesc) {
  184. this.state.tabsKey = "1";
  185. };
  186. this.state.visible = nextProps.showDesc;
  187. },
  188. render() {
  189. return (
  190. <div className="patent-desc">
  191. <Modal maskClosable={false} visible={this.state.visible}
  192. onOk={this.checkPatentProcess} onCancel={this.handleCancel}
  193. width='800px'
  194. title='新建客户'
  195. footer=''
  196. className="admin-desc-content">
  197. <Spin spinning={this.state.loading}>
  198. <AchievementDetailForm
  199. data={this.props.data}
  200. newmodal={this.props.newmodal}
  201. closeDesc={this.handleCancel}
  202. visible={this.state.visible}
  203. handleOk={this.handleOk} />
  204. </Spin>
  205. </Modal>
  206. </div>
  207. );
  208. },
  209. });
  210. export default CustomerDetail;