myClientDesc.jsx 7.5 KB

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