detail.jsx 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449
  1. import React from "react";
  2. import { Spin, message, Modal, Button, DatePicker, Input, Icon } from "antd";
  3. import ajax from "jquery/src/ajax/xhr.js";
  4. import $ from "jquery/src/ajax";
  5. import './detail.less';
  6. import moment from "moment";
  7. import ReactToPrint from "react-to-print";
  8. import { getPdf } from "../../../../utils/tools";
  9. const { RangePicker } = DatePicker;
  10. const detail = React.createClass({
  11. getInitialState() {
  12. return {
  13. loading: false,
  14. change: false,
  15. data: {},
  16. num: 0,
  17. };
  18. },
  19. // 获取详情
  20. getInfo() {
  21. this.setState({
  22. loading: true,
  23. })
  24. $.ajax({
  25. method: 'get',
  26. dataType: 'json',
  27. crossDomain: false,
  28. url: globalConfig.context + '/api/admin/RD/details',
  29. data: {
  30. id: this.props.rowdata.id,
  31. },
  32. success: function (data) {
  33. this.setState({
  34. data: data.data,
  35. })
  36. this.state.num == 0 && this.addBrowse()
  37. }.bind(this),
  38. }).always(
  39. function () {
  40. this.setState({
  41. loading: false,
  42. })
  43. }.bind(this)
  44. )
  45. },
  46. // 浏览+1
  47. addBrowse() {
  48. let i = 20
  49. this.timer = setInterval(() => {
  50. i--;
  51. if (i == 0) {
  52. clearInterval(this.timer);
  53. $.ajax({
  54. method: 'post',
  55. dataType: 'json',
  56. crossDomain: false,
  57. url: globalConfig.context + '/api/admin/RD/addBrowse',
  58. data: {
  59. id: this.props.rowdata.id,
  60. },
  61. success: function (data) {
  62. this.setState({
  63. num: 1
  64. })
  65. }.bind(this),
  66. }).always(
  67. function () {
  68. }.bind(this)
  69. )
  70. }
  71. }, 1000)
  72. },
  73. // 下载+1
  74. addDownload() {
  75. $.ajax({
  76. method: 'post',
  77. dataType: 'json',
  78. crossDomain: false,
  79. url: globalConfig.context + '/api/admin/RD/addDownload',
  80. data: {
  81. id: this.props.rowdata.id,
  82. },
  83. success: function (data) {
  84. this.state.data.downloadCount++
  85. this.setState({ data: this.state.data });
  86. // this.getInfo()
  87. }.bind(this),
  88. }).always(
  89. function () {
  90. }.bind(this)
  91. )
  92. },
  93. // PDF下载
  94. pdfDownload() {
  95. message.loading("下载中...");
  96. window.location.href = globalConfig.context + `/api/admin/RD/downloadDetailsPDF?id=${this.props.rowdata.id}`;
  97. // getPdf(this.state.data.rdName, "pdf")
  98. this.addDownload()
  99. },
  100. // Word下载
  101. wordDownload() {
  102. message.loading("下载中...");
  103. window.location.href = globalConfig.context + `/api/admin/RD/downloadDetailsWord?id=${this.props.rowdata.id}`;
  104. this.addDownload()
  105. },
  106. // 修改详情
  107. update() {
  108. const { data } = this.state
  109. // if (!data.userName) {
  110. // message.warning("公司名称不能为空!");
  111. // return
  112. // }
  113. // if (!data.consultantName) {
  114. // message.warning("项目负责人不能为空!");
  115. // return
  116. // }
  117. // if (!data.technicalField) {
  118. // message.warning("技术领域不能为空!");
  119. // return
  120. // }
  121. // if (!data.technologySource) {
  122. // message.warning("技术来源不能为空!");
  123. // return
  124. // }
  125. // if (!data.totalAmount) {
  126. // message.warning("研发费用总预计不能为空!");
  127. // return
  128. // }
  129. // if (!data.rdObjective) {
  130. // message.warning("研发目的/立项目的/实施方式不能为空!");
  131. // return
  132. // }
  133. // if (!data.coreTechnology) {
  134. // message.warning("核心技术/创新点不能为空!");
  135. // return
  136. // }
  137. // if (!data.achieveResults) {
  138. // message.warning("成果不能为空!");
  139. // return
  140. // }
  141. this.setState({
  142. loading: true,
  143. });
  144. $.ajax({
  145. method: "POST",
  146. dataType: "json",
  147. crossDomain: false,
  148. url: globalConfig.context + "/api/admin/RD/update",
  149. data:
  150. {
  151. id: data.id,
  152. ipNo: data.ipNo,
  153. rdNo: data.rdNo,
  154. rdStartStr: data.rdStartStr,
  155. rdEndStr: data.rdEndStr,
  156. userName: data.userName,
  157. consultantName: data.consultantName,
  158. technicalField: data.technicalField,
  159. technologySource: data.technologySource,
  160. totalAmount: data.totalAmount,
  161. rdObjective: data.rdObjective,
  162. coreTechnology: data.coreTechnology,
  163. achieveResults: data.achieveResults,
  164. },
  165. }).done(
  166. function (data) {
  167. this.setState({
  168. loading: false,
  169. });
  170. if (!data.error.length) {
  171. this.getInfo();
  172. message.success("保存成功!");
  173. this.setState({
  174. change: false
  175. })
  176. } else {
  177. message.warning(data.error[0].message);
  178. }
  179. }.bind(this)
  180. );
  181. },
  182. componentWillMount() {
  183. this.getInfo();
  184. },
  185. componentWillUnmount() {
  186. clearInterval(this.timer)
  187. },
  188. render() {
  189. const { data, change } = this.state
  190. return (
  191. <Modal
  192. title={null}
  193. visible={this.props.visible}
  194. onCancel={this.props.onCancel}
  195. footer={null}
  196. width={874}
  197. maskClosable={false}
  198. >
  199. <div
  200. style={{
  201. float: "right",
  202. marginTop: 10,
  203. position: "absolute",
  204. top: 0,
  205. right: 60,
  206. zIndex: 9,
  207. }}
  208. >
  209. {/* <ReactToPrint
  210. trigger={() => (
  211. <Button
  212. type="primary"
  213. style={{ marginRight: 20 }}
  214. >
  215. 打印
  216. </Button>
  217. )}
  218. content={() => this.refs.all}
  219. /> */}
  220. <Button
  221. disabled={change}
  222. type="primary"
  223. style={{ marginLeft: 0 }}
  224. onClick={this.wordDownload.bind(this)}
  225. >
  226. <Icon type="download" />
  227. WORD下载
  228. </Button>
  229. <Button
  230. disabled={change}
  231. type="primary"
  232. style={{ marginLeft: 20 }}
  233. onClick={this.pdfDownload.bind(this)}
  234. >
  235. <Icon type="download" />
  236. PDF下载
  237. </Button>
  238. <div style={{ color: "#58A3FF" }}>已下载次数:{data.downloadCount}</div>
  239. </div>
  240. <Spin spinning={this.state.loading}>
  241. <div
  242. className="pdfcount"
  243. id="pdf"
  244. ref={(e) => {
  245. this.refs.all = e;
  246. }}
  247. >
  248. <h1 style={{ textAlign: "center", marginBottom: 30 }}>{data.rdName}</h1>
  249. <div className="formitem">项目起止时间:
  250. {
  251. change ?
  252. <RangePicker
  253. allowClear={false}
  254. style={{ width: 200 }}
  255. value={[
  256. data.rdStartStr ? moment(data.rdStartStr) : null,
  257. data.rdEndStr ? moment(data.rdEndStr) : null,
  258. ]}
  259. onChange={(datas, dataString) => {
  260. this.setState({
  261. data: Object.assign(data, {
  262. rdStartStr: dataString[0],
  263. rdEndStr: dataString[1],
  264. }),
  265. });
  266. }}
  267. />
  268. :
  269. <span>{!data.rdStartStr ? "" : (data.rdStartStr + "~" + data.rdEndStr)}</span>
  270. }
  271. </div>
  272. <div className="formitems">公司名称:
  273. {
  274. change ?
  275. <Input
  276. placeholder=""
  277. value={data.userName}
  278. onChange={(e) => {
  279. data.userName = e.target.value
  280. this.setState({ data });
  281. }}
  282. />
  283. : <span>{data.userName}</span>
  284. }
  285. </div>
  286. <div className="formitems">项目负责人:
  287. {
  288. change ?
  289. <Input
  290. placeholder=""
  291. value={data.consultantName}
  292. onChange={(e) => {
  293. data.consultantName = e.target.value
  294. this.setState({ data });
  295. }}
  296. />
  297. : <span>{data.consultantName}</span>
  298. }
  299. </div>
  300. <div className="formitems">技术领域:
  301. {
  302. change ?
  303. <Input
  304. placeholder=""
  305. value={data.technicalField}
  306. onChange={(e) => {
  307. data.technicalField = e.target.value
  308. this.setState({ data });
  309. }}
  310. />
  311. : <span>{data.technicalField}</span>
  312. }
  313. </div>
  314. <div className="formitems">技术来源:
  315. {
  316. change ?
  317. <Input
  318. placeholder=""
  319. value={data.technologySource}
  320. onChange={(e) => {
  321. data.technologySource = e.target.value
  322. this.setState({ data });
  323. }}
  324. />
  325. : <span>{data.technologySource}</span>
  326. }
  327. </div>
  328. <div className="formitem">研发费用总预计:
  329. {
  330. change ?
  331. <Input
  332. type='number'
  333. placeholder=""
  334. value={data.totalAmount}
  335. style={{ width: 80 }}
  336. onChange={(e) => {
  337. data.totalAmount = e.target.value
  338. this.setState({ data });
  339. }}
  340. />
  341. : <span>{data.totalAmount}</span>
  342. }
  343. &nbsp;&nbsp;{"万元"}
  344. </div>
  345. <div className="formitem">研发目的/立项目的/实施方式
  346. {
  347. change ?
  348. <Input
  349. type="textarea"
  350. placeholder=""
  351. autosize={{ minRows: 4 }}
  352. value={data.rdObjective}
  353. onChange={(e) => {
  354. data.rdObjective = e.target.value
  355. this.setState({ data });
  356. }}
  357. />
  358. : <p>{data.rdObjective}</p>
  359. }
  360. </div>
  361. <div className="formitem">核心技术/创新点
  362. {
  363. change ?
  364. <Input
  365. type="textarea"
  366. placeholder=""
  367. autosize={{ minRows: 4 }}
  368. value={data.coreTechnology}
  369. onChange={(e) => {
  370. data.coreTechnology = e.target.value
  371. this.setState({ data });
  372. }}
  373. />
  374. : <p>{data.coreTechnology}</p>
  375. }
  376. </div>
  377. <div className="formitem">成果
  378. {
  379. change ?
  380. <Input
  381. type="textarea"
  382. placeholder=""
  383. autosize={{ minRows: 4 }}
  384. value={data.achieveResults}
  385. onChange={(e) => {
  386. data.achieveResults = e.target.value
  387. this.setState({ data });
  388. }}
  389. />
  390. : <p>{data.achieveResults}</p>
  391. }
  392. </div>
  393. </div>
  394. </Spin>
  395. {
  396. change
  397. ? <div
  398. style={{
  399. position: "absolute",
  400. bottom: 10,
  401. right: 60,
  402. zIndex: 9,
  403. }}
  404. >
  405. <Button
  406. type="primary"
  407. style={{ marginLeft: 20 }}
  408. onClick={() => { this.setState({ change: false }) }}
  409. >
  410. 取消
  411. </Button>
  412. <Button
  413. type="primary"
  414. style={{ marginLeft: 20 }}
  415. onClick={this.update.bind(this)}
  416. >
  417. 保存
  418. </Button>
  419. </div>
  420. : <Button
  421. type="primary"
  422. style={{
  423. position: "absolute",
  424. bottom: 10,
  425. right: 60,
  426. zIndex: 9,
  427. }}
  428. onClick={() => { this.setState({ change: true }) }}
  429. >
  430. 编辑
  431. </Button>
  432. }
  433. </Modal>
  434. );
  435. },
  436. });
  437. export default detail;