topTab.jsx 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447
  1. import React from 'react';
  2. import { Row, Col, Icon, Modal, Button, Spin, Select, Input, message, Badge, Table, Tabs } from 'antd';
  3. import { provinceArr } from '../dataDic.js';
  4. import { companySearch } from '../tools.js';
  5. import './topTab.less';
  6. import ajax from 'jquery/src/ajax/xhr.js'
  7. import $ from 'jquery/src/ajax';
  8. import logo from '../../../image/acc-logo.png';
  9. const MessageModal = React.createClass({
  10. getInitialState() {
  11. return {
  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. columns: [
  39. {
  40. title: '编号',
  41. dataIndex: 'key',
  42. key: 'key'
  43. }, {
  44. title: '类型',
  45. dataIndex: 'noticeType',
  46. key: 'noticeType',
  47. render: (text) => {
  48. switch (text) {
  49. case 1:
  50. return <a href={globalConfig.context + "/admin/servicesManage/patent.html#comprehensive"}> 专利申请管理 </a>;
  51. case 3:
  52. return <a href={globalConfig.context + "/admin/servicesManage/copyright.html#copyright"}> 软著申请管理 </a>;
  53. case 2:
  54. return <a href={globalConfig.context + "/admin/servicesManage/highTech.html#highTechApply"}> 高企认定管理 </a>;
  55. case 4:
  56. return <a href={globalConfig.context + "/admin/servicesManage/technology.html#applyManage"}> 科技项目申报管理 </a>;
  57. }
  58. }
  59. }, {
  60. title: '时间',
  61. dataIndex: 'createTimeFormattedDate',
  62. key: 'createTimeFormattedDate'
  63. }, {
  64. title: '内容',
  65. dataIndex: 'content',
  66. key: 'content',
  67. }
  68. ],
  69. data: []
  70. };
  71. },
  72. loadReaded(pageNo) {
  73. this.state.data = [];
  74. this.setState({
  75. loading: true
  76. });
  77. $.ajax({
  78. method: "get",
  79. dataType: "json",
  80. crossDomain: false,
  81. url: globalConfig.context + "/api/admin/notice/readed",
  82. data: {
  83. pageNo: pageNo || 1,
  84. pageSize: this.state.pagination.pageSize,
  85. }
  86. }).done((data) => {
  87. if (!data.data) {
  88. if (data.error && data.error.length) {
  89. message.warning(data.error[0].message);
  90. return;
  91. };
  92. };
  93. this.state.data = [];
  94. for (let i = 0; i < data.data.list.length; i++) {
  95. let thisdata = data.data.list[i];
  96. this.state.data.push({
  97. key: i + 1,
  98. id: thisdata.id,
  99. aid: thisdata.aid,
  100. noticeType: thisdata.noticeType,
  101. content: thisdata.content,
  102. createTime: thisdata.createTime,
  103. createTimeFormattedDate: thisdata.createTimeFormattedDate,
  104. });
  105. };
  106. this.state.pagination.current = data.data.pageNo;
  107. this.state.pagination.total = data.data.totalCount;
  108. this.setState({
  109. dataSource: this.state.data,
  110. pagination: this.state.pagination
  111. });
  112. }).always(function () {
  113. this.setState({
  114. loading: false
  115. });
  116. }.bind(this));
  117. },
  118. loadUnread(pageNo) {
  119. this.state.data = [];
  120. this.setState({
  121. loading: true
  122. });
  123. $.ajax({
  124. method: "get",
  125. dataType: "json",
  126. crossDomain: false,
  127. url: globalConfig.context + "/api/admin/notice/unread",
  128. data: {
  129. pageNo: pageNo || 1,
  130. pageSize: this.state.UnreadPagination.pageSize,
  131. }
  132. }).done((data) => {
  133. if (!data.data) {
  134. if (data.error && data.error.length) {
  135. message.warning(data.error[0].message);
  136. return;
  137. };
  138. };
  139. this.state.data = [];
  140. for (let i = 0; i < data.data.list.length; i++) {
  141. let thisdata = data.data.list[i];
  142. this.state.data.push({
  143. key: i + 1,
  144. id: thisdata.id,
  145. aid: thisdata.aid,
  146. noticeType: thisdata.noticeType,
  147. content: thisdata.content,
  148. createTime: thisdata.createTime,
  149. createTimeFormattedDate: thisdata.createTimeFormattedDate,
  150. });
  151. };
  152. this.state.UnreadPagination.current = data.data.pageNo;
  153. this.state.UnreadPagination.total = data.data.totalCount;
  154. this.setState({
  155. unreadData: this.state.data,
  156. UnreadPagination: this.state.UnreadPagination
  157. });
  158. }).always(function () {
  159. this.setState({
  160. loading: false
  161. });
  162. }.bind(this));
  163. },
  164. componentWillReceiveProps(nextProps) {
  165. if (!this.state.visible && nextProps.showDesc) {
  166. this.loadReaded();
  167. this.loadUnread();
  168. };
  169. this.state.visible = nextProps.showDesc
  170. },
  171. handleOk() {
  172. this.setState({
  173. visible: false,
  174. });
  175. this.props.closeDesc(false, true);
  176. },
  177. handleCancel(e) {
  178. this.setState({
  179. visible: false,
  180. });
  181. this.props.closeDesc(false, true);
  182. },
  183. render() {
  184. return (
  185. <div className="topTab-modal">
  186. <Spin spinning={this.state.loading} className='spin-box'>
  187. <Modal title="信息中心" visible={this.state.visible}
  188. onOk={this.handleOk} onCancel={this.handleCancel}
  189. width='600px' footer=''
  190. >
  191. <Tabs defaultActiveKey="1">
  192. <Tabs.TabPane tab="新信息" key="1">
  193. <Table columns={this.state.columns}
  194. dataSource={this.state.unreadData}
  195. pagination={this.state.UnreadPagination} />
  196. </Tabs.TabPane>
  197. <Tabs.TabPane tab="已读信息" key="2">
  198. <Table columns={this.state.columns}
  199. dataSource={this.state.dataSource}
  200. pagination={this.state.pagination} />
  201. </Tabs.TabPane>
  202. </Tabs>
  203. </Modal>
  204. </Spin>
  205. </div>
  206. );
  207. }
  208. });
  209. const UserModal = React.createClass({
  210. getInitialState() {
  211. return {
  212. visible: false,
  213. loading: false,
  214. provinceOption: []
  215. };
  216. },
  217. componentWillMount() {
  218. let _me = this;
  219. provinceArr.map(function (item) {
  220. _me.state.provinceOption.push(
  221. <Select.Option value={item} key={item}>{item}</Select.Option>
  222. )
  223. });
  224. },
  225. loadData() {
  226. this.setState({
  227. loading: true
  228. });
  229. $.ajax({
  230. method: "get",
  231. dataType: "json",
  232. crossDomain: false,
  233. url: globalConfig.context + "/api/admin/adminInfo",
  234. success: function (data) {
  235. if (!data.data) {
  236. if (data.error[0] && data.error[0]) {
  237. message.warning(data.error[0].message);
  238. };
  239. return;
  240. };
  241. this.setState({
  242. id: data.data.id,
  243. mobile: data.data.mobile,
  244. name: data.data.name,
  245. email: data.data.email,
  246. createTime: data.data.createTime,
  247. number: data.data.number,
  248. province: data.data.province,
  249. createTimeFormattedDate: data.data.createTimeFormattedDate
  250. });
  251. }.bind(this),
  252. }).always(function (data) {
  253. this.setState({
  254. loading: false
  255. });
  256. }.bind(this));
  257. },
  258. componentWillReceiveProps(nextProps) {
  259. if (!this.state.visible && nextProps.showDesc) {
  260. this.loadData();
  261. };
  262. this.state.visible = nextProps.showDesc
  263. },
  264. handleOk() {
  265. this.setState({
  266. loading: true
  267. });
  268. $.ajax({
  269. method: "post",
  270. dataType: "json",
  271. crossDomain: false,
  272. url: globalConfig.context + "/api/admin/updateAdminInfo",
  273. data: {
  274. id: this.state.id,
  275. mobile: this.state.mobile,
  276. name: this.state.name,
  277. email: this.state.email,
  278. province: this.state.province,
  279. password: this.state.password,
  280. pwd: this.state.pwd
  281. }
  282. }).always(function (data) {
  283. if (data.error && data.error.length) {
  284. message.warning(data.error[0].message);
  285. this.setState({
  286. loading: false
  287. });
  288. } else {
  289. message.success('保存成功!');
  290. this.props.closeDesc(false, true);
  291. };
  292. }.bind(this));
  293. },
  294. handleCancel(e) {
  295. this.setState({
  296. visible: false,
  297. });
  298. this.props.closeDesc(false);
  299. },
  300. render() {
  301. return (
  302. <div className="topTab-modal">
  303. <Spin spinning={this.state.loading} className='spin-box'>
  304. <Modal title="用户设置" visible={this.state.visible}
  305. onOk={this.handleOk} onCancel={this.handleCancel}
  306. width='380px'
  307. >
  308. <ul className="modal-content">
  309. <li>
  310. <span className='modal-text'>名字</span>
  311. <Input value={this.state.name} onChange={(e) => { this.state.name = e.target.value; this.setState({ name: this.state.name }); }} />
  312. </li>
  313. <li>
  314. <span className='modal-text'>登录账号</span>
  315. <Input value={this.state.mobile} onChange={(e) => { this.state.mobile = e.target.value; this.setState({ mobile: this.state.mobile }); }} />
  316. </li>
  317. <li>
  318. <span className='modal-text'>省份</span>
  319. <Select placeholder="选择省份"
  320. style={{ width: 200 }}
  321. value={this.state.province}
  322. showSearch
  323. filterOption={companySearch}
  324. onChange={(e) => { this.setState({ province: e }) }}>
  325. {this.state.provinceOption}
  326. </Select>
  327. </li>
  328. <li>
  329. <span className='modal-text'>邮箱</span>
  330. <Input value={this.state.email} onChange={(e) => { this.state.email = e.target.value; this.setState({ email: this.state.email }); }} />
  331. </li>
  332. <li>
  333. <span className='modal-text'>密码</span>
  334. <Input value={this.state.password} onChange={(e) => { this.state.password = e.target.value; this.setState({ password: this.state.password }); }} />
  335. </li>
  336. <li>
  337. <span className='modal-text'>原密码</span>
  338. <Input value={this.state.pwd} onChange={(e) => { this.state.pwd = e.target.value; this.setState({ pwd: this.state.pwd }); }} />
  339. </li>
  340. </ul>
  341. </Modal>
  342. </Spin>
  343. </div>
  344. );
  345. }
  346. });
  347. const TopTab = React.createClass({
  348. getInitialState() {
  349. return {
  350. username: '请登录!',
  351. };
  352. },
  353. logOut() {
  354. let theActive = this.props.active;
  355. $.ajax({
  356. method: "get",
  357. dataType: "json",
  358. url: globalConfig.context + "/login",
  359. }).done(function (data) {
  360. window.location.href = globalConfig.context + "/admin/login.html"
  361. });
  362. },
  363. componentWillMount() {
  364. this.loadData();
  365. },
  366. loadData() {
  367. this.setState({
  368. loading: true
  369. });
  370. $.ajax({
  371. method: "get",
  372. dataType: "json",
  373. crossDomain: false,
  374. url: globalConfig.context + "/api/admin/notice/unreadCount",
  375. success: function (data) {
  376. if (!data.data) {
  377. if (data.error[0] && data.error[0]) {
  378. message.warning(data.error[0].message);
  379. return;
  380. };
  381. };
  382. this.setState({
  383. badge: data.data,
  384. });
  385. }.bind(this),
  386. }).always(function (data) {
  387. this.setState({
  388. loading: false
  389. });
  390. }.bind(this));
  391. },
  392. closeUserModal(e, s) {
  393. this.state.userModalShow = e;
  394. if (s) {
  395. this.loadData();
  396. };
  397. },
  398. closeMessageModal(e, s) {
  399. this.state.messageModalShow = e;
  400. if (s) {
  401. this.loadData();
  402. };
  403. },
  404. render() {
  405. return (
  406. <div className="account-top" >
  407. <div className="acc-top-user">
  408. <span className="acc-top-user-name">欢迎您 , {adminData.name || adminData.mobile ? <a onClick={() => { this.setState({ userModalShow: true }); }}> {adminData.name || adminData.mobile} </a> : <a onClick={this.logOut}>{this.state.username}</a>} <a onClick={this.logOut}>[ 退出 ]</a></span>
  409. <span className="acc-top-user-toindex"><a href={globalConfig.avatarHost + "/html/index.html"}>返回首页</a></span>
  410. <a onClick={() => { this.setState({ messageModalShow: true }); }} className="user-badge">
  411. <Icon type="mail" />
  412. {(() => {
  413. if (!window.showSystem && this.state.badge) {
  414. return <Badge status="processing" />
  415. }
  416. })()}
  417. </a>
  418. </div>
  419. <div className="acc-index">
  420. <div className="acc-index-imgbox">
  421. <img src={logo} alt="" />
  422. </div>
  423. <span><a href={globalConfig.context + "/admin/index.html"}>管理中心首页</a></span>
  424. </div>
  425. <div className="acc-top-tab">
  426. <Row>
  427. <Col style={{ display: window.showUserManage ? 'block' : 'none' }} className={this.props.active === 'userManage' ? 'active' : ''} span={3}><a href={globalConfig.context + "/admin/userManage.html"}>用户管理</a></Col>
  428. <Col style={{ display: window.showServices ? 'block' : 'none' }} className={this.props.active === 'services' ? 'active' : ''} span={3}><a href={globalConfig.context + "/admin/servicesManage/patent.html"}>科技服务管理</a></Col>
  429. <Col style={{ display: window.showAchievement ? 'block' : 'none' }} className={this.props.active === 'achievement' ? 'active' : ''} span={3}><a href="">科技成果管理</a></Col>
  430. <Col style={{ display: window.showDemand ? 'block' : 'none' }} className={this.props.active === 'demand' ? 'active' : ''} span={3}><a href="">科技需求管理</a></Col>
  431. <Col style={{ display: window.showIdea ? 'block' : 'none' }} className={this.props.active === 'idea' ? 'active' : ''} span={3}><a href="">科技思想管理</a></Col>
  432. <Col style={{ display: window.showSystem ? 'block' : 'none' }} className={this.props.active === 'system' ? 'active' : ''} span={3}><a href={globalConfig.context + "/admin/set.html"}>系统设置</a></Col>
  433. </Row>
  434. </div>
  435. <UserModal showDesc={this.state.userModalShow} closeDesc={this.closeUserModal} />
  436. <MessageModal showDesc={this.state.messageModalShow} closeDesc={this.closeMessageModal} />
  437. </div >
  438. )
  439. }
  440. });
  441. export default TopTab;