addchannel.jsx 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528
  1. import React from "react";
  2. import {
  3. Modal,
  4. message,
  5. Spin,
  6. Input,
  7. Select,
  8. Button,
  9. Form,
  10. Col,
  11. Cascader,
  12. Tag,
  13. Tooltip,
  14. AutoComplete,
  15. Icon,
  16. } from "antd";
  17. import $ from "jquery/src/ajax";
  18. import { areaSelect } from "@/NewDicProvinceList";
  19. import { socialAttribute, customerSource } from "@/dataDic.js";
  20. import TextArea from "antd/es/input/TextArea";
  21. const confirm = Modal.confirm;
  22. const AchievementDetailForm = Form.create()(
  23. React.createClass({
  24. getInitialState() {
  25. return {
  26. loading: false,
  27. data: {},
  28. detailApi: "",
  29. businessScope: [],
  30. inputVisible: false,
  31. cooperationProjects: [],
  32. selectCooperationProjects: [],
  33. };
  34. },
  35. handleSubmit(e) {
  36. // this.props.closeDesc();
  37. e.preventDefault();
  38. this.props.form.validateFields((err, values) => {
  39. if (values.name.length > 64) {
  40. message.warning("渠道名称字数不超过64个");
  41. return false;
  42. }
  43. let regu =
  44. /[`~!#$%^&*'_[\]+=<>?:"{}|~!#¥%……&*=-@-!{}|/《》?:“”【】、;;‘’,,.。、\s+]/g;
  45. if (regu.test(values.name)) {
  46. message.warning("渠道名称不能存在特殊符号!");
  47. return false;
  48. }
  49. if (!values.channelType) {
  50. message.warning("请选择渠道类别");
  51. return false;
  52. }
  53. if (values.channelType != 1) {
  54. if (!values.ProvinceCity[1]) {
  55. message.warning("请选择地区");
  56. return false;
  57. }
  58. if (/.*[\u4e00-\u9fa5]+.*$/.test(values.contacts)) {
  59. } else {
  60. message.error("请填写正确的联系人,且至少包含一个汉字");
  61. return false;
  62. }
  63. if (values.contacts.length > 32) {
  64. message.warning("联系人字数不超过32个");
  65. return false;
  66. }
  67. if (/.*[\u4e00-\u9fa5]+.*$/.test(values.position)) {
  68. } else {
  69. message.error("请填写正确的职位,且至少包含一个汉字");
  70. return false;
  71. }
  72. if (values.contactMobile.length > 13) {
  73. message.warning("联系电话字数不超过13个");
  74. return false;
  75. }
  76. if (values.introduction.length === 0) {
  77. message.warning("请填写渠道简介");
  78. return false;
  79. }
  80. }
  81. // let arr = [];
  82. // for (let i of this.state.selectCooperationProjects) {
  83. // arr.push(i.label);
  84. // }
  85. if (!err) {
  86. this.setState({
  87. loading: true,
  88. });
  89. let info = values.channelType != 1 ?
  90. {
  91. name: values.name,
  92. channelType: values.channelType,
  93. province: values.ProvinceCity[0], //省
  94. city: values.ProvinceCity[1], //市
  95. area: values.ProvinceCity[2], //区
  96. contacts: values.contacts,
  97. position: values.position,
  98. contactMobile: values.contactMobile,
  99. introduction: values.introduction,
  100. } :
  101. {
  102. name: values.name,
  103. channelType: values.channelType,
  104. }
  105. $.ajax({
  106. method: "POST",
  107. dataType: "json",
  108. crossDomain: false,
  109. url: globalConfig.context + "/api/admin/customer/addChannel",
  110. data: info,
  111. }).done(
  112. function (data) {
  113. this.setState({
  114. loading: false,
  115. });
  116. if (!data.error.length) {
  117. message.success("保存成功!");
  118. // this.setState({
  119. // verification: false,
  120. // });
  121. this.props.closeDesc();
  122. } else {
  123. message.warning(data.error[0].message);
  124. }
  125. }.bind(this)
  126. );
  127. }
  128. });
  129. },
  130. componentWillMount() {
  131. this.state.name = "";
  132. this.state.content = "";
  133. this.state.position = "";
  134. this.state.telnum = "";
  135. // this.state.societyTagt='0';
  136. this.state.customerSource = "0";
  137. this.state.inputValue = "";
  138. this.state.businessScope = [];
  139. this.state.inputVisible = false;
  140. this.state.cooperationProjects = [];
  141. this.state.selectCooperationProjects = [];
  142. },
  143. componentWillReceiveProps(nextProps) {
  144. if (!this.props.visible && nextProps.visible) {
  145. this.state.name = "";
  146. this.state.content = "";
  147. this.state.position = "";
  148. this.state.telnum = "";
  149. this.state.inputValue = "";
  150. this.state.businessScope = [];
  151. this.state.inputVisible = false;
  152. this.state.cooperationProjects = [];
  153. this.state.selectCooperationProjects = [];
  154. // this.state.societyTagt='0';
  155. this.props.form.resetFields();
  156. }
  157. },
  158. handleClose(removedTag) {
  159. let businessScope = this.state.businessScope.filter((tag) => {
  160. return tag !== removedTag;
  161. });
  162. this.setState({ businessScope });
  163. },
  164. handleCloseCooperation(removedTag) {
  165. let selectCooperationProjects =
  166. this.state.selectCooperationProjects.filter((tag) => {
  167. return tag.value !== removedTag.value;
  168. });
  169. this.setState({ selectCooperationProjects });
  170. },
  171. showInput() {
  172. let str = this.state.businessScope.join("/");
  173. this.setState({
  174. inputVisible: true,
  175. inputValue: str,
  176. });
  177. },
  178. handleInputConfirm() {
  179. let inputValue = this.state.inputValue;
  180. let arr = inputValue.split("/");
  181. let lv = true;
  182. for (let i of arr) {
  183. if (i.length > 16) {
  184. message.warning("单个标签字数不能超过16个字符");
  185. lv = false;
  186. return;
  187. }
  188. }
  189. if (lv) {
  190. arr = Array.from(new Set(arr));
  191. arr = arr.filter((v) => v);
  192. this.setState({
  193. businessScope: arr,
  194. inputVisible: false,
  195. inputValue: "",
  196. });
  197. }
  198. },
  199. //加载(自动补全)
  200. supervisor(value) {
  201. $.ajax({
  202. method: "get",
  203. dataType: "json",
  204. crossDomain: false,
  205. url: globalConfig.context + "/api/admin/order/getBusinessProjectByName",
  206. data: {
  207. businessName: value,
  208. },
  209. success: function (data) {
  210. let thedata = data.data;
  211. if (data.error.length === 0) {
  212. this.setState({
  213. cooperationProjects: thedata,
  214. });
  215. } else {
  216. message.warning(data.error[0].message);
  217. }
  218. }.bind(this),
  219. }).always(function () { }.bind(this));
  220. },
  221. onSelect(value) {
  222. let arr = this.state.cooperationProjects.filter((v) => v.id === value);
  223. let arr1 = this.state.selectCooperationProjects.filter(
  224. (v) => v.value === value
  225. );
  226. if (arr.length > 0) {
  227. if (arr1.length > 0) {
  228. message.warning("选项已存在");
  229. } else {
  230. this.state.selectCooperationProjects.push({
  231. label: arr[0].bname,
  232. value: arr[0].id,
  233. });
  234. this.setState({
  235. selectCooperationProjects: this.state.selectCooperationProjects,
  236. });
  237. }
  238. }
  239. },
  240. checkUserName() {
  241. this.setState({
  242. verification: false,
  243. });
  244. if (!this.props.form.getFieldValue("name")) {
  245. message.warning("请输入公司名称");
  246. return;
  247. }
  248. $.ajax({
  249. method: "get",
  250. dataType: "json",
  251. crossDomain: false,
  252. url: globalConfig.context + "/api/admin/customer/checkUserName",
  253. data: {
  254. userName: this.props.form.getFieldValue("name"),
  255. },
  256. success: function (data) {
  257. if (data.error.length === 0) {
  258. if (!data.data) {
  259. this.setState({
  260. verification: true,
  261. });
  262. } else {
  263. Modal.info({
  264. title: "提醒",
  265. content: (
  266. <div>
  267. <p style={{ color: "red" }}>
  268. 企业客户已存在!请在“客户管理-企业客户-企业客户查询”输入企业全称查询所属人信息
  269. </p>
  270. </div>
  271. ),
  272. });
  273. this.setState({
  274. verification: false,
  275. });
  276. }
  277. } else {
  278. message.warning(data.error[0].message);
  279. }
  280. }.bind(this),
  281. }).always(function () { }.bind(this));
  282. },
  283. render() {
  284. const theData = this.state.data || {};
  285. const { getFieldDecorator, getFieldsValue } = this.props.form;
  286. const FormItem = Form.Item;
  287. const formItemLayout = {
  288. labelCol: { span: 6 },
  289. wrapperCol: { span: 14 },
  290. };
  291. return (
  292. <div>
  293. <Form
  294. layout="horizontal"
  295. onSubmit={this.handleSubmit}
  296. id="demand-form"
  297. >
  298. <Spin spinning={this.state.loading}>
  299. <div>
  300. <div className="clearfix">
  301. <FormItem
  302. className="mid-item"
  303. {...formItemLayout}
  304. label="渠道名称"
  305. >
  306. {getFieldDecorator("name", {
  307. rules: [{ required: true, message: "此项为必填项!" }],
  308. initialValue: this.state.name,
  309. })(
  310. <span
  311. style={{
  312. display: "flex",
  313. alignItems: "center",
  314. position: "relative",
  315. }}
  316. >
  317. <Input placeholder="渠道名称" />
  318. {this.state.verification && (
  319. <Icon
  320. type="check-circle"
  321. style={{
  322. fontSize: 16,
  323. color: "#30e031",
  324. position: "absolute",
  325. right: "80px",
  326. }}
  327. />
  328. )}
  329. <Button
  330. onClick={this.checkUserName}
  331. type="primary"
  332. style={{ marginLeft: "10px" }}
  333. >
  334. 验证
  335. </Button>
  336. </span>
  337. )}
  338. </FormItem>
  339. </div>
  340. <div className="clearfix">
  341. <FormItem
  342. className="mid-item"
  343. {...formItemLayout}
  344. label="渠道类别"
  345. >
  346. {getFieldDecorator("channelType", {
  347. rules: [{ required: true, message: "此项为必填项!" }],
  348. initialValue: this.state.channelType,
  349. })(
  350. <Select placeholder="请选择">
  351. <Select.Option value={2}>民主党派</Select.Option>
  352. <Select.Option value={3}>园区</Select.Option>
  353. <Select.Option value={4}>民间组织</Select.Option>
  354. <Select.Option value={5}>战略合作单位</Select.Option>
  355. <Select.Option value={1}>其他</Select.Option>
  356. </Select>
  357. )}
  358. </FormItem>
  359. </div>
  360. {
  361. !!getFieldsValue().channelType && getFieldsValue().channelType != 1 &&
  362. <div className="clearfix">
  363. <FormItem {...formItemLayout} label="省-市-区">
  364. {getFieldDecorator("ProvinceCity", {
  365. rules: [{ required: true, message: "此项为必填项!" }],
  366. initialValue: this.state.ProvinceCity,
  367. })(
  368. <Cascader options={areaSelect()} placeholder="选择城市" />
  369. )}
  370. </FormItem>
  371. </div>
  372. }
  373. {
  374. !!getFieldsValue().channelType && getFieldsValue().channelType != 1 &&
  375. <div className="clearfix">
  376. <FormItem
  377. className="mid-item"
  378. {...formItemLayout}
  379. label="联系人"
  380. >
  381. {getFieldDecorator("contacts", {
  382. rules: [{ required: true, message: "此项为必填项!" }],
  383. initialValue: this.state.contacts,
  384. })(<Input placeholder="联系人姓名" />)}
  385. </FormItem>
  386. </div>
  387. }
  388. {
  389. !!getFieldsValue().channelType && getFieldsValue().channelType != 1 &&
  390. <div className="clearfix">
  391. <FormItem
  392. className="mid-item"
  393. {...formItemLayout}
  394. label="职位"
  395. >
  396. {getFieldDecorator("position", {
  397. rules: [{ required: true, message: "此项为必填项!" }],
  398. initialValue: this.state.position,
  399. })(<Input placeholder="联系人职位" />)}
  400. </FormItem>
  401. </div>
  402. }
  403. {
  404. !!getFieldsValue().channelType && getFieldsValue().channelType != 1 &&
  405. <div className="clearfix">
  406. <FormItem
  407. className="mid-item"
  408. {...formItemLayout}
  409. label="联系电话"
  410. >
  411. {getFieldDecorator("contactMobile", {
  412. rules: [{ required: true, message: "此项为必填项!" }],
  413. initialValue: this.state.contactMobile,
  414. })(
  415. <Input placeholder="请填写手机号,仅填座机号时,请后续补充手机号" />
  416. )}
  417. </FormItem>
  418. </div>
  419. }
  420. {
  421. !!getFieldsValue().channelType && getFieldsValue().channelType != 1 &&
  422. <div className="clearfix">
  423. <FormItem
  424. className="mid-item"
  425. {...formItemLayout}
  426. required
  427. label="渠道简介"
  428. >
  429. {getFieldDecorator("introduction", {
  430. rules: [{ required: true, message: "此项为必填项!" }],
  431. initialValue: this.state.introduction,
  432. })(
  433. <TextArea
  434. style={{ width: "330px", height: "100px" }}
  435. placeholder="请填写渠道简介"
  436. value={this.state.inputValue}
  437. onChange={(e) => {
  438. this.setState({
  439. inputValue: e.target.value,
  440. });
  441. }}
  442. />
  443. )}
  444. </FormItem>
  445. </div>
  446. }
  447. </div>
  448. <FormItem wrapperCol={{ span: 12, offset: 6 }}>
  449. <Button
  450. type="primary"
  451. htmlType="submit"
  452. style={{ marginRight: "50px" }}
  453. >
  454. 保存
  455. </Button>
  456. <Button type="ghost" onClick={this.props.closeDesc}>
  457. 取消
  458. </Button>
  459. </FormItem>
  460. </Spin>
  461. </Form>
  462. </div>
  463. );
  464. },
  465. })
  466. );
  467. const AddChannel = React.createClass({
  468. getInitialState() {
  469. return {
  470. visible: false,
  471. tabsKey: 1,
  472. loading: false,
  473. dataSource: [],
  474. };
  475. },
  476. handleCancel(e) {
  477. this.props.closeDesc();
  478. },
  479. handleOk(e) {
  480. this.setState({
  481. visible: false,
  482. });
  483. this.props.closeDesc();
  484. // this.props.closeDesc(false, true);
  485. },
  486. componentWillReceiveProps(nextProps) {
  487. if (!this.state.visible && nextProps.showDesc) {
  488. this.state.tabsKey = "1";
  489. }
  490. this.state.visible = nextProps.showDesc;
  491. },
  492. render() {
  493. const { showDesc } = this.props;
  494. return (
  495. <div className="patent-desc">
  496. <Modal
  497. maskClosable={false}
  498. visible={showDesc == "add"}
  499. onOk={this.checkPatentProcess}
  500. onCancel={this.handleCancel}
  501. width="600px"
  502. title="新建渠道"
  503. footer=""
  504. className="admin-desc-content"
  505. >
  506. <Spin spinning={this.state.loading}>
  507. <AchievementDetailForm
  508. data={this.props.data}
  509. newmodal={this.props.newmodal}
  510. closeDesc={this.handleCancel}
  511. visible={this.state.visible}
  512. handleOk={this.handleOk}
  513. />
  514. </Spin>
  515. </Modal>
  516. </div>
  517. );
  518. },
  519. });
  520. export default Form.create({})(AddChannel);