addIntention.jsx 17 KB

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