123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449 |
- import React from "react";
- import { Spin, message, Modal, Button, DatePicker, Input, Icon } from "antd";
- import ajax from "jquery/src/ajax/xhr.js";
- import $ from "jquery/src/ajax";
- import './detail.less';
- import moment from "moment";
- import ReactToPrint from "react-to-print";
- import { getPdf } from "../../../../utils/tools";
- const { RangePicker } = DatePicker;
- const detail = React.createClass({
- getInitialState() {
- return {
- loading: false,
- change: false,
- data: {},
- num: 0,
- };
- },
- // 获取详情
- getInfo() {
- this.setState({
- loading: true,
- })
- $.ajax({
- method: 'get',
- dataType: 'json',
- crossDomain: false,
- url: globalConfig.context + '/api/admin/RD/details',
- data: {
- id: this.props.rowdata.id,
- },
- success: function (data) {
- this.setState({
- data: data.data,
- })
- this.state.num == 0 && this.addBrowse()
- }.bind(this),
- }).always(
- function () {
- this.setState({
- loading: false,
- })
- }.bind(this)
- )
- },
- // 浏览+1
- addBrowse() {
- let i = 20
- this.timer = setInterval(() => {
- i--;
- if (i == 0) {
- clearInterval(this.timer);
- $.ajax({
- method: 'post',
- dataType: 'json',
- crossDomain: false,
- url: globalConfig.context + '/api/admin/RD/addBrowse',
- data: {
- id: this.props.rowdata.id,
- },
- success: function (data) {
- this.setState({
- num: 1
- })
- }.bind(this),
- }).always(
- function () {
- }.bind(this)
- )
- }
- }, 1000)
- },
- // 下载+1
- addDownload() {
- $.ajax({
- method: 'post',
- dataType: 'json',
- crossDomain: false,
- url: globalConfig.context + '/api/admin/RD/addDownload',
- data: {
- id: this.props.rowdata.id,
- },
- success: function (data) {
- this.state.data.downloadCount++
- this.setState({ data: this.state.data });
- // this.getInfo()
- }.bind(this),
- }).always(
- function () {
- }.bind(this)
- )
- },
- // PDF下载
- pdfDownload() {
- message.loading("下载中...");
- window.location.href = globalConfig.context + `/api/admin/RD/downloadDetailsPDF?id=${this.props.rowdata.id}`;
- // getPdf(this.state.data.rdName, "pdf")
- this.addDownload()
- },
- // Word下载
- wordDownload() {
- message.loading("下载中...");
- window.location.href = globalConfig.context + `/api/admin/RD/downloadDetailsWord?id=${this.props.rowdata.id}`;
- this.addDownload()
- },
- // 修改详情
- update() {
- const { data } = this.state
- // if (!data.userName) {
- // message.warning("公司名称不能为空!");
- // return
- // }
- // if (!data.consultantName) {
- // message.warning("项目负责人不能为空!");
- // return
- // }
- // if (!data.technicalField) {
- // message.warning("技术领域不能为空!");
- // return
- // }
- // if (!data.technologySource) {
- // message.warning("技术来源不能为空!");
- // return
- // }
- // if (!data.totalAmount) {
- // message.warning("研发费用总预计不能为空!");
- // return
- // }
- // if (!data.rdObjective) {
- // message.warning("研发目的/立项目的/实施方式不能为空!");
- // return
- // }
- // if (!data.coreTechnology) {
- // message.warning("核心技术/创新点不能为空!");
- // return
- // }
- // if (!data.achieveResults) {
- // message.warning("成果不能为空!");
- // return
- // }
- this.setState({
- loading: true,
- });
- $.ajax({
- method: "POST",
- dataType: "json",
- crossDomain: false,
- url: globalConfig.context + "/api/admin/RD/update",
- data:
- {
- id: data.id,
- ipNo: data.ipNo,
- rdNo: data.rdNo,
- rdStartStr: data.rdStartStr,
- rdEndStr: data.rdEndStr,
- userName: data.userName,
- consultantName: data.consultantName,
- technicalField: data.technicalField,
- technologySource: data.technologySource,
- totalAmount: data.totalAmount,
- rdObjective: data.rdObjective,
- coreTechnology: data.coreTechnology,
- achieveResults: data.achieveResults,
- },
- }).done(
- function (data) {
- this.setState({
- loading: false,
- });
- if (!data.error.length) {
- this.getInfo();
- message.success("保存成功!");
- this.setState({
- change: false
- })
- } else {
- message.warning(data.error[0].message);
- }
- }.bind(this)
- );
- },
- componentWillMount() {
- this.getInfo();
- },
- componentWillUnmount() {
- clearInterval(this.timer)
- },
- render() {
- const { data, change } = this.state
- return (
- <Modal
- title={null}
- visible={this.props.visible}
- onCancel={this.props.onCancel}
- footer={null}
- width={874}
- maskClosable={false}
- >
- <div
- style={{
- float: "right",
- marginTop: 10,
- position: "absolute",
- top: 0,
- right: 60,
- zIndex: 9,
- }}
- >
- {/* <ReactToPrint
- trigger={() => (
- <Button
- type="primary"
- style={{ marginRight: 20 }}
- >
- 打印
- </Button>
- )}
- content={() => this.refs.all}
- /> */}
- <Button
- disabled={change}
- type="primary"
- style={{ marginLeft: 0 }}
- onClick={this.wordDownload.bind(this)}
- >
- <Icon type="download" />
- WORD下载
- </Button>
- <Button
- disabled={change}
- type="primary"
- style={{ marginLeft: 20 }}
- onClick={this.pdfDownload.bind(this)}
- >
- <Icon type="download" />
- PDF下载
- </Button>
- <div style={{ color: "#58A3FF" }}>已下载次数:{data.downloadCount}</div>
- </div>
- <Spin spinning={this.state.loading}>
- <div
- className="pdfcount"
- id="pdf"
- ref={(e) => {
- this.refs.all = e;
- }}
- >
- <h1 style={{ textAlign: "center", marginBottom: 30 }}>{data.rdName}</h1>
- <div className="formitem">项目起止时间:
- {
- change ?
- <RangePicker
- allowClear={false}
- style={{ width: 200 }}
- value={[
- data.rdStartStr ? moment(data.rdStartStr) : null,
- data.rdEndStr ? moment(data.rdEndStr) : null,
- ]}
- onChange={(datas, dataString) => {
- this.setState({
- data: Object.assign(data, {
- rdStartStr: dataString[0],
- rdEndStr: dataString[1],
- }),
- });
- }}
- />
- :
- <span>{!data.rdStartStr ? "" : (data.rdStartStr + "~" + data.rdEndStr)}</span>
- }
- </div>
- <div className="formitems">公司名称:
- {
- change ?
- <Input
- placeholder=""
- value={data.userName}
- onChange={(e) => {
- data.userName = e.target.value
- this.setState({ data });
- }}
- />
- : <span>{data.userName}</span>
- }
- </div>
- <div className="formitems">项目负责人:
- {
- change ?
- <Input
- placeholder=""
- value={data.consultantName}
- onChange={(e) => {
- data.consultantName = e.target.value
- this.setState({ data });
- }}
- />
- : <span>{data.consultantName}</span>
- }
- </div>
- <div className="formitems">技术领域:
- {
- change ?
- <Input
- placeholder=""
- value={data.technicalField}
- onChange={(e) => {
- data.technicalField = e.target.value
- this.setState({ data });
- }}
- />
- : <span>{data.technicalField}</span>
- }
- </div>
- <div className="formitems">技术来源:
- {
- change ?
- <Input
- placeholder=""
- value={data.technologySource}
- onChange={(e) => {
- data.technologySource = e.target.value
- this.setState({ data });
- }}
- />
- : <span>{data.technologySource}</span>
- }
- </div>
- <div className="formitem">研发费用总预计:
- {
- change ?
- <Input
- type='number'
- placeholder=""
- value={data.totalAmount}
- style={{ width: 80 }}
- onChange={(e) => {
- data.totalAmount = e.target.value
- this.setState({ data });
- }}
- />
- : <span>{data.totalAmount}</span>
- }
- {"万元"}
- </div>
- <div className="formitem">研发目的/立项目的/实施方式
- {
- change ?
- <Input
- type="textarea"
- placeholder=""
- autosize={{ minRows: 4 }}
- value={data.rdObjective}
- onChange={(e) => {
- data.rdObjective = e.target.value
- this.setState({ data });
- }}
- />
- : <p>{data.rdObjective}</p>
- }
- </div>
- <div className="formitem">核心技术/创新点
- {
- change ?
- <Input
- type="textarea"
- placeholder=""
- autosize={{ minRows: 4 }}
- value={data.coreTechnology}
- onChange={(e) => {
- data.coreTechnology = e.target.value
- this.setState({ data });
- }}
- />
- : <p>{data.coreTechnology}</p>
- }
- </div>
- <div className="formitem">成果
- {
- change ?
- <Input
- type="textarea"
- placeholder=""
- autosize={{ minRows: 4 }}
- value={data.achieveResults}
- onChange={(e) => {
- data.achieveResults = e.target.value
- this.setState({ data });
- }}
- />
- : <p>{data.achieveResults}</p>
- }
- </div>
- </div>
- </Spin>
- {
- change
- ? <div
- style={{
- position: "absolute",
- bottom: 10,
- right: 60,
- zIndex: 9,
- }}
- >
- <Button
- type="primary"
- style={{ marginLeft: 20 }}
- onClick={() => { this.setState({ change: false }) }}
- >
- 取消
- </Button>
- <Button
- type="primary"
- style={{ marginLeft: 20 }}
- onClick={this.update.bind(this)}
- >
- 保存
- </Button>
- </div>
- : <Button
- type="primary"
- style={{
- position: "absolute",
- bottom: 10,
- right: 60,
- zIndex: 9,
- }}
- onClick={() => { this.setState({ change: true }) }}
- >
- 编辑
- </Button>
- }
- </Modal>
- );
- },
- });
- export default detail;
|