topTab.jsx 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673
  1. import React from 'react';
  2. import { Row, Col, Icon, Modal, Button, Spin, Input, message, Badge, Table, Tabs, Tag } from 'antd';
  3. import { getProvince } from '../NewDicProvinceList.js';
  4. import { getActives} from '../tools.js';
  5. import './topTab.less';
  6. import $ from 'jquery/src/ajax';
  7. import logo from '../../../image/acc-logo.png';
  8. import FollowDetail from "./customer/NEW/intentionCustomer/followDetail";
  9. const TabPane = Tabs.TabPane;
  10. const MessageModal = React.createClass({
  11. getInitialState() {
  12. return {
  13. unreadData:[],
  14. unreadDataType:'0',
  15. dataSourceType:'1',
  16. unreadDataIndex:0,
  17. visible: false,
  18. loading: false,
  19. pagination: {
  20. defaultCurrent: 1,
  21. defaultPageSize: 10,
  22. showQuickJumper: true,
  23. pageSize: 10,
  24. onChange: function (page) {
  25. this.loadReaded(page);
  26. }.bind(this),
  27. showTotal: function (total) {
  28. return '共' + total + '条数据';
  29. }
  30. },
  31. UnreadPagination: {
  32. defaultCurrent: 1,
  33. defaultPageSize: 10,
  34. showQuickJumper: true,
  35. pageSize: 10,
  36. onChange: function (page) {
  37. this.loadUnread(page);
  38. }.bind(this),
  39. showTotal: function (total) {
  40. return '共' + total + '条数据';
  41. }
  42. },
  43. categoryArr:[],
  44. columns: [
  45. {
  46. title: '类型',
  47. dataIndex: 'noticeType',
  48. key: 'noticeType',
  49. render: (text, record) => {
  50. return (<span>{record.noticeTypeName}</span>)
  51. }
  52. }, {
  53. title: '时间',
  54. dataIndex: 'createTimeFormattedDate',
  55. key: 'createTimeFormattedDate'
  56. }, {
  57. title: '内容',
  58. dataIndex: 'content',
  59. key: 'content',
  60. }, {
  61. title: "操作",
  62. dataIndex: "abc",
  63. key: "abc",
  64. render: (text, record) => {
  65. let contractNo = '';
  66. if((record.noticeType === 14 || record.noticeType === 40) && record.content.indexOf('合同编号-') !== -1){
  67. let arr = record.content.split('合同编号-');
  68. contractNo = arr[1].match(/(\S*), 订单编号/)[1];
  69. }
  70. return (
  71. record.noticeType === 48 || record.noticeType === 49 ?
  72. <Button type="primary" onClick={()=>{
  73. this.category();
  74. record.id = record.uid;
  75. this.setState({
  76. followData: record,
  77. visitModul: true,
  78. });
  79. }}>立即跟进</Button> :
  80. record.noticeType === 14 || record.noticeType === 40 ?
  81. <Button disabled={!contractNo} type="primary" onClick={(e)=>{
  82. e.stopPropagation();
  83. let input = document.getElementById("copyText");
  84. input.value = contractNo;
  85. input.select();
  86. document.execCommand("copy");
  87. message.success('复制成功')
  88. }}>
  89. 复制合同号
  90. </Button> : null
  91. )
  92. }
  93. },
  94. ],
  95. data: []
  96. };
  97. },
  98. category() {
  99. $.ajax({
  100. method: "get",
  101. dataType: "json",
  102. crossDomain: false,
  103. url: globalConfig.context + "/api/admin/Varieties/getSuperList",
  104. data: {},
  105. success: function (data) {
  106. let thedata = data.data;
  107. let theArr = [];
  108. if (!thedata) {
  109. if (data.error && data.error.length) {
  110. message.warning(data.error[0].message);
  111. }
  112. thedata = {};
  113. } else {
  114. thedata.map(function (item, index) {
  115. theArr.push({
  116. value: item.id,
  117. key: item.cname,
  118. });
  119. });
  120. }
  121. this.setState({
  122. categoryArr: theArr,
  123. });
  124. }.bind(this),
  125. });
  126. },
  127. loadReaded(pageNo) {
  128. this.state.data = [];
  129. this.setState({
  130. loading: true
  131. });
  132. $.ajax({
  133. method: "get",
  134. dataType: "json",
  135. crossDomain: false,
  136. url: globalConfig.context + "/api/admin/notice/readed",
  137. data: {
  138. pageNo: pageNo || 1,
  139. pageSize: this.state.pagination.pageSize,
  140. type:this.state.unreadDataType,
  141. }
  142. }).done((data) => {
  143. if (!data.data) {
  144. if (data.error && data.error.length) {
  145. message.warning(data.error[0].message);
  146. return;
  147. };
  148. };
  149. this.state.data = [];
  150. for (let i = 0; i < data.data.list.length; i++) {
  151. let thisdata = data.data.list[i];
  152. this.state.data.push({
  153. key: i + 1,
  154. id: thisdata.id,
  155. rid: thisdata.rid,
  156. uid: thisdata.uid,
  157. aid: thisdata.aid,
  158. noticeType: thisdata.noticeType,
  159. year: thisdata.year,
  160. noticeTypeName: thisdata.noticeTypeName,
  161. content: thisdata.content,
  162. createTime: thisdata.createTime,
  163. createTimeFormattedDate: thisdata.createTimeFormattedDate,
  164. principle: thisdata.principle,
  165. unitName: thisdata.unitName
  166. });
  167. };
  168. this.state.pagination.current = data.data.pageNo;
  169. this.state.pagination.total = data.data.totalCount;
  170. this.setState({
  171. dataSource: this.state.data,
  172. pagination: this.state.pagination
  173. });
  174. }).always(function () {
  175. this.setState({
  176. loading: false
  177. });
  178. }.bind(this));
  179. },
  180. loadUnread(pageNo) {
  181. this.state.data = [];
  182. this.setState({
  183. loading: true
  184. });
  185. $.ajax({
  186. method: "get",
  187. dataType: "json",
  188. crossDomain: false,
  189. url: globalConfig.context + "/api/admin/notice/unread",
  190. data: {
  191. }
  192. }).done((data) => {
  193. if (data.error && data.error.length) {
  194. message.warning(data.error[0].message);
  195. return;
  196. }else{
  197. let arr = data.data.filter(v=>v.list.length > 0)
  198. if(arr.length) {
  199. this.setState({
  200. newVisible: true
  201. });
  202. }
  203. let index = data.data.findIndex(v=>v.list.length > 0);
  204. if(index >= 0){
  205. data.data[index].isRead = true;
  206. this.setState({
  207. unreadDataType: index ? data.data[index]['id']+'' : '0',
  208. unreadDataIndex:index,
  209. });
  210. }else{
  211. this.setState({
  212. unreadDataType: data.data[0]['id']+'',
  213. unreadDataIndex:'0',
  214. });
  215. }
  216. this.setState({
  217. unreadData: data.data,
  218. });
  219. }
  220. }).always(function () {
  221. this.setState({
  222. loading: false
  223. });
  224. }.bind(this));
  225. },
  226. componentWillReceiveProps(nextProps) {
  227. if (!this.state.visible && nextProps.showDesc) {
  228. this.loadReaded();
  229. this.loadUnread();
  230. };
  231. this.state.visible = nextProps.showDesc
  232. },
  233. handleOk() {
  234. let arr = this.state.unreadData.filter(v=>v.list.length > 0 && !v.isRead);
  235. if(arr.length > 0){
  236. message.warning('还存在未读消息,请查看后再关闭当前页面!');
  237. return;
  238. }else{
  239. this.setState({
  240. visible: false,
  241. });
  242. }
  243. this.props.closeDesc(false, true);
  244. },
  245. handleCancel(e) {
  246. let arr = this.state.unreadData.filter(v=>v.list.length > 0 && !v.isRead);
  247. if(arr.length > 0){
  248. message.warning('还存在未读消息,请查看后再关闭当前页面!');
  249. return;
  250. }else{
  251. this.setState({
  252. visible: false,
  253. });
  254. }
  255. this.props.closeDesc(false, true);
  256. },
  257. closeDesc(){
  258. this.setState({
  259. categoryArr:[],
  260. followData:'',
  261. visitModul:false
  262. },()=>{
  263. this.loadReaded(this.state.pagination.current);
  264. })
  265. },
  266. render() {
  267. return (
  268. <div className="topTab-modal">
  269. <Spin spinning={this.state.loading} className='spin-box'>
  270. <Modal maskClosable={false} title="信息中心" visible={this.state.visible}
  271. onOk={this.handleOk} onCancel={this.handleCancel}
  272. width='1200px' footer=''
  273. >
  274. <Spin spinning={this.state.loading} className="spin-box">
  275. <Tabs defaultActiveKey={this.state.unreadDataType} activeKey={this.state.unreadDataType} onChange={v=>{
  276. let index = this.state.unreadData.findIndex(d=>d.id == v);
  277. this.state.unreadData[index].isRead = true;
  278. this.setState({
  279. unreadDataIndex:index,
  280. unreadData:this.state.unreadData,
  281. unreadDataType:v
  282. },()=>{
  283. if(this.state.dataSourceType === '2'){
  284. this.loadReaded()
  285. }
  286. })
  287. }}>
  288. {
  289. this.state.unreadData.map((v)=>(
  290. <Tabs.TabPane
  291. key={v.id+''}
  292. tab={<div>
  293. {v.list.length === 0 || v.isRead ? null : <div style={{width:'8px',height:"8px",borderRadius:'8px',background:'#f00',position: 'absolute',right: '5px', top: '2px'}}/>}
  294. {v.name}
  295. </div>
  296. }/>
  297. ))
  298. }
  299. </Tabs>
  300. <Tabs defaultActiveKey="1" type="card" tabPosition='left' value={this.state.dataSourceType} onChange={(v)=>{
  301. this.setState({
  302. dataSourceType:v
  303. })
  304. if(v === '2'){
  305. this.loadReaded()
  306. }
  307. }}>
  308. <Tabs.TabPane tab={'未读'} key="1">
  309. <Table
  310. bordered
  311. columns={this.state.columns}
  312. dataSource={this.state.unreadData[this.state.unreadDataIndex] ? this.state.unreadData[this.state.unreadDataIndex].list : []}
  313. pagination={false}
  314. />
  315. </Tabs.TabPane>
  316. <Tabs.TabPane tab="已读" key="2">
  317. <Table
  318. bordered
  319. columns={this.state.columns}
  320. dataSource={this.state.dataSource}
  321. pagination={this.state.pagination}
  322. />
  323. </Tabs.TabPane>
  324. </Tabs>
  325. </Spin>
  326. <textarea id='copyText' style={{opacity:0}}/>
  327. </Modal>
  328. </Spin>
  329. <FollowDetail
  330. categoryArr={this.state.categoryArr}
  331. followData={this.state.followData}
  332. visitModul={this.state.visitModul}
  333. closeDesc={this.closeDesc}
  334. />
  335. </div>
  336. );
  337. }
  338. });
  339. const UserModal = React.createClass({
  340. getInitialState() {
  341. return {
  342. visible: false,
  343. loading: false,
  344. locations: []
  345. };
  346. },
  347. loadData() {
  348. this.setState({
  349. loading: true
  350. });
  351. $.ajax({
  352. method: "get",
  353. dataType: "json",
  354. crossDomain: false,
  355. url: globalConfig.context + "/api/admin/adminInfo",
  356. success: function (data) {
  357. if (!data.data) {
  358. if (data.error[0] && data.error[0]) {
  359. message.warning(data.error[0].message);
  360. };
  361. return;
  362. };
  363. this.setState({
  364. id: data.data.id,
  365. mobile: data.data.mobile,
  366. contactMobile: data.data.contactMobile,
  367. name: data.data.name,
  368. position: data.data.position,
  369. email: data.data.email,
  370. createTime: data.data.createTime,
  371. number: data.data.number,
  372. createTimeFormattedDate: data.data.createTimeFormattedDate,
  373. pwd:'',
  374. password:''
  375. });
  376. this.loadLocations(data.data.id);
  377. }.bind(this),
  378. }).always(function (data) {
  379. this.setState({
  380. loading: false
  381. });
  382. }.bind(this));
  383. },
  384. loadLocations(id) {
  385. this.setState({
  386. loading: true
  387. });
  388. $.ajax({
  389. url: globalConfig.context + '/api/admin/supervise/adminDetailLocation',
  390. cache: false,
  391. data: {
  392. "id": id
  393. }
  394. }).done((data) => {
  395. if (!data.data) {
  396. if (data.error && data.error.length) {
  397. message.warning(data.error[0].message);
  398. return;
  399. };
  400. };
  401. data.data.map((item) => {
  402. if (item.city) {
  403. item.city = item.city.split(',');
  404. }
  405. });
  406. this.setState({
  407. locations: data.data,
  408. loading: false
  409. });
  410. })
  411. },
  412. componentWillReceiveProps(nextProps) {
  413. if (!this.state.visible && nextProps.showDesc) {
  414. this.loadData();
  415. };
  416. this.state.visible = nextProps.showDesc
  417. },
  418. handleOk() {
  419. this.setState({
  420. loading: true
  421. });
  422. if(this.state.contactMobile){
  423. if(!(/^1[1-9][0-9]\d{4,8}$/.test(this.state.contactMobile))){
  424. message.warning("不是完整的11位手机号或者正确的手机号前七位");
  425. this.setState({
  426. loading: false
  427. });
  428. return false;
  429. }
  430. }
  431. // if(this.state.mobile.length>11){
  432. // message.warning("登录账号不能超过11位");
  433. // return false;
  434. // }
  435. $.ajax({
  436. method: "post",
  437. dataType: "json",
  438. crossDomain: false,
  439. url: globalConfig.context + "/api/admin/updateAdminInfo",
  440. data: {
  441. id: this.state.id,
  442. mobile: this.state.mobile,
  443. contactMobile: this.state.contactMobile,
  444. name: this.state.name,
  445. email: this.state.email,
  446. province: this.state.province,
  447. password: this.state.password,
  448. pwd: this.state.pwd
  449. }
  450. }).always(function (data) {
  451. if (data.error && data.error.length) {
  452. message.warning(data.error[0].message);
  453. } else {
  454. this.setState({
  455. loading: false
  456. });
  457. message.success('保存成功!');
  458. this.props.closeDesc(false, true);
  459. };
  460. }.bind(this));
  461. },
  462. handleCancel(e) {
  463. this.setState({
  464. visible: false,
  465. });
  466. this.props.closeDesc(false);
  467. },
  468. render() {
  469. return (
  470. <div className="topTab-modal">
  471. <Spin spinning={this.state.loading} className='spin-box'>
  472. <Modal maskClosable={false} title="用户设置" visible={this.state.visible}
  473. onOk={this.handleOk} onCancel={this.handleCancel}
  474. width='380px' >
  475. <ul className="modal-content">
  476. <li>
  477. <span className='modal-text'>名字</span>
  478. <Input value={this.state.name} onChange={(e) => { this.state.name = e.target.value; this.setState({ name: this.state.name }); }} />
  479. </li>
  480. <li>
  481. <span className='modal-text'>职位</span>
  482. <span>{this.state.position}</span>
  483. </li>
  484. <li>
  485. <span className='modal-text'>登录账号</span>
  486. <span>{this.state.mobile}</span>
  487. </li>
  488. <li>
  489. <span className='modal-text'>联系方式</span>
  490. <Input value={this.state.contactMobile} onChange={(e) => { this.state.contactMobile = e.target.value; this.setState({ contactMobile: this.state.contactMobile }); }} />
  491. </li>
  492. <li>
  493. <span className='modal-text'>省份</span>
  494. <div style={{ display: "inline-block", width: '78%' }}>
  495. {this.state.locations.map((item, i) => {
  496. return <Tag key={i}>{getProvince(item.province) + ' ' + (item.city ? item.city.map((c) => {
  497. return getProvince(c) + ' '
  498. }) : '')}</Tag>
  499. })}
  500. </div>
  501. </li>
  502. <li>
  503. <span className='modal-text'>邮箱</span>
  504. <Input value={this.state.email} onChange={(e) => { this.state.email = e.target.value; this.setState({ email: this.state.email }); }} />
  505. </li>
  506. <li>
  507. <span className='modal-text'>原密码</span>
  508. <Input value={this.state.pwd} type="password" onChange={(e) => { this.state.pwd = e.target.value; this.setState({ pwd: this.state.pwd }); }} />
  509. </li>
  510. <li>
  511. <span className='modal-text'>密码</span>
  512. <Input value={this.state.password} type="password" onChange={(e) => { this.state.password = e.target.value; this.setState({ password: this.state.password }); }} />
  513. </li>
  514. </ul>
  515. </Modal>
  516. </Spin>
  517. </div>
  518. );
  519. }
  520. });
  521. const TopTab = React.createClass({
  522. getInitialState() {
  523. return {
  524. username: '请登录!',
  525. defaultActiveKey:'-1',
  526. htmlMenus:[],
  527. };
  528. },
  529. logOut() {
  530. let theActive = this.props.active;
  531. $.ajax({
  532. method: "get",
  533. dataType: "json",
  534. url: globalConfig.context + "/login",
  535. }).done(function (data) {
  536. window.location.href = globalConfig.context + "/admin/login.html"
  537. });
  538. },
  539. componentWillMount() {
  540. if (this.props.active) {
  541. this.loadData();
  542. };
  543. this.mainMenu();
  544. },
  545. //主菜单请求
  546. mainMenu(){
  547. this.setState({
  548. loading:true
  549. });
  550. $.ajax({
  551. method: "get",
  552. dataType: "json",
  553. crossDomain: false,
  554. url: globalConfig.context + "/api/admin/selectNavList",
  555. data: {
  556. },
  557. success:function(data){
  558. if (!data.data) {
  559. if (data.error && data.error.length) {
  560. message.warning(data.error[0].message);
  561. return;
  562. };
  563. };
  564. let menu=data.data;
  565. var htmlMenu=[];
  566. let index = menu.findIndex(v=>getActives(v.name) === this.props.active);
  567. this.setState({
  568. htmlMenus:menu,
  569. defaultActiveKey:index+''
  570. })
  571. }.bind(this),
  572. }).always(function(data){
  573. this.setState({
  574. loading:false
  575. })
  576. }.bind(this))
  577. },
  578. loadData() {
  579. this.setState({
  580. loading: true
  581. });
  582. $.ajax({
  583. method: "get",
  584. dataType: "json",
  585. crossDomain: false,
  586. url: globalConfig.context + "/api/admin/notice/unreadCount",
  587. success: function (data) {
  588. if (!data.data) {
  589. if (data.error[0] && data.error[0]) {
  590. message.warning(data.error[0].message);
  591. return;
  592. };
  593. };
  594. this.setState({
  595. badge: data.data,
  596. });
  597. }.bind(this),
  598. }).always(function (data) {
  599. this.setState({
  600. loading: false
  601. });
  602. }.bind(this));
  603. },
  604. closeUserModal(e, s) {
  605. this.state.userModalShow = e;
  606. if (s) {
  607. this.loadData();
  608. };
  609. },
  610. closeMessageModal(e, s) {
  611. this.state.messageModalShow = e;
  612. if (s) {
  613. this.loadData();
  614. };
  615. },
  616. render() {
  617. return (
  618. <div className="account-top" >
  619. <div className="acc-top-user">
  620. <span className="acc-top-user-name">欢迎您 , {adminData.name || adminData.mobile ? <a onClick={() => {
  621. // if (window.showPermissionList && window.showRoleList) {
  622. // return
  623. // };
  624. this.setState({ userModalShow: true });
  625. }}> {adminData.name || adminData.mobile} </a> : <a onClick={this.logOut}>{this.state.username}</a>} <a onClick={this.logOut}>[ 退出 ]</a></span>
  626. <span className="acc-top-user-toindex"><a href={jumpUrl||'' + "/portal/index.html"}>返回首页</a></span>
  627. {this.props.active ? <a onClick={() => { this.setState({ messageModalShow: true }); }} className="user-badge">
  628. <Icon type="mail" />
  629. {
  630. !window.showSystem && this.state.badge ?
  631. <Badge status="processing" /> : null
  632. }
  633. </a> : null}
  634. </div>
  635. <div className="acc-index">
  636. <div className="acc-index-imgbox">
  637. <img src={logo} alt="" />
  638. </div>
  639. <span><a href={globalConfig.context + "/admin/index.html"}>管理中心首页</a></span>
  640. </div>
  641. <div className="acc-top-tab">
  642. {this.state.htmlMenus.length > 0 ? <Tabs
  643. defaultActiveKey={this.state.defaultActiveKey}
  644. activeKey={this.state.defaultActiveKey}
  645. tabPosition='top'
  646. onTabClick={v=>{
  647. window.location.href=globalConfig.context + this.state.htmlMenus[parseInt(v)].url+'?rid='+this.state.htmlMenus[parseInt(v)].id;
  648. }}
  649. // onChange={v=>{
  650. // window.location.href=globalConfig.context + this.state.htmlMenus[parseInt(v)].url+'?rid='+this.state.htmlMenus[parseInt(v)].id;
  651. // }}
  652. >
  653. {this.state.htmlMenus.map((v,k)=>(
  654. <TabPane key={k} tab={v.name}/>
  655. ))}
  656. </Tabs> : null}
  657. </div>
  658. <UserModal showDesc={this.state.userModalShow} closeDesc={this.closeUserModal} />
  659. <MessageModal showDesc={this.state.messageModalShow} closeDesc={this.closeMessageModal} />
  660. </div >
  661. )
  662. }
  663. });
  664. export default TopTab;