addIntention.jsx 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415
  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>
  168. <FormItem wrapperCol={{ span: 12, offset: 6 }}>
  169. <Button type="primary" htmlType="submit" style={{marginRight:'50px'}}>保存</Button>
  170. <Button type="ghost" onClick={this.props.closeDesc}>取消</Button>
  171. </FormItem>
  172. </Spin>
  173. </Form >
  174. </div>
  175. )
  176. }
  177. }));
  178. const AddPerson = Form.create()(React.createClass({
  179. getInitialState() {
  180. return {
  181. loading: false,
  182. data: {},
  183. detailApi:''
  184. };
  185. },
  186. handleSubmit(e) {
  187. e.preventDefault();
  188. this.props.form.validateFields((err, values) => {
  189. if(values.companyNamet.length>64){
  190. message.warning('联系人字数不超过64个')
  191. return false;
  192. };
  193. if(!values.ProvinceCity[1]) {
  194. message.warning('请选择地区');
  195. return false;
  196. };
  197. if(values.telnums.length>13){
  198. message.warning('电话号码字数不超过13个')
  199. return false;
  200. };
  201. if (!err) {
  202. this.setState({
  203. loading: true
  204. });
  205. $.ajax({
  206. method: "POST",
  207. dataType: "json",
  208. crossDomain: false,
  209. url: globalConfig.context + '/api/admin/customer/addCustomer',
  210. data: {
  211. contacts:values.companyNamet,
  212. societyTag:values.societyTagt,
  213. name: values.companyNamet,
  214. contactMobile: values.telnums,
  215. source:values.customerSource,
  216. province:(values.ProvinceCity)[0],//省
  217. city:(values.ProvinceCity)[1],//市
  218. area:(values.ProvinceCity)[2],//区
  219. type:'0'
  220. }
  221. }).done(function (data) {
  222. this.setState({
  223. loading: false
  224. });
  225. if (!data.error.length) {
  226. message.success('保存成功!');
  227. this.props.handleOk();
  228. } else {
  229. message.warning(data.error[0].message);
  230. }
  231. }.bind(this));
  232. }
  233. });
  234. },
  235. componentWillMount() {
  236. this.state.companyNamet='';
  237. this.state.telnum='';
  238. this.state.societyTagt='0';
  239. this.state.customerSource='0';
  240. },
  241. componentWillReceiveProps(nextProps) {
  242. if (!this.props.visible && nextProps.visible) {
  243. this.state.companyNamet='';
  244. this.state.telnum='';
  245. this.state.societyTagt='0';
  246. this.state.customerSource='0';
  247. this.props.form.resetFields();
  248. };
  249. },
  250. render() {
  251. const theData = this.state.data || {};
  252. const { getFieldDecorator } = this.props.form;
  253. const FormItem = Form.Item
  254. const formItemLayout = {
  255. labelCol: { span: 6 },
  256. wrapperCol: { span: 14 },
  257. };
  258. return (
  259. <div>
  260. <Form layout="horizontal" onSubmit={this.handleSubmit} id="demand-form">
  261. <Spin spinning={this.state.loading}>
  262. <Col style={{color:'red',marginBottom:'10px'}} span={12} offset={6}>注意:请录入真实有效的客户信息</Col>
  263. <div className="clearfix">
  264. <FormItem className="mid-item"
  265. {...formItemLayout}
  266. label="客户姓名" >
  267. {getFieldDecorator('companyNamet', {
  268. rules: [{ required: true, message: '此项为必填项!' }],
  269. initialValue: this.state.companyNamet
  270. })(
  271. <Input placeholder="客户姓名" />
  272. )}
  273. </FormItem>
  274. </div>
  275. <div className="clearfix">
  276. <FormItem
  277. {...formItemLayout}
  278. label="省-市-区"
  279. >
  280. {getFieldDecorator('ProvinceCity', {
  281. rules: [{ required: true, message: '此项为必填项!' }],
  282. initialValue: this.state.ProvinceCity
  283. })(
  284. <Cascader options={areaSelect()} placeholder="选择城市" />
  285. )}
  286. </FormItem>
  287. </div>
  288. <div className="clearfix">
  289. <FormItem className="mid-item"
  290. {...formItemLayout}
  291. label="联系电话" >
  292. {getFieldDecorator('telnums', {
  293. rules: [{ required: true, message: '此项为必填项!' }],
  294. initialValue: this.state.telnums
  295. })(
  296. <Input placeholder="联系电话" />
  297. )}
  298. </FormItem>
  299. </div>
  300. <div className="clearfix">
  301. <FormItem className="mid-item"
  302. {...formItemLayout}
  303. label="社会属性"
  304. >
  305. {getFieldDecorator('societyTagt', {
  306. rules: [{ required: true, message: '此项为必填项!' }],
  307. initialValue: this.state.societyTagt
  308. })(
  309. <Select placeholder="客户社会属性">
  310. {
  311. socialAttribute.map(function (item) {
  312. return <Select.Option key={item.value} >{item.key}</Select.Option>
  313. })
  314. }
  315. </Select>
  316. )}
  317. </FormItem>
  318. </div>
  319. <div className="clearfix">
  320. <FormItem className="mid-item"
  321. {...formItemLayout}
  322. label="客户来源"
  323. >
  324. {getFieldDecorator('customerSource', {
  325. rules: [{ required: true, message: '此项为必填项!' }],
  326. initialValue: this.state.customerSource
  327. })(
  328. <Select placeholder="客户来源">
  329. {
  330. customerSource.map(function (item) {
  331. return <Select.Option key={item.value} >{item.key}</Select.Option>
  332. })
  333. }
  334. </Select>
  335. )}
  336. </FormItem>
  337. </div>
  338. <FormItem wrapperCol={{ span: 12, offset: 6 }}>
  339. <Button style={{marginRight:'50px'}} type="primary" htmlType="submit">保存</Button>
  340. <Button type="ghost" onClick={this.props.closeDesc}>取消</Button>
  341. </FormItem>
  342. </Spin>
  343. </Form >
  344. </div>
  345. )
  346. }
  347. }));
  348. const AddIntention = React.createClass({
  349. getInitialState() {
  350. return {
  351. visible: false,
  352. tabsKey: 1,
  353. loading: false,
  354. dataSource: [],
  355. };
  356. },
  357. handleCancel(e) {
  358. this.setState({
  359. visible: false,
  360. });
  361. this.props.closeDesc(false);
  362. },
  363. handleOk(e) {
  364. this.setState({
  365. visible: false,
  366. });
  367. this.props.closeDesc(false, true);
  368. },
  369. componentWillReceiveProps(nextProps) {
  370. if (!this.state.visible && nextProps.showDesc) {
  371. this.state.tabsKey = "1";
  372. };
  373. this.state.visible = nextProps.showDesc;
  374. },
  375. render() {
  376. return (
  377. <div className="patent-desc">
  378. <Modal maskClosable={false} visible={this.state.visible}
  379. onOk={this.checkPatentProcess} onCancel={this.handleCancel}
  380. width='600px'
  381. title='新建客户'
  382. footer=''
  383. className="admin-desc-content">
  384. <Spin spinning={this.state.loading}>
  385. {this.props.api.indexOf('Personal')<0?<AchievementDetailForm
  386. data={this.props.data}
  387. newmodal={this.props.newmodal}
  388. closeDesc={this.handleCancel}
  389. visible={this.state.visible}
  390. handleOk={this.handleOk} />:<AddPerson
  391. data={this.props.data}
  392. newmodal={this.props.newmodal}
  393. closeDesc={this.handleCancel}
  394. visible={this.state.visible}
  395. handleOk={this.handleOk}
  396. />}
  397. </Spin>
  398. </Modal>
  399. </div>
  400. );
  401. },
  402. });
  403. export default AddIntention;