addIntention.jsx 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394
  1. import React from 'react';
  2. import { Icon, Modal, message, Spin, Input, Select, Button, Form ,Col} from 'antd';
  3. import './myClient.less';
  4. import ajax from 'jquery/src/ajax/xhr.js';
  5. import $ from 'jquery/src/ajax';
  6. import {socialAttribute,customerSource} from '@/dataDic.js';
  7. const AchievementDetailForm = Form.create()(React.createClass({
  8. getInitialState() {
  9. return {
  10. loading: false,
  11. data: {},
  12. detailApi:''
  13. };
  14. },
  15. handleSubmit(e) {
  16. e.preventDefault();
  17. this.props.form.validateFields((err, values) => {
  18. if(values.name.length>64){
  19. message.warning('客户名称字数不超过64个')
  20. return false;
  21. };
  22. if(values.content.length>32){
  23. message.warning('联系人字数不超过32个')
  24. return false;
  25. };
  26. if(values.length>13){
  27. message.warning('电话号码字数不超过13个')
  28. return false;
  29. };
  30. if (!err) {
  31. this.setState({
  32. loading: true
  33. });
  34. $.ajax({
  35. method: "POST",
  36. dataType: "json",
  37. crossDomain: false,
  38. url: globalConfig.context + '/api/admin/customer/addCustomer',
  39. data: {
  40. name: values.name,
  41. contacts:values.content,
  42. contactMobile:values.telnum,
  43. societyTag:values.societyTagt,
  44. source:values.customerSource,
  45. type:'1'
  46. }
  47. }).done(function (data) {
  48. this.setState({
  49. loading: false
  50. });
  51. if (!data.error.length) {
  52. message.success('保存成功!');
  53. this.props.handleOk();
  54. } else {
  55. message.warning(data.error[0].message);
  56. }
  57. }.bind(this));
  58. }
  59. });
  60. },
  61. componentWillMount() {
  62. this.state.name='';
  63. this.state.content='';
  64. this.state.telnum='';
  65. this.state.societyTagt=undefined;
  66. this.state.customerSource='0'
  67. },
  68. componentWillReceiveProps(nextProps) {
  69. if (!this.props.visible && nextProps.visible) {
  70. this.state.name='';
  71. this.state.content='';
  72. this.state.telnum='';
  73. this.state.societyTagt=undefined;
  74. this.props.form.resetFields();
  75. };
  76. },
  77. render() {
  78. const theData = this.state.data || {};
  79. const { getFieldDecorator } = this.props.form;
  80. const FormItem = Form.Item
  81. const formItemLayout = {
  82. labelCol: { span: 6 },
  83. wrapperCol: { span: 14 },
  84. };
  85. return (
  86. <div>
  87. <Form layout="horizontal" onSubmit={this.handleSubmit} id="demand-form">
  88. <Spin spinning={this.state.loading}>
  89. <div>
  90. <Col style={{color:'red',marginBottom:'10px'}} span={12} offset={6}>注:请录入真实有效的客户信息</Col>
  91. <div className="clearfix">
  92. <FormItem className="mid-item"
  93. {...formItemLayout}
  94. label="公司名称" >
  95. {getFieldDecorator('name', {
  96. rules: [{ required: true, message: '此项为必填项!' }],
  97. initialValue: this.state.name
  98. })(
  99. <Input placeholder="公司名称" />
  100. )}
  101. </FormItem>
  102. </div>
  103. <div className="clearfix">
  104. <FormItem className="mid-item"
  105. {...formItemLayout}
  106. label="联系人" >
  107. {getFieldDecorator('content', {
  108. rules: [{ required: true, message: '此项为必填项!' }],
  109. initialValue: this.state.content
  110. })(
  111. <Input placeholder="联系人" />
  112. )}
  113. </FormItem>
  114. </div>
  115. <div className="clearfix">
  116. <FormItem className="mid-item"
  117. {...formItemLayout}
  118. label="联系电话" >
  119. {getFieldDecorator('telnum', {
  120. rules: [{ required: true, message: '此项为必填项!' }],
  121. initialValue: this.state.telnum
  122. })(
  123. <Input placeholder="联系电话" />
  124. )}
  125. </FormItem>
  126. </div>
  127. <div className="clearfix">
  128. <FormItem className="mid-item"
  129. {...formItemLayout}
  130. label="社会属性"
  131. >
  132. {getFieldDecorator('societyTagt', {
  133. rules: [{ required: true, message: '此项为必填项!' }],
  134. initialValue: this.state.societyTagt
  135. })(
  136. <Select placeholder="客户社会属性">
  137. {
  138. socialAttribute.map(function (item) {
  139. return <Select.Option key={item.value} >{item.key}</Select.Option>
  140. })
  141. }
  142. </Select>
  143. )}
  144. </FormItem>
  145. </div>
  146. <div className="clearfix">
  147. <FormItem className="mid-item"
  148. {...formItemLayout}
  149. label="客户来源"
  150. >
  151. {getFieldDecorator('customerSource', {
  152. rules: [{ required: true, message: '此项为必填项!' }],
  153. initialValue: this.state.customerSource
  154. })(
  155. <Select placeholder="客户来源">
  156. {
  157. customerSource.map(function (item) {
  158. return <Select.Option key={item.value} >{item.key}</Select.Option>
  159. })
  160. }
  161. </Select>
  162. )}
  163. </FormItem>
  164. </div>
  165. </div>
  166. <FormItem wrapperCol={{ span: 12, offset: 6 }}>
  167. <Button type="primary" htmlType="submit" style={{marginRight:'50px'}}>保存</Button>
  168. <Button type="ghost" onClick={this.props.closeDesc}>取消</Button>
  169. </FormItem>
  170. </Spin>
  171. </Form >
  172. </div>
  173. )
  174. }
  175. }));
  176. const AddPerson = Form.create()(React.createClass({
  177. getInitialState() {
  178. return {
  179. loading: false,
  180. data: {},
  181. detailApi:''
  182. };
  183. },
  184. handleSubmit(e) {
  185. e.preventDefault();
  186. this.props.form.validateFields((err, values) => {
  187. if(values.companyNamet.length>64){
  188. message.warning('联系人字数不超过64个')
  189. return false;
  190. };
  191. if(values.telnums.length>13){
  192. message.warning('电话号码字数不超过13个')
  193. return false;
  194. };
  195. if (!err) {
  196. this.setState({
  197. loading: true
  198. });
  199. $.ajax({
  200. method: "POST",
  201. dataType: "json",
  202. crossDomain: false,
  203. url: globalConfig.context + '/api/admin/customer/addCustomer',
  204. data: {
  205. contacts:values.companyNamet,
  206. societyTag:values.societyTagt,
  207. name: values.companyNamet,
  208. contactMobile: values.telnums,
  209. source:values.customerSource,
  210. type:'0'
  211. }
  212. }).done(function (data) {
  213. this.setState({
  214. loading: false
  215. });
  216. if (!data.error.length) {
  217. message.success('保存成功!');
  218. this.props.handleOk();
  219. } else {
  220. message.warning(data.error[0].message);
  221. }
  222. }.bind(this));
  223. }
  224. });
  225. },
  226. componentWillMount() {
  227. this.state.companyNamet='';
  228. this.state.telnum='';
  229. this.state.societyTagt=undefined;
  230. this.state.customerSource='0';
  231. },
  232. componentWillReceiveProps(nextProps) {
  233. if (!this.props.visible && nextProps.visible) {
  234. this.state.companyNamet='';
  235. this.state.telnum='';
  236. this.state.societyTagt=undefined;
  237. this.state.customerSource='0';
  238. this.props.form.resetFields();
  239. };
  240. },
  241. render() {
  242. const theData = this.state.data || {};
  243. const { getFieldDecorator } = this.props.form;
  244. const FormItem = Form.Item
  245. const formItemLayout = {
  246. labelCol: { span: 6 },
  247. wrapperCol: { span: 14 },
  248. };
  249. return (
  250. <div>
  251. <Form layout="horizontal" onSubmit={this.handleSubmit} id="demand-form">
  252. <Spin spinning={this.state.loading}>
  253. <Col style={{color:'red',marginBottom:'10px'}} span={12} offset={6}>注:请录入真实有效的客户信息</Col>
  254. <div className="clearfix">
  255. <FormItem className="mid-item"
  256. {...formItemLayout}
  257. label="客户姓名" >
  258. {getFieldDecorator('companyNamet', {
  259. rules: [{ required: true, message: '此项为必填项!' }],
  260. initialValue: this.state.companyNamet
  261. })(
  262. <Input placeholder="客户姓名" />
  263. )}
  264. </FormItem>
  265. </div>
  266. <div className="clearfix">
  267. <FormItem className="mid-item"
  268. {...formItemLayout}
  269. label="联系电话" >
  270. {getFieldDecorator('telnums', {
  271. rules: [{ required: true, message: '此项为必填项!' }],
  272. initialValue: this.state.telnums
  273. })(
  274. <Input placeholder="联系电话" />
  275. )}
  276. </FormItem>
  277. </div>
  278. <div className="clearfix">
  279. <FormItem className="mid-item"
  280. {...formItemLayout}
  281. label="社会属性"
  282. >
  283. {getFieldDecorator('societyTagt', {
  284. rules: [{ required: true, message: '此项为必填项!' }],
  285. initialValue: this.state.societyTagt
  286. })(
  287. <Select placeholder="客户社会属性">
  288. {
  289. socialAttribute.map(function (item) {
  290. return <Select.Option key={item.value} >{item.key}</Select.Option>
  291. })
  292. }
  293. </Select>
  294. )}
  295. </FormItem>
  296. </div>
  297. <div className="clearfix">
  298. <FormItem className="mid-item"
  299. {...formItemLayout}
  300. label="客户来源"
  301. >
  302. {getFieldDecorator('customerSource', {
  303. rules: [{ required: true, message: '此项为必填项!' }],
  304. initialValue: this.state.customerSource
  305. })(
  306. <Select placeholder="客户来源">
  307. {
  308. customerSource.map(function (item) {
  309. return <Select.Option key={item.value} >{item.key}</Select.Option>
  310. })
  311. }
  312. </Select>
  313. )}
  314. </FormItem>
  315. </div>
  316. <FormItem wrapperCol={{ span: 12, offset: 6 }}>
  317. <Button style={{marginRight:'50px'}} type="primary" htmlType="submit">保存</Button>
  318. <Button type="ghost" onClick={this.props.closeDesc}>取消</Button>
  319. </FormItem>
  320. </Spin>
  321. </Form >
  322. </div>
  323. )
  324. }
  325. }));
  326. const AddIntention = React.createClass({
  327. getInitialState() {
  328. return {
  329. visible: false,
  330. tabsKey: 1,
  331. loading: false,
  332. dataSource: [],
  333. };
  334. },
  335. handleCancel(e) {
  336. this.setState({
  337. visible: false,
  338. });
  339. this.props.closeDesc(false);
  340. },
  341. handleOk(e) {
  342. this.setState({
  343. visible: false,
  344. });
  345. this.props.closeDesc(false, true);
  346. },
  347. componentWillReceiveProps(nextProps) {
  348. if (!this.state.visible && nextProps.showDesc) {
  349. this.state.tabsKey = "1";
  350. };
  351. this.state.visible = nextProps.showDesc;
  352. },
  353. render() {
  354. return (
  355. <div className="patent-desc">
  356. <Modal maskClosable={false} visible={this.state.visible}
  357. onOk={this.checkPatentProcess} onCancel={this.handleCancel}
  358. width='600px'
  359. title='新建客户'
  360. footer=''
  361. className="admin-desc-content">
  362. <Spin spinning={this.state.loading}>
  363. {this.props.api.indexOf('Personal')<0?<AchievementDetailForm
  364. data={this.props.data}
  365. newmodal={this.props.newmodal}
  366. closeDesc={this.handleCancel}
  367. visible={this.state.visible}
  368. handleOk={this.handleOk} />:<AddPerson
  369. data={this.props.data}
  370. newmodal={this.props.newmodal}
  371. closeDesc={this.handleCancel}
  372. visible={this.state.visible}
  373. handleOk={this.handleOk}
  374. />}
  375. </Spin>
  376. </Modal>
  377. </div>
  378. );
  379. },
  380. });
  381. export default AddIntention;