contactPerson.jsx 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717
  1. import React from "react";
  2. import {
  3. Table,
  4. Button,
  5. Spin,
  6. message,
  7. Popconfirm,
  8. Alert,
  9. Modal,
  10. Input,
  11. Cascader,
  12. Select,
  13. } from "antd";
  14. import $ from "jquery/src/ajax";
  15. import AddContact from "../../../customer/NEW/signCustomer/followDetail/addContact";
  16. import "./index.less";
  17. import { areaSelect, getProvince } from "@/NewDicProvinceList";
  18. const TextArea = Input.TextArea;
  19. const Option = Select.Option;
  20. const ContactPerson = React.createClass({
  21. getInitialState() {
  22. return {
  23. major: 0,
  24. loading: false,
  25. addcontactModul: false,
  26. enterpriseName: "",
  27. ContactsLists: [
  28. {
  29. title: "姓名",
  30. dataIndex: "name",
  31. key: "name",
  32. render: (text, record, index) => {
  33. if (record.id) return <div>{text}</div>;
  34. },
  35. },
  36. {
  37. title: "联系人部门",
  38. dataIndex: "department",
  39. key: "department",
  40. render: (text, record, index) => {
  41. if (record.id) return <div>{text}</div>;
  42. },
  43. },
  44. {
  45. title: "联系人职务",
  46. dataIndex: "position",
  47. key: "position",
  48. render: (text, record, index) => {
  49. if (record.id) return <div>{text}</div>;
  50. },
  51. },
  52. {
  53. title: "主要联系人",
  54. dataIndex: "major",
  55. width: 100,
  56. key: "major",
  57. render: (text) => {
  58. return text == 1 ? "是" : "否";
  59. },
  60. },
  61. {
  62. title: "地区",
  63. dataIndex: "cityName",
  64. key: "cityName",
  65. render: (text, record, index) => {
  66. if (record.id) return <div>{text}</div>;
  67. },
  68. },
  69. {
  70. title: "手机号码",
  71. dataIndex: "mobile",
  72. key: "mobile",
  73. render: (text, record, index) => {
  74. if (record.id) return <div>{text}</div>;
  75. },
  76. },
  77. {
  78. title: "座机",
  79. dataIndex: "fixedTel",
  80. key: "fixedTel",
  81. render: (text, record, index) => {
  82. if (record.id) return <div>{text}</div>;
  83. },
  84. },
  85. {
  86. title: "微信",
  87. dataIndex: "wechat",
  88. key: "wechat",
  89. render: (text, record, index) => {
  90. if (record.id) return <div>{text}</div>;
  91. },
  92. },
  93. {
  94. title: "联系人QQ",
  95. dataIndex: "qq",
  96. key: "qq",
  97. render: (text, record, index) => {
  98. if (record.id) return <div>{text}</div>;
  99. },
  100. },
  101. {
  102. title: "电子邮箱",
  103. dataIndex: "email",
  104. key: "email",
  105. render: (text, record, index) => {
  106. if (record.id) return <div>{text}</div>;
  107. },
  108. },
  109. {
  110. title: "更新时间",
  111. dataIndex: "createTimes",
  112. key: "createTimes",
  113. render: (text, record, index) => {
  114. if (record.id) return <div>{text}</div>;
  115. },
  116. },
  117. {
  118. title: "跟进人",
  119. dataIndex: "aname",
  120. key: "aname",
  121. render: (text, record, index) => {
  122. if (record.id) return <div>{text}</div>;
  123. },
  124. },
  125. {
  126. title: "操作",
  127. dataIndex: "dels",
  128. key: "dels",
  129. render: (text, record, index) => {
  130. return (
  131. !this.props.isCustomerAdmin && (
  132. <div>
  133. {/* 禁止管理员删除联系人 */}
  134. {/* {adminData.isSuperAdmin || !record.id ? (
  135. <Popconfirm
  136. title="是否删除?"
  137. onConfirm={(e) => {
  138. this.confirmDelet(record);
  139. }}
  140. okText="删除"
  141. cancelText="不删除"
  142. >
  143. <Button
  144. style={{
  145. marginRight: "10px",
  146. color: "#ffffff",
  147. background: "#f00",
  148. border: "none",
  149. }}
  150. >
  151. 删除
  152. </Button>
  153. </Popconfirm>
  154. ) : (
  155. ""
  156. )} */}
  157. {record.major != 1 ? (
  158. <Button
  159. style={{
  160. marginRight: "10px",
  161. color: "#ffffff",
  162. background: "green",
  163. border: "none",
  164. }}
  165. onClick={(e) => {
  166. e.stopPropagation(), this.mainContact(record);
  167. }}
  168. >
  169. 设为主要联系人
  170. </Button>
  171. ) : (
  172. ""
  173. )}
  174. </div>
  175. )
  176. );
  177. },
  178. },
  179. ],
  180. channeOb: [
  181. { name: "民主党派", val: 2 },
  182. { name: "园区", val: 3 },
  183. { name: "民间组织", val: 4 },
  184. { name: "战略合作单位", val: 5 },
  185. { name: "其他", val: 1 },
  186. ],
  187. visible: "", //修改弹窗状态
  188. name: "",
  189. locationProvince: "",
  190. introduction: "",
  191. newname: "",
  192. dataArrar: [],
  193. newintroduction: "",
  194. newtype: 0,
  195. };
  196. },
  197. //tab2删除
  198. confirmDelet(e) {
  199. this.setState({
  200. loading: true,
  201. });
  202. if (e.id) {
  203. $.ajax({
  204. method: "get",
  205. dataType: "json",
  206. crossDomain: false,
  207. url: globalConfig.context + "/api/admin/customer/deleteOneContact",
  208. data: {
  209. ocbId: e.id, //删除的ID
  210. },
  211. }).done(
  212. function (data) {
  213. if (!data.error.length) {
  214. message.success("删除成功!");
  215. this.setState({
  216. loading: false,
  217. });
  218. } else {
  219. message.warning(data.error[0].message);
  220. }
  221. this.contactLists();
  222. }.bind(this)
  223. );
  224. } else {
  225. this.contactLists();
  226. }
  227. },
  228. //选择主要联系人
  229. mainContact(record) {
  230. this.setState({
  231. loading: true,
  232. });
  233. $.ajax({
  234. method: "get",
  235. dataType: "json",
  236. crossDomain: false,
  237. url: globalConfig.context + "/api/admin/customer/updateMainContact",
  238. data: {
  239. uid: this.props.data.id,
  240. ocbId: record.id,
  241. },
  242. }).done(
  243. function (data) {
  244. if (!data.error.length) {
  245. message.success("设为主要联系人成功!");
  246. this.setState({
  247. loading: false,
  248. });
  249. } else {
  250. message.warning(data.error[0].message);
  251. }
  252. this.contactLists();
  253. }.bind(this)
  254. );
  255. this.state.contactList.forEach((item) => {
  256. item.major = 0;
  257. });
  258. record.major = 1;
  259. // console.log(record);
  260. this.setState({
  261. contactList: this.state.contactList,
  262. });
  263. },
  264. //tab2获取联系人详情
  265. contactLists(ids) {
  266. this.setState({
  267. loading: true,
  268. });
  269. $.ajax({
  270. method: "get",
  271. dataType: "json",
  272. crossDomain: false,
  273. url: globalConfig.context + "/api/admin/customer/findCustomerContacts",
  274. data: {
  275. uid: ids || this.props.data.id, //名称1
  276. },
  277. success: function (data) {
  278. let theArr = [];
  279. if (data.error.length || data.data.list == "") {
  280. if (data.error && data.error.length) {
  281. message.warning(data.error[0].message);
  282. }
  283. } else {
  284. for (let i = 0; i < data.data.length; i++) {
  285. let thisdata = data.data[i];
  286. theArr.push({
  287. key: i,
  288. id: thisdata.id,
  289. name: thisdata.name,
  290. mobile: thisdata.mobile,
  291. email: thisdata.email,
  292. qq: thisdata.qq,
  293. wechat: thisdata.wechat,
  294. department: thisdata.department,
  295. position: thisdata.position,
  296. major: thisdata.major,
  297. createTimes: thisdata.createTimes,
  298. fixedTel: thisdata.fixedTel,
  299. aname: thisdata.aname,
  300. cityName:
  301. (thisdata.provinceName || "") +
  302. (thisdata.cityName || "") +
  303. (thisdata.areaName || ""),
  304. });
  305. }
  306. }
  307. this.setState({
  308. contactList: theArr,
  309. });
  310. }.bind(this),
  311. }).always(
  312. function () {
  313. this.setState({
  314. loading: false,
  315. });
  316. }.bind(this)
  317. );
  318. },
  319. //新增
  320. //tab2新增联系人
  321. addcontact() {
  322. this.setState({
  323. addcontactModul: true,
  324. });
  325. },
  326. //
  327. componentWillMount() {
  328. const { data } = this.props
  329. this.contactLists(this.props.data.id);
  330. this.setState({
  331. name: this.props.name,
  332. locationProvince: (data.province || "") + (!data.city ? "" : "-") + (data.city || "") + (!data.area ? "" : "-") + (data.area || ""),
  333. introduction: this.props.data.introduction,
  334. type: this.props.data.type,
  335. });
  336. },
  337. componentWillReceiveProps(nextProps) {
  338. // if (nextProps.data.id && nextProps.contactState) {
  339. if (nextProps.data.id) {
  340. this.contactLists(nextProps.data.id);
  341. }
  342. },
  343. // 修改渠道名称
  344. onOk() {
  345. if (!this.state.newname) {
  346. message.warning("请输入渠道名称");
  347. return;
  348. }
  349. this.setState({
  350. loading: true,
  351. });
  352. $.ajax({
  353. url: globalConfig.context + "/api/admin/customer/updateUserName",
  354. method: "post",
  355. data: {
  356. uid: this.props.data.id,
  357. userName: this.state.newname,
  358. },
  359. }).done(
  360. function (data) {
  361. this.setState({
  362. loading: false,
  363. });
  364. if (data.error.length === 0) {
  365. message.success("恭喜您,更名成功!");
  366. this.setState({
  367. visible: "",
  368. name: this.state.newname,
  369. });
  370. } else {
  371. message.warning(data.error[0].message);
  372. }
  373. }.bind(this)
  374. );
  375. },
  376. // 修改信息
  377. updateDate() {
  378. const { dataArrar, visible, newintroduction, newtype } = this.state;
  379. if (dataArrar.length === 0 && visible == "city") {
  380. message.warning("请选择省-市-区");
  381. return;
  382. }
  383. if (!newintroduction && visible == "introduction") {
  384. message.warning("请输入简介");
  385. return;
  386. }
  387. if (newtype == 0 && visible == "type") {
  388. message.warning("请选择渠道类别");
  389. return;
  390. }
  391. this.setState({
  392. loading: true,
  393. });
  394. let data = {
  395. uid: this.props.data.id,
  396. };
  397. if (visible == "city") {
  398. data.province = dataArrar[0] || undefined;
  399. data.city = dataArrar[1] || undefined;
  400. data.area = dataArrar[2] || undefined;
  401. }
  402. if (visible == "introduction") {
  403. data.introduction = newintroduction;
  404. }
  405. if (visible == "type") {
  406. data.channelType = newtype;
  407. }
  408. $.ajax({
  409. url: globalConfig.context + "/api/admin/customer/updateUserDate",
  410. method: "post",
  411. data: data,
  412. }).done(
  413. function (data) {
  414. this.setState({
  415. loading: false,
  416. });
  417. if (data.error.length === 0) {
  418. message.success("恭喜您,更改成功!");
  419. this.setState({
  420. visible: "",
  421. });
  422. if (visible == "city") {
  423. this.setState({
  424. locationProvince: getProvince(
  425. dataArrar[0],
  426. dataArrar[1],
  427. dataArrar[2]
  428. ),
  429. });
  430. }
  431. if (visible == "introduction") {
  432. this.setState({
  433. introduction: newintroduction,
  434. });
  435. }
  436. if (visible == "type") {
  437. this.setState({
  438. type: newtype,
  439. });
  440. }
  441. } else {
  442. message.warning(data.error[0].message);
  443. }
  444. }.bind(this)
  445. );
  446. },
  447. render() {
  448. const { visible } = this.state;
  449. return (
  450. <div>
  451. <div className="clearfix">
  452. <Alert
  453. message="注:已保存信息不可修改,可新增正确的信息并设置为主要联系人"
  454. banner
  455. />
  456. <div
  457. style={{
  458. display: "flex",
  459. flexDirection: "row",
  460. justifyContent: "space-between",
  461. margin: "30px 60px 30px 0px",
  462. }}
  463. >
  464. <div
  465. style={{
  466. fontSize: 14,
  467. fontWeight: "bold",
  468. }}
  469. >
  470. <div style={{ padding: "5px 0" }}>
  471. <span>渠道名称:{this.state.name}</span>
  472. <Button
  473. type="primary"
  474. style={{ marginLeft: "20px" }}
  475. onClick={() => {
  476. this.setState({
  477. visible: "name",
  478. newname: "",
  479. });
  480. }}
  481. >
  482. 渠道更名
  483. </Button>
  484. </div>
  485. <div style={{ padding: "5px 0" }}>
  486. <span>
  487. 渠道类别:{[
  488. "",
  489. "其他",
  490. "民主党派",
  491. "园区",
  492. "民间组织",
  493. "战略合作单位",
  494. ][this.state.type]}
  495. </span>
  496. <Button
  497. type="primary"
  498. style={{ marginLeft: "20px" }}
  499. onClick={() => {
  500. this.setState({
  501. visible: "type",
  502. newtype: "",
  503. });
  504. }}
  505. >
  506. 修改
  507. </Button>
  508. </div>
  509. <div style={{ padding: "5px 0" }}>
  510. <span>
  511. 省-市-区:
  512. {this.state.locationProvince}
  513. </span>
  514. <Button
  515. type="primary"
  516. style={{ marginLeft: "20px" }}
  517. onClick={() => {
  518. this.setState({
  519. visible: "city",
  520. dataArrar: [],
  521. });
  522. }}
  523. >
  524. 修改
  525. </Button>
  526. </div>
  527. <div style={{ padding: "5px 0" }}>
  528. <span>渠道简介:{this.state.introduction}</span>
  529. <Button
  530. type="primary"
  531. style={{ marginLeft: "20px" }}
  532. onClick={() => {
  533. this.setState({
  534. visible: "introduction",
  535. newintroduction: [],
  536. });
  537. }}
  538. >
  539. 修改
  540. </Button>
  541. </div>
  542. </div>
  543. <Button
  544. className="ContactsList"
  545. type="primary"
  546. onClick={this.addcontact}
  547. >
  548. 新增联系人
  549. </Button>
  550. </div>
  551. </div>
  552. <div className="clearfix">
  553. <Spin spinning={this.state.loading}>
  554. <Table
  555. pagination={false}
  556. columns={this.state.ContactsLists}
  557. dataSource={this.state.contactList}
  558. />
  559. </Spin>
  560. </div>
  561. {/* 新增联系人 */}
  562. <AddContact
  563. addcontactModul={this.state.addcontactModul}
  564. uids={this.props.data.id}
  565. closeFollow={() => {
  566. this.setState(
  567. {
  568. addcontactModul: false,
  569. },
  570. () => {
  571. this.contactLists();
  572. }
  573. );
  574. }}
  575. />
  576. {/* 信息修改 */}
  577. <Modal
  578. footer={null}
  579. maskClosable={false}
  580. width={300}
  581. title={"信息修改"}
  582. visible={visible != ""}
  583. onCancel={() => {
  584. this.setState({
  585. visible: "",
  586. });
  587. }}
  588. >
  589. <div>
  590. {visible == "name" && (
  591. <div className="enterpriseNameContent">
  592. <div className="enterpriseNameItem">
  593. <div className="enterpriseNameTitle">更改前:</div>
  594. <div className="enterpriseNameValue">{this.state.name}</div>
  595. </div>
  596. <div className="enterpriseNameItem">
  597. <div className="enterpriseNameTitle">更改后:</div>
  598. <div className="enterpriseNameValue">
  599. <Input
  600. value={this.state.newname}
  601. onChange={(e) => {
  602. this.setState({
  603. newname: e.target.value,
  604. });
  605. }}
  606. />
  607. </div>
  608. </div>
  609. </div>
  610. )}
  611. {visible == "city" && (
  612. <div className="enterpriseNameContent">
  613. <div className="enterpriseNameItem">
  614. <div className="enterpriseNameTitle">更改前:</div>
  615. <div className="enterpriseNameValue">
  616. {this.state.locationProvince}
  617. </div>
  618. </div>
  619. <div className="enterpriseNameItem">
  620. <div className="enterpriseNameTitle">更改后:</div>
  621. <div className="enterpriseNameValue">
  622. <Cascader
  623. options={areaSelect()}
  624. placeholder="选择城市"
  625. onChange={(e, pre) => {
  626. this.setState({
  627. dataArrar: e,
  628. });
  629. }}
  630. />
  631. </div>
  632. </div>
  633. </div>
  634. )}
  635. {visible == "introduction" && (
  636. <div className="enterpriseNameContent">
  637. <div className="enterpriseNameItem">
  638. <div className="enterpriseNameTitle">更改前:</div>
  639. <div className="enterpriseNameValue">
  640. {this.state.introduction}
  641. </div>
  642. </div>
  643. <div className="enterpriseNameItem">
  644. <div className="enterpriseNameTitle">更改后:</div>
  645. <div className="enterpriseNameValue">
  646. <TextArea
  647. style={{ width: "200px" }}
  648. value={this.state.newintroduction}
  649. onChange={(e) => {
  650. this.setState({
  651. newintroduction: e.target.value,
  652. });
  653. }}
  654. />
  655. </div>
  656. </div>
  657. </div>
  658. )}
  659. {visible == "type" && (
  660. <div className="enterpriseNameContent">
  661. <div className="enterpriseNameItem">
  662. <div className="enterpriseNameTitle">更改前:</div>
  663. <div className="enterpriseNameValue">
  664. {[
  665. "",
  666. "其他",
  667. "民主党派",
  668. "园区",
  669. "民间组织",
  670. "战略合作单位",
  671. ][this.state.type]}</div>
  672. </div>
  673. <div className="enterpriseNameItem">
  674. <div className="enterpriseNameTitle">更改后:</div>
  675. <div className="enterpriseNameValue">
  676. <Select
  677. style={{ width: 165 }}
  678. placeholder="请选择"
  679. value={this.state.newtype == 0 ? undefined : this.state.newtype}
  680. onChange={(e) => {
  681. this.setState({
  682. newtype: e,
  683. });
  684. }}
  685. >
  686. {this.state.channeOb.map(it => (
  687. <Option key={it.val}>{it.name}</Option>
  688. ))}
  689. </Select>
  690. </div>
  691. </div>
  692. </div>
  693. )}
  694. <Popconfirm
  695. placement="top"
  696. title="确定要修改吗?"
  697. onConfirm={(e) => {
  698. e.stopPropagation();
  699. visible == "name" ? this.onOk() : this.updateDate();
  700. }}
  701. okText="确定"
  702. cancelText="取消"
  703. >
  704. <Button type="primary">确定修改</Button>
  705. </Popconfirm>
  706. </div>
  707. </Modal>
  708. </div>
  709. );
  710. },
  711. });
  712. export default ContactPerson;