addIntention.jsx 17 KB

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