showModal.jsx 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493
  1. import React from "react";
  2. import $ from "jquery/src/ajax";
  3. import { Spin, Button, Tabs, Table, message, Modal } from "antd";
  4. import FollowDetail from "./manageCenter/customer/NEW/intentionCustomer/followDetail"
  5. const MessageModal = React.createClass({
  6. getInitialState() {
  7. return {
  8. unreadData: [],
  9. unreadDataType: "0",
  10. dataSourceType: "1",
  11. unreadDataIndex: 0,
  12. visible: false,
  13. loading: false,
  14. pagination: {
  15. defaultCurrent: 1,
  16. defaultPageSize: 10,
  17. showQuickJumper: true,
  18. pageSize: 10,
  19. onChange: function (page) {
  20. this.loadReaded(page);
  21. }.bind(this),
  22. showTotal: function (total) {
  23. return "共" + total + "条数据";
  24. },
  25. },
  26. UnreadPagination: {
  27. defaultCurrent: 1,
  28. defaultPageSize: 10,
  29. showQuickJumper: true,
  30. pageSize: 10,
  31. onChange: function (page) {
  32. this.loadUnread(page);
  33. }.bind(this),
  34. showTotal: function (total) {
  35. return "共" + total + "条数据";
  36. },
  37. },
  38. categoryArr: [],
  39. columns: [
  40. {
  41. title: "类型",
  42. dataIndex: "noticeType",
  43. key: "noticeType",
  44. render: (text, record) => {
  45. return <span style={{ color: record.noticeType == 59 && "red" }}>{record.noticeTypeName}</span>;
  46. },
  47. },
  48. {
  49. title: "时间",
  50. dataIndex: "createTimeFormattedDate",
  51. key: "createTimeFormattedDate",
  52. },
  53. {
  54. title: "内容",
  55. dataIndex: "content",
  56. key: "content",
  57. render: (text, record) => {
  58. return <span style={{ color: record.noticeType == 59 && "red" }}>{text}</span>;
  59. },
  60. },
  61. {
  62. title: "操作",
  63. dataIndex: "abc",
  64. key: "abc",
  65. render: (text, record) => {
  66. let contractNo = "";
  67. if (
  68. (record.noticeType === 14 || record.noticeType === 40) &&
  69. record.content.indexOf("合同编号-") !== -1
  70. ) {
  71. let arr = record.content.split("合同编号-");
  72. contractNo = arr[1].match(/(\S*), 订单编号/)[1];
  73. }
  74. return record.noticeType === 48 || record.noticeType === 49 ? (
  75. <Button
  76. type="primary"
  77. onClick={() => {
  78. this.category();
  79. record.id = record.uid;
  80. this.setState({
  81. followData: record,
  82. visitModul: true,
  83. });
  84. }}
  85. >
  86. 立即跟进
  87. </Button>
  88. ) : record.noticeType === 14 || record.noticeType === 40 ? (
  89. <Button
  90. disabled={!contractNo}
  91. type="primary"
  92. onClick={(e) => {
  93. e.stopPropagation();
  94. let input = document.getElementById("copyText");
  95. input.value = contractNo;
  96. input.select();
  97. document.execCommand("copy");
  98. message.success("复制成功");
  99. }}
  100. >
  101. 复制合同号
  102. </Button>
  103. ) : null;
  104. },
  105. },
  106. ],
  107. data: [],
  108. };
  109. },
  110. category() {
  111. $.ajax({
  112. method: "get",
  113. dataType: "json",
  114. crossDomain: false,
  115. url: globalConfig.context + "/api/admin/Varieties/getSuperList",
  116. data: {},
  117. success: function (data) {
  118. let thedata = data.data;
  119. let theArr = [];
  120. if (!thedata) {
  121. if (data.error && data.error.length) {
  122. message.warning(data.error[0].message);
  123. }
  124. thedata = {};
  125. } else {
  126. thedata.map(function (item, index) {
  127. theArr.push({
  128. value: item.id,
  129. key: item.cname,
  130. });
  131. });
  132. }
  133. this.setState({
  134. categoryArr: theArr,
  135. });
  136. }.bind(this),
  137. });
  138. },
  139. loadReaded(pageNo) {
  140. this.state.data = [];
  141. this.setState({
  142. loading: true,
  143. });
  144. $.ajax({
  145. method: "get",
  146. dataType: "json",
  147. crossDomain: false,
  148. url: globalConfig.context + "/api/admin/notice/readed",
  149. data: {
  150. pageNo: pageNo || 1,
  151. pageSize: this.state.pagination.pageSize,
  152. type: this.state.unreadDataType,
  153. },
  154. })
  155. .done((data) => {
  156. if (!data.data) {
  157. if (data.error && data.error.length) {
  158. message.warning(data.error[0].message);
  159. return;
  160. }
  161. }
  162. this.state.data = [];
  163. for (let i = 0; i < data.data.list.length; i++) {
  164. let thisdata = data.data.list[i];
  165. this.state.data.push({
  166. key: i + 1,
  167. id: thisdata.id,
  168. rid: thisdata.rid,
  169. uid: thisdata.uid,
  170. aid: thisdata.aid,
  171. noticeType: thisdata.noticeType,
  172. year: thisdata.year,
  173. noticeTypeName: thisdata.noticeTypeName,
  174. content: thisdata.content,
  175. createTime: thisdata.createTime,
  176. createTimeFormattedDate: thisdata.createTimeFormattedDate,
  177. principle: thisdata.principle,
  178. unitName: thisdata.unitName,
  179. });
  180. }
  181. this.state.pagination.current = data.data.pageNo;
  182. this.state.pagination.total = data.data.totalCount;
  183. this.setState({
  184. dataSource: this.state.data,
  185. pagination: this.state.pagination,
  186. });
  187. })
  188. .always(
  189. function () {
  190. this.setState({
  191. loading: false,
  192. });
  193. }.bind(this)
  194. );
  195. },
  196. loadUnread(pageNo) {
  197. this.state.data = [];
  198. this.setState({
  199. loading: true,
  200. });
  201. $.ajax({
  202. method: "get",
  203. dataType: "json",
  204. crossDomain: false,
  205. url: globalConfig.context + "/api/admin/notice/unread",
  206. data: {},
  207. })
  208. .done((data) => {
  209. if (data.error && data.error.length) {
  210. message.warning(data.error[0].message);
  211. return;
  212. } else {
  213. let arr = data.data.filter((v) => v.list.length > 0);
  214. if (arr.length) {
  215. this.setState({
  216. newVisible: true,
  217. });
  218. }
  219. let index = data.data.findIndex((v) => v.list.length > 0);
  220. if (index >= 0) {
  221. data.data[index].isRead = true;
  222. this.setState({
  223. unreadDataType: data.data[index]["id"] + "",
  224. unreadDataIndex: index,
  225. });
  226. } else {
  227. this.setState({
  228. unreadDataType: data.data[0]["id"] + "",
  229. unreadDataIndex: "0",
  230. });
  231. }
  232. this.setState({
  233. unreadData: data.data,
  234. });
  235. }
  236. })
  237. .always(
  238. function () {
  239. this.setState({
  240. loading: false,
  241. });
  242. }.bind(this)
  243. );
  244. },
  245. componentWillReceiveProps(nextProps) {
  246. if (!this.state.visible && nextProps.showDesc) {
  247. this.loadReaded();
  248. this.loadUnread();
  249. }
  250. this.state.visible = nextProps.showDesc;
  251. },
  252. handleOk() {
  253. let arr = this.state.unreadData.filter(
  254. (v) => v.list.length > 0 && !v.isRead
  255. );
  256. if (arr.length > 0) {
  257. message.warning("还存在未读消息,请查看后再关闭当前页面!");
  258. return;
  259. } else {
  260. this.setState({
  261. visible: false,
  262. });
  263. }
  264. this.props.closeDesc(false, true);
  265. },
  266. handleCancel(e) {
  267. let arr = this.state.unreadData.filter(
  268. (v) => v.list.length > 0 && !v.isRead
  269. );
  270. if (arr.length > 0) {
  271. message.warning("还存在未读消息,请查看后再关闭当前页面!");
  272. return;
  273. } else {
  274. this.setState({
  275. visible: false,
  276. });
  277. }
  278. this.props.closeDesc(false, true);
  279. },
  280. closeDesc() {
  281. this.setState(
  282. {
  283. categoryArr: [],
  284. followData: "",
  285. visitModul: false,
  286. },
  287. () => {
  288. this.loadReaded(this.state.pagination.current);
  289. }
  290. );
  291. },
  292. render() {
  293. return (
  294. <div className="topTab-modal">
  295. <Spin spinning={this.state.loading} className="spin-box">
  296. <Modal
  297. maskClosable={false}
  298. title="信息中心"
  299. visible={this.state.visible}
  300. onOk={this.handleOk}
  301. onCancel={this.handleCancel}
  302. width="1200px"
  303. footer=""
  304. >
  305. <Spin spinning={this.state.loading} className="spin-box">
  306. <Tabs
  307. defaultActiveKey={this.state.unreadDataType}
  308. activeKey={this.state.unreadDataType}
  309. onChange={(v) => {
  310. let index = this.state.unreadData.findIndex((d) => d.id == v);
  311. this.state.unreadData[index].isRead = true;
  312. this.setState(
  313. {
  314. unreadDataIndex: index,
  315. unreadData: this.state.unreadData,
  316. unreadDataType: v,
  317. },
  318. () => {
  319. if (this.state.dataSourceType === "2") {
  320. this.loadReaded();
  321. }
  322. }
  323. );
  324. }}
  325. >
  326. {this.state.unreadData.map((v) => (
  327. <Tabs.TabPane
  328. key={v.id + ""}
  329. tab={
  330. <div
  331. style={{ color: v.id == 7 && "red" }}
  332. >
  333. {v.list.length === 0 || v.isRead ? null : (
  334. <div
  335. style={{
  336. width: "8px",
  337. height: "8px",
  338. borderRadius: "8px",
  339. background: "#f00",
  340. position: "absolute",
  341. right: "5px",
  342. top: "2px",
  343. }}
  344. />
  345. )}
  346. {v.name}
  347. </div>
  348. }
  349. />
  350. ))}
  351. </Tabs>
  352. <Tabs
  353. defaultActiveKey="1"
  354. type="card"
  355. tabPosition="left"
  356. value={this.state.dataSourceType}
  357. onChange={(v) => {
  358. this.setState({
  359. dataSourceType: v,
  360. });
  361. if (v === "2") {
  362. this.loadReaded();
  363. }
  364. }}
  365. >
  366. <Tabs.TabPane tab={"未读"} key="1">
  367. <Table
  368. bordered
  369. columns={this.state.columns}
  370. dataSource={
  371. this.state.unreadData[this.state.unreadDataIndex]
  372. ? this.state.unreadData[this.state.unreadDataIndex].list
  373. : []
  374. }
  375. pagination={false}
  376. />
  377. </Tabs.TabPane>
  378. <Tabs.TabPane tab="已读" key="2">
  379. <Table
  380. bordered
  381. columns={this.state.columns}
  382. dataSource={this.state.dataSource}
  383. pagination={this.state.pagination}
  384. />
  385. </Tabs.TabPane>
  386. </Tabs>
  387. </Spin>
  388. <textarea id="copyText" style={{ opacity: 0 }} />
  389. </Modal>
  390. </Spin>
  391. <FollowDetail
  392. categoryArr={this.state.categoryArr}
  393. followData={this.state.followData}
  394. visitModul={this.state.visitModul}
  395. closeDesc={this.closeDesc}
  396. />
  397. </div>
  398. );
  399. },
  400. });
  401. const ShowModal = React.createClass({
  402. getInitialState() {
  403. return {
  404. newVisible: false,
  405. messageModalShow: false,
  406. };
  407. },
  408. componentWillReceiveProps(nextProps) {
  409. if (this.timer) {
  410. clearTimeout(this.timer);
  411. }
  412. this.timer = setTimeout(() => {
  413. this.performAction(nextProps);
  414. }, 500);
  415. },
  416. performAction(nextProps) {
  417. this.setState({
  418. newVisible: nextProps.ShowModal
  419. });
  420. },
  421. handleOk() {
  422. this.setState({
  423. newVisible: false,
  424. messageModalShow: false,
  425. });
  426. },
  427. closeMessageModal(e, s) {
  428. this.setState({
  429. ShowModal: e,
  430. newVisible: false,
  431. messageModalShow: e
  432. })
  433. this.props.onClose();
  434. },
  435. render() {
  436. return (
  437. <div>
  438. <Modal
  439. style={{ position: "relative" }}
  440. title="消息提醒"
  441. visible={this.state.newVisible}
  442. closable={false}
  443. footer={null}
  444. destroyOnClose={true}
  445. >
  446. <div style={{ textAlign: "center" }}>
  447. 您有新消息尚未查看,请及时查看信息!
  448. <span
  449. style={{ color: "#58a3ff", cursor: "pointer" }}
  450. // href={"/admin/index.html#normal"}
  451. onClick={() => {
  452. this.setState({
  453. messageModalShow: true,
  454. newVisible: false,
  455. })
  456. !!this.props.seeInfo && this.props.seeInfo()
  457. }}
  458. >点我查看信息</span>
  459. </div>
  460. <Button
  461. onClick={this.handleOk}
  462. type={"primary"}
  463. style={{
  464. position: "relative",
  465. left: "50%",
  466. transform: "translateX(-50%)",
  467. bottom: -10
  468. }}
  469. >
  470. 关闭
  471. </Button>
  472. <MessageModal
  473. showDesc={this.state.messageModalShow}
  474. closeDesc={this.closeMessageModal}
  475. />
  476. </Modal>
  477. </div>
  478. );
  479. }
  480. });
  481. export default ShowModal;