index.jsx 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542
  1. import React, { Component } from "react";
  2. import {
  3. Spin,
  4. Button,
  5. Table,
  6. message,
  7. Input,
  8. DatePicker,
  9. Select,
  10. Icon,
  11. Upload,
  12. Tooltip,
  13. Modal,
  14. } from 'antd';
  15. import $ from "jquery/src/ajax";
  16. import ajax from 'jquery/src/ajax/xhr.js'
  17. import moment from "moment";
  18. import '../../public.less';
  19. import logo from '../../../../../image/kede.png';
  20. import { getLoginStatus } from '../../../../utils/tools';
  21. import Detail from "./detail"; // 详情
  22. const Option = Select.Option;
  23. const { RangePicker } = DatePicker;
  24. class Content extends Component {
  25. constructor(props) {
  26. super(props);
  27. this.state = {
  28. dataSource: [], // table数据
  29. loading: false, // 加载loading
  30. upLoadFileLoading: false, // 上传loading
  31. searchInfor: {}, // 查询条件
  32. visible: false, // 控制弹窗变量
  33. rowdata: {}, // 行数据
  34. pagination: {
  35. defaultCurrent: 1,
  36. defaultPageSize: 10,
  37. showQuickJumper: true,
  38. pageSize: 10,
  39. onChange: function (page) {
  40. this.loadData(page);
  41. }.bind(this),
  42. showTotal: function (total) {
  43. return "共" + total + "条数据";
  44. },
  45. },
  46. columns: [
  47. {
  48. title: "索引",
  49. dataIndex: "id",
  50. key: "id",
  51. fixed: "left",
  52. width: 50,
  53. },
  54. {
  55. title: "单位名称",
  56. dataIndex: "userName",
  57. key: "userName",
  58. fixed: "left",
  59. width: 180,
  60. },
  61. {
  62. title: "研发活动编号",
  63. dataIndex: "rdNo",
  64. key: "rdNo",
  65. width: 100,
  66. },
  67. {
  68. title: "知识产权编号",
  69. dataIndex: "ipNo",
  70. key: "ipNo",
  71. width: 100,
  72. },
  73. {
  74. title: "研发活动名称",
  75. dataIndex: "rdName",
  76. key: "rdName",
  77. },
  78. {
  79. title: "起止时间",
  80. dataIndex: "rdStartStr",
  81. key: "rdStartStr",
  82. width: 160,
  83. render: (text, record) => (
  84. <div>
  85. {!text ? "" : (text + "~" + record.rdEndStr)}
  86. </div>
  87. )
  88. },
  89. {
  90. title: "技术领域",
  91. dataIndex: "technicalField",
  92. key: "technicalField",
  93. },
  94. {
  95. title: "技术来源",
  96. dataIndex: "technologySource",
  97. key: "technologySource",
  98. },
  99. {
  100. title: "研发经费总预算(万元)",
  101. dataIndex: "totalAmount",
  102. key: "totalAmount",
  103. width: 80
  104. },
  105. {
  106. title: "研发经费近三年总支出(万元)",
  107. dataIndex: "recentThreeAmount",
  108. key: "recentThreeAmount",
  109. width: 80
  110. },
  111. {
  112. title: "研发目的及组织实施方式",
  113. dataIndex: "rdObjective",
  114. key: "rdObjective",
  115. render: (text) => {
  116. return (
  117. <Tooltip title={text}>
  118. <div style={{
  119. maxWidth: '300px',
  120. overflow: 'hidden',
  121. textOverflow: "ellipsis",
  122. whiteSpace: 'nowrap',
  123. }}>{text}</div>
  124. </Tooltip>
  125. )
  126. }
  127. },
  128. {
  129. title: "核心技术及创新点",
  130. dataIndex: "coreTechnology",
  131. key: "coreTechnology",
  132. render: (text) => {
  133. return (
  134. <Tooltip title={text}>
  135. <div style={{
  136. maxWidth: '300px',
  137. overflow: 'hidden',
  138. textOverflow: "ellipsis",
  139. whiteSpace: 'nowrap',
  140. }}>{text}</div>
  141. </Tooltip>
  142. )
  143. }
  144. },
  145. {
  146. title: "取得的创段性成果",
  147. dataIndex: "achieveResults",
  148. key: "achieveResults",
  149. render: (text) => {
  150. return (
  151. <Tooltip title={text}>
  152. <div style={{
  153. maxWidth: '300px',
  154. overflow: 'hidden',
  155. textOverflow: "ellipsis",
  156. whiteSpace: 'nowrap',
  157. }}>{text}</div>
  158. </Tooltip>
  159. )
  160. }
  161. },
  162. {
  163. title: "上传时间",
  164. dataIndex: "createTimeStr",
  165. key: "createTimeStr",
  166. width: 120,
  167. },
  168. {
  169. title: "咨询师名称",
  170. dataIndex: "consultantName",
  171. key: "consultantName",
  172. },
  173. {
  174. title: "阅读次数",
  175. dataIndex: "browseCount",
  176. key: "browseCount",
  177. },
  178. {
  179. title: "下载次数",
  180. dataIndex: "downloadCount",
  181. key: "downloadCount",
  182. },
  183. ],
  184. upLoad: {
  185. customRequest: (options) => {
  186. this.setState({
  187. upLoadFileLoading: true,
  188. })
  189. let params = new FormData();
  190. params.append("file", options.file);
  191. $.ajax({
  192. method: "post",
  193. url: globalConfig.context + "/api/admin/RD/import",
  194. async: true,
  195. cache: false,
  196. contentType: false,
  197. processData: false,
  198. data: params
  199. }).done(
  200. function (data) {
  201. this.setState({
  202. upLoadFileLoading: false,
  203. })
  204. if (data.error.length == 0) {
  205. if (data.data.OK == 0) {
  206. if (data.data.ERROR.length == 0) {
  207. message.error("导入未成功,请使用正确模板导入");
  208. } else {
  209. this.onTips(data)
  210. }
  211. this.loadData();
  212. } else {
  213. message.success(`${data.data.OK}条数据导入成功!`);
  214. if (data.data.ERROR.length != 0) {
  215. this.onTips(data)
  216. }
  217. this.loadData();
  218. }
  219. } else {
  220. message.error(data.error[0].message);
  221. }
  222. }.bind(this)
  223. ).always(
  224. function (err) {
  225. if (err.status === 404) {
  226. message.error('数据错误');
  227. }
  228. this.setState({
  229. upLoadFileLoading: false,
  230. });
  231. }.bind(this)
  232. );
  233. },
  234. name: "file",
  235. action: globalConfig.context + "/api/admin/RD/import",
  236. },
  237. };
  238. }
  239. // 导入提示
  240. onTips(data) {
  241. if (data.data.ERROR.length > 0) {
  242. Modal.info({
  243. title: "提示",
  244. width: 700,
  245. content: (
  246. <div>
  247. <div><span style={{ color: "red" }}>{data.data.OK}&nbsp;</span>条数据导入成功!</div>
  248. <div>部分导入失败,您有以下<span style={{ color: "red" }}>&nbsp;{data.data.ERROR.length}&nbsp;</span>条数据有误!</div>
  249. {
  250. data.data.ERROR.map((item, index) =>
  251. <p key={index}><span style={{ color: "red" }}>{item}</span></p>
  252. )
  253. }
  254. {/* <div style={{ color: "red", marginTop: 20 }}>以上数据因研发活动编号重复无法导入</div> */}
  255. </div>
  256. ),
  257. okText: '确定',
  258. });
  259. }
  260. }
  261. // 列表查询
  262. loadData(pageNo) {
  263. const { searchInfor, pagination } = this.state;
  264. this.setState({
  265. loading: true,
  266. });
  267. let datas = Object.assign(searchInfor, {
  268. pageNo: pageNo || 1,
  269. pageSize: pagination.pageSize,
  270. });
  271. $.ajax({
  272. method: "get",
  273. dataType: "json",
  274. crossDomain: false,
  275. url: globalConfig.context + "/api/admin/RD/list",
  276. data: datas,
  277. success: function (data) {
  278. this.setState({
  279. loading: false,
  280. });
  281. if (data.error && data.error.length === 0) {
  282. if (data.data.list) {
  283. pagination.current = data.data.pageNo;
  284. pagination.total = data.data.totalCount;
  285. if (data.data && data.data.list && !data.data.list.length) {
  286. pagination.current = 0;
  287. pagination.total = 0;
  288. }
  289. this.setState({
  290. dataSource: data.data.list,
  291. pagination: this.state.pagination,
  292. pageNo: data.data.pageNo,
  293. });
  294. } else {
  295. this.setState({
  296. dataSource: data.data,
  297. pagination: false,
  298. });
  299. }
  300. } else {
  301. getLoginStatus(data)
  302. }
  303. }.bind(this),
  304. }).always(
  305. function () {
  306. this.setState({
  307. loading: false,
  308. });
  309. }.bind(this)
  310. );
  311. }
  312. // 重置
  313. resetAll() {
  314. this.setState({
  315. searchInfor: JSON.parse(JSON.stringify({})),
  316. }, () => {
  317. this.loadData()
  318. })
  319. }
  320. // 导出
  321. exportExec() {
  322. message.config({
  323. duration: 20,
  324. });
  325. let loading = message.loading("下载中...");
  326. this.setState({
  327. exportPendingLoading: true,
  328. });
  329. let data = {
  330. pageNo: 1,
  331. pageSize: 99999,
  332. };
  333. let obj1 = JSON.parse(JSON.stringify(this.state.searchInfor));
  334. data = Object.assign(data, obj1);
  335. $.ajax({
  336. method: "get",
  337. dataType: "json",
  338. crossDomain: false,
  339. url: globalConfig.context + "/api/admin/RD/exportList",
  340. data,
  341. success: function (data) {
  342. if (data.error.length === 0) {
  343. this.download(data.data);
  344. } else {
  345. message.warning(data.error[0].message);
  346. }
  347. }.bind(this),
  348. }).always(
  349. function () {
  350. loading();
  351. this.setState({
  352. exportPendingLoading: false,
  353. });
  354. }.bind(this)
  355. );
  356. }
  357. // Excel下载
  358. download(fileName) {
  359. window.location.href =
  360. globalConfig.context + "/open/download?fileName=" + fileName;
  361. }
  362. // 模板下载
  363. downloadTemplate(api) {
  364. message.loading("下载中...");
  365. window.location.href = globalConfig.context + api;
  366. }
  367. // 双击
  368. onRowDoubleClick(record) {
  369. this.setState({
  370. visible: true,
  371. rowdata: record,
  372. })
  373. }
  374. // 关闭弹窗
  375. onCancel() {
  376. this.setState({
  377. visible: false,
  378. rowdata: {}
  379. }, () => {
  380. this.loadData(this.state.pageNo)
  381. })
  382. }
  383. componentWillMount() {
  384. this.loadData();
  385. }
  386. render() {
  387. const { columns, searchInfor, upLoadFileLoading } = this.state;
  388. return (
  389. <Spin
  390. size="large"
  391. tip="Loading..."
  392. spinning={upLoadFileLoading}
  393. >
  394. <div className="user-content">
  395. {/* <div className="content-title">
  396. </div> */}
  397. <div className="patent-table">
  398. <div className="user-search">
  399. <RangePicker
  400. style={{ width: 200 }}
  401. value={[
  402. searchInfor.rdStart ? moment(searchInfor.rdStart) : null,
  403. searchInfor.rdEnd ? moment(searchInfor.rdEnd) : null,
  404. ]}
  405. onChange={(data, dataString) => {
  406. this.setState({
  407. searchInfor: Object.assign(searchInfor, {
  408. rdStart: dataString[0],
  409. rdEnd: dataString[1],
  410. }),
  411. });
  412. }}
  413. />
  414. <Input
  415. placeholder={"请输入研发活动名称"}
  416. style={{ width: 180 }}
  417. value={searchInfor.rdName}
  418. onChange={(e) => {
  419. this.setState({
  420. searchInfor: Object.assign(searchInfor, {
  421. rdName: e.target.value,
  422. }),
  423. });
  424. }}
  425. />
  426. <Input
  427. placeholder={"请输入咨询师名称"}
  428. style={{ width: 180 }}
  429. value={searchInfor.consultantName}
  430. onChange={(e) => {
  431. this.setState({
  432. searchInfor: Object.assign(searchInfor, {
  433. consultantName: e.target.value,
  434. }),
  435. });
  436. }}
  437. />
  438. <span>上传时间:</span>
  439. <RangePicker
  440. style={{ width: 200 }}
  441. value={[
  442. searchInfor.startTime ? moment(searchInfor.startTime) : null,
  443. searchInfor.endTime ? moment(searchInfor.endTime) : null,
  444. ]}
  445. onChange={(data, dataString) => {
  446. this.setState({
  447. searchInfor: Object.assign(searchInfor, {
  448. startTime: dataString[0],
  449. endTime: dataString[1],
  450. }),
  451. });
  452. }}
  453. />
  454. <Input
  455. placeholder={"请输入单位名称"}
  456. style={{ width: 180 }}
  457. value={searchInfor.userName}
  458. onChange={(e) => {
  459. this.setState({
  460. searchInfor: Object.assign(searchInfor, {
  461. userName: e.target.value,
  462. }),
  463. });
  464. }}
  465. />
  466. <Button
  467. type="primary"
  468. onClick={() => {
  469. this.loadData();
  470. }}
  471. style={{ margin: "0 5px" }}
  472. >
  473. 搜索
  474. </Button>
  475. <Button
  476. onClick={this.resetAll.bind(this)}
  477. style={{ margin: "0 5px" }}
  478. >
  479. 重置
  480. </Button>
  481. <div className="button">
  482. <Upload {...this.state.upLoad}>
  483. <Button
  484. type="primary"
  485. style={{ marginLeft: 10 }}
  486. >
  487. <Icon type="upload" />
  488. 导入数据
  489. </Button>
  490. </Upload>
  491. <Button
  492. type="primary"
  493. onClick={this.downloadTemplate.bind(this, "/api/admin/RD/downloadTemplate")}
  494. style={{ marginLeft: 10 }}
  495. >
  496. <Icon type="download" />
  497. 下载上传模板
  498. </Button>
  499. <Button
  500. type="primary"
  501. onClick={this.exportExec.bind(this)}
  502. style={{ marginLeft: 10 }}
  503. >
  504. <Icon type="download" />
  505. 导出Excel
  506. </Button>
  507. </div>
  508. </div>
  509. <Spin spinning={this.state.loading}>
  510. <Table
  511. size="middle"
  512. bordered
  513. columns={columns}
  514. scroll={{ x: window.innerWidth > 1536 ? '140%' : window.innerWidth < 1152 ? '290%' : '210%' }}
  515. dataSource={this.state.dataSource}
  516. pagination={this.state.pagination}
  517. onRowDoubleClick={this.onRowDoubleClick.bind(this)}
  518. />
  519. </Spin>
  520. </div>
  521. {
  522. // 详情
  523. this.state.visible &&
  524. <Detail
  525. rowdata={this.state.rowdata}
  526. visible={this.state.visible}
  527. onCancel={this.onCancel.bind(this)}
  528. />
  529. }
  530. </div>
  531. </Spin>
  532. );
  533. }
  534. }
  535. export default Content;