techProduct.jsx 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568
  1. import React from 'react';
  2. import { Icon, Upload, Form, Button, Radio, Input, Spin, Table, message, Select, Modal, Cascader, Transfer, InputNumber } from 'antd';
  3. import { technicalSourceList } from '../../dataDic.js';
  4. import { techFieldList } from '../../DicTechFieldList.js';
  5. import { getTechField, getTechnicalSource, beforeUploadFile, newDownloadFile } from '../../tools.js';
  6. import './techProduct.less';
  7. import moment from 'moment';
  8. import ajax from 'jquery/src/ajax/xhr.js';
  9. import $ from 'jquery/src/ajax';
  10. const TechProductDescFrom = Form.create()(React.createClass({
  11. getInitialState() {
  12. return {
  13. loading: false,
  14. targetKeys: [],
  15. selectedKeys: [],
  16. technicalSourceOption: [],
  17. };
  18. },
  19. componentWillMount() {
  20. let _me = this;
  21. technicalSourceList.map(function (item) {
  22. _me.state.technicalSourceOption.push(
  23. <Select.Option value={item.value} key={10000 + item.value}>{item.key}</Select.Option>
  24. )
  25. });
  26. this.state.targetKeys = this.props.data.intellectualPropertyNumber;
  27. },
  28. componentWillReceiveProps(nextProps) {
  29. if (!this.props.visible && nextProps.visible && nextProps.data) {
  30. this.state.targetKeys = nextProps.data.intellectualPropertyNumber || [];
  31. this.props.form.resetFields();
  32. this.state.fileList = [];
  33. };
  34. },
  35. handleSubmit(e) {
  36. e.preventDefault();
  37. this.props.form.validateFields((err, values) => {
  38. if (!err) {
  39. this.props.spinState(true);
  40. $.ajax({
  41. method: "POST",
  42. dataType: "json",
  43. crossDomain: false,
  44. url: globalConfig.context + "/api/user/cognizance/techProduct",
  45. data: {
  46. id: this.props.data.id,
  47. serialNumber: values.serialNumber,
  48. productName: values.productName,
  49. technicalField1: values.techField[0],
  50. technicalField2: values.techField[1],
  51. technicalField3: values.techField[2],
  52. technicalSource: values.technicalSource,
  53. lastYearRevenue: values.lastYearRevenue,
  54. mainProduct: values.mainProduct,
  55. intellectualPropertyNumber: this.state.targetKeys.join(","),
  56. keyTechnology: values.keyTechnology,
  57. competitiveEdge: values.competitiveEdge,
  58. conditionEffect: values.conditionEffect,
  59. accountUrl: this.state.accountUrl
  60. }
  61. }).done(function (data) {
  62. if (!data.error.length) {
  63. message.success('保存成功!');
  64. this.props.clickOk();
  65. this.props.form.resetFields();
  66. this.state.targetKeys = [];
  67. this.state.selectedKeys = [];
  68. this.props.spinState(false);
  69. } else {
  70. message.warning(data.error[0].message);
  71. this.props.spinState(false);
  72. }
  73. }.bind(this));
  74. }
  75. });
  76. },
  77. intellectualChange(nextTargetKeys, direction, moveKeys) {
  78. this.setState({ targetKeys: nextTargetKeys });
  79. },
  80. intellectualSelectChange(sourceSelectedKeys, targetSelectedKeys) {
  81. this.setState({ selectedKeys: [...sourceSelectedKeys, ...targetSelectedKeys] });
  82. },
  83. render() {
  84. const FormItem = Form.Item;
  85. const { getFieldDecorator } = this.props.form;
  86. const theData = this.props.data;
  87. const formItemLayout = {
  88. labelCol: { span: 10 },
  89. wrapperCol: { span: 12 },
  90. };
  91. const _me = this;
  92. return (
  93. <Form onSubmit={this.handleSubmit} id="techProduct-form">
  94. <div className="clearfix">
  95. <FormItem className="half-item"
  96. {...formItemLayout}
  97. label="编号:ps"
  98. >
  99. {getFieldDecorator('serialNumber', {
  100. rules: [{ required: true, message: '此项为必填项!' }],
  101. initialValue: theData.serialNumber
  102. })(
  103. <Input />
  104. )}
  105. </FormItem>
  106. <FormItem className="half-item"
  107. {...formItemLayout}
  108. label="产品(服务)名称"
  109. >
  110. {getFieldDecorator('productName', {
  111. rules: [{ required: true, message: '此项为必填项!' }],
  112. initialValue: theData.productName
  113. })(
  114. <Input />
  115. )}
  116. </FormItem>
  117. </div>
  118. <div className="clearfix">
  119. <FormItem className="half-item"
  120. {...formItemLayout}
  121. label="技术来源"
  122. >
  123. {getFieldDecorator('technicalSource', {
  124. rules: [{ required: true, message: '此项为必填项!' }],
  125. initialValue: theData.technicalSource
  126. })(
  127. <Select placeholder="选择技术来源"
  128. onChange={(e) => { this.setState({ technicalSource: e }) }}>
  129. {this.state.technicalSourceOption}
  130. </Select>
  131. )}
  132. </FormItem>
  133. <FormItem className="half-item"
  134. labelCol={{ span: 10 }}
  135. label="上年度销售收入(万元)"
  136. >
  137. {getFieldDecorator('lastYearRevenue', {
  138. rules: [{ type: "number", required: true, message: '此项为必填项!' }],
  139. initialValue: theData.lastYearRevenue ? Number(theData.lastYearRevenue) : 0
  140. })(
  141. <InputNumber min={0} max={999999} step={0.01} />
  142. )}
  143. </FormItem>
  144. </div>
  145. <FormItem
  146. labelCol={{ span: 5 }}
  147. wrapperCol={{ span: 16 }}
  148. label="技术领域"
  149. >
  150. {getFieldDecorator('techField', {
  151. rules: [{ type: "array", required: true, message: '此项为必填项!' }],
  152. initialValue: theData.techField
  153. })(
  154. <Cascader
  155. options={techFieldList}
  156. onChange={(value, selectedOptions) => { this.setState({ techField: value }); console.log(value) }}
  157. placeholder="请选择"
  158. showSearch
  159. />
  160. )}
  161. </FormItem>
  162. <div className="clearfix">
  163. <FormItem className="half-item"
  164. {...formItemLayout}
  165. label="是否主要产品(服务)"
  166. >
  167. {getFieldDecorator('mainProduct', {
  168. rules: [{ type: "number", required: true, message: '此项为必填项!' }],
  169. initialValue: theData.mainProduct
  170. })(
  171. <Radio.Group>
  172. <Radio value={1}>是</Radio>
  173. <Radio value={0}>否</Radio>
  174. </Radio.Group>
  175. )}
  176. </FormItem>
  177. </div>
  178. <p>知识产权编号:</p>
  179. <Transfer
  180. dataSource={this.props.mockData}
  181. listStyle={{
  182. width: 300,
  183. height: 300,
  184. }}
  185. titles={['未选择', '已选择']}
  186. targetKeys={this.state.targetKeys}
  187. selectedKeys={this.state.selectedKeys}
  188. onChange={this.intellectualChange}
  189. onSelectChange={this.intellectualSelectChange}
  190. render={item => `${item.name}-${item.key}`}
  191. />
  192. <div className="clearfix">
  193. <FormItem className="half-item"
  194. labelCol={{ span: 0 }}
  195. wrapperCol={{ span: 22 }}
  196. >
  197. <p>关键技术及主要技术指标(限400字)</p>
  198. {getFieldDecorator('keyTechnology', {
  199. rules: [{ required: true, message: '此项为必填项!' }],
  200. initialValue: theData.keyTechnology
  201. })(
  202. <Input type='textarea' rows={6} onChange={(e) => { if (e.target.value.length > 400) { return; } }} />
  203. )}
  204. </FormItem>
  205. <FormItem className="half-item"
  206. labelCol={{ span: 0 }}
  207. wrapperCol={{ span: 22 }}
  208. >
  209. <p>与同类产品(服务)的竞争优势(限400字)</p>
  210. {getFieldDecorator('competitiveEdge', {
  211. rules: [{ required: true, message: '此项为必填项!' }],
  212. initialValue: theData.competitiveEdge
  213. })(
  214. <Input type='textarea' rows={6} onChange={(e) => { if (e.target.value.length > 400) { return; } }} />
  215. )}
  216. </FormItem>
  217. <FormItem className="half-item"
  218. labelCol={{ span: 0 }}
  219. wrapperCol={{ span: 22 }}
  220. >
  221. <p style={{ lineHeight: "32px" }}>知识产权获得情况及其对产品(服务)在技术上发挥的支持作用(限400字)*</p>
  222. {getFieldDecorator('conditionEffect', {
  223. rules: [{ required: true, message: '此项为必填项!' }],
  224. initialValue: theData.conditionEffect
  225. })(
  226. <Input type='textarea' rows={6} onChange={(e) => { if (e.target.value.length > 400) { return; } }} />
  227. )}
  228. </FormItem>
  229. </div>
  230. <div style={{ width: '50%' }}>
  231. <Upload
  232. name="ratepay"
  233. action={globalConfig.context + "/api/user/cognizance/uploadTecProduct"}
  234. data={{ 'sign': 'tech_product' }}
  235. beforeUpload={beforeUploadFile}
  236. fileList={this.state.fileList}
  237. onChange={(info) => {
  238. if (info.file.status !== 'uploading') {
  239. console.log(info.file, info.fileList);
  240. }
  241. if (info.file.status === 'done') {
  242. if (!info.file.response.error.length) {
  243. message.success(`${info.file.name} 文件上传成功!`);
  244. } else {
  245. message.warning(info.file.response.error[0].message);
  246. return;
  247. };
  248. this.state.accountUrl = info.file.response.data;
  249. } else if (info.file.status === 'error') {
  250. message.error(`${info.file.name} 文件上传失败。`);
  251. };
  252. this.setState({ fileList: info.fileList.slice(-1) });
  253. }}
  254. >
  255. <Button><Icon type="upload" /> 上传高新技术产品台帐 </Button>
  256. </Upload>
  257. <p style={{ marginTop: '10px' }}>{theData.accountUrl ? <a onClick={newDownloadFile.bind(null, theData.id, 'tech_product', '/api/user/cognizance/downloadTecProduct')}>{theData.accountDownloadFileName}</a> : <span><Icon type="exclamation-circle" style={{ color: '#ffbf00', marginRight: '6px' }} />未上传!</span>}</p>
  258. </div>
  259. <FormItem style={{ marginTop: '20px' }}>
  260. <Button className="set-submit" type="primary" htmlType="submit">保存</Button>
  261. <Button type="ghost" style={{ marginLeft: '20px' }} onClick={this.props.closeModal}>取消</Button>
  262. </FormItem>
  263. </Form >
  264. );
  265. },
  266. }));
  267. const TechProductDesc = React.createClass({
  268. getInitialState() {
  269. return {
  270. visible: false,
  271. loading: false
  272. };
  273. },
  274. componentWillReceiveProps(nextProps) {
  275. this.state.visible = nextProps.showDesc
  276. },
  277. showModal() {
  278. this.setState({
  279. visible: true,
  280. });
  281. },
  282. handleOk() {
  283. this.setState({
  284. visible: false,
  285. });
  286. this.props.closeDesc(false, true);
  287. },
  288. handleCancel(e) {
  289. this.setState({
  290. visible: false,
  291. });
  292. this.props.closeDesc(false);
  293. },
  294. spinChange(e) {
  295. this.setState({
  296. loading: e
  297. });
  298. },
  299. render() {
  300. return (
  301. <div className="patent-addNew">
  302. <Modal maskClosable={false} title="上年度高新技术产品(服务)情况表" visible={this.state.visible}
  303. onOk={this.handleOk} onCancel={this.handleCancel}
  304. width='1000px'
  305. footer='' >
  306. <Spin spinning={this.state.loading} className='spin-box'>
  307. <TechProductDescFrom
  308. data={this.props.data}
  309. mockData={this.props.mockData}
  310. spinState={this.spinChange}
  311. closeModal={this.handleCancel}
  312. visible={this.state.visible}
  313. clickOk={this.handleOk} />
  314. </Spin>
  315. </Modal>
  316. </div>
  317. );
  318. },
  319. });
  320. const TechProduct = React.createClass({
  321. loadData(pageNo) {
  322. this.state.data = [];
  323. this.setState({
  324. loading: true
  325. });
  326. $.when($.ajax({
  327. method: "get",
  328. dataType: "json",
  329. crossDomain: false,
  330. url: globalConfig.context + "/api/user/cognizance/techProductList",
  331. data: {
  332. pageNo: pageNo || 1,
  333. pageSize: this.state.pagination.pageSize
  334. }
  335. }), $.ajax({
  336. method: "get",
  337. dataType: "json",
  338. crossDomain: false,
  339. url: globalConfig.context + "/api/user/cognizance/intellectualList",
  340. data: {
  341. pageNo: pageNo || 1,
  342. pageSize: 99,
  343. }
  344. })).done((data1, data2) => {
  345. let data = data1[0];
  346. let intellectualList = data2[0];
  347. if (!data.data || !data.data.list) {
  348. if (data.error && data.error.length) {
  349. message.warning(data.error[0].message);
  350. this.state.ButtonDisabled = true;
  351. };
  352. return;
  353. };
  354. if (!intellectualList.data || !intellectualList.data.list) {
  355. if (intellectualList.error && intellectualList.error.length) {
  356. message.warning(intellectualList.error[0].message);
  357. this.state.ButtonDisabled = true;
  358. };
  359. return;
  360. };
  361. let theArr = [];
  362. for (let i = 0; i < intellectualList.data.list.length; i++) {
  363. theArr.push({
  364. key: intellectualList.data.list[i].intellectualPropertyNumber,
  365. name: intellectualList.data.list[i].intellectualPropertyName
  366. });
  367. };
  368. this.state.mockData = theArr;
  369. for (let i = 0; i < data.data.list.length; i++) {
  370. let thisdata = data.data.list[i];
  371. this.state.data.push({
  372. key: i,
  373. id: thisdata.id,
  374. uid: thisdata.uid,
  375. mockData: this.state.mockData,
  376. serialNumber: thisdata.serialNumber,
  377. productName: thisdata.productName,
  378. techField: [thisdata.technicalField1, thisdata.technicalField2, thisdata.technicalField3],
  379. technicalField: getTechField(thisdata.technicalField1, thisdata.technicalField2, thisdata.technicalField3),
  380. technicalField1: thisdata.technicalField1,
  381. technicalField2: thisdata.technicalField2,
  382. technicalField3: thisdata.technicalField3,
  383. technicalSource: String(thisdata.technicalSource),
  384. lastYearRevenue: thisdata.lastYearRevenue,
  385. mainProduct: thisdata.mainProduct,
  386. PropertyNumber: thisdata.intellectualPropertyNumber,
  387. intellectualPropertyNumber: thisdata.intellectualPropertyNumber ? thisdata.intellectualPropertyNumber.split(",") : [],
  388. keyTechnology: thisdata.keyTechnology,
  389. competitiveEdge: thisdata.competitiveEdge,
  390. conditionEffect: thisdata.conditionEffect,
  391. year: thisdata.year,
  392. createTime: thisdata.createTime,
  393. accountDownloadFileName: thisdata.accountDownloadFileName,
  394. accountUrl: thisdata.accountUrl
  395. });
  396. };
  397. this.state.pagination.current = data.data.pageNo;
  398. this.state.pagination.total = data.data.totalCount;
  399. this.setState({
  400. dataSource: this.state.data,
  401. pagination: this.state.pagination
  402. });
  403. }).always(function () {
  404. this.setState({
  405. loading: false
  406. });
  407. }.bind(this));
  408. },
  409. getInitialState() {
  410. return {
  411. selectedRowKeys: [],
  412. selectedRows: [],
  413. loading: false,
  414. pagination: {
  415. defaultCurrent: 1,
  416. defaultPageSize: 10,
  417. showQuickJumper: true,
  418. pageSize: 10,
  419. onChange: function (page) {
  420. this.loadData(page);
  421. }.bind(this),
  422. showTotal: function (total) {
  423. return '共' + total + '条数据';
  424. }
  425. },
  426. columns: [
  427. {
  428. title: '产品编号',
  429. dataIndex: 'serialNumber',
  430. key: 'serialNumber'
  431. }, {
  432. title: '产品(服务)名称',
  433. dataIndex: 'productName',
  434. key: 'productName'
  435. }, {
  436. title: '技术领域',
  437. dataIndex: 'technicalField',
  438. key: 'technicalField'
  439. }, {
  440. title: '技术来源',
  441. dataIndex: 'technicalSource',
  442. key: 'technicalSource',
  443. render: (text) => { return getTechnicalSource(text) }
  444. }, {
  445. title: '上年度销售收入(万元)',
  446. dataIndex: 'lastYearRevenue',
  447. key: 'lastYearRevenue'
  448. }, {
  449. title: '是否主要产品(服务)',
  450. dataIndex: 'mainProduct',
  451. key: 'mainProduct',
  452. render: (text) => { if (text == "1") { return '是' } else { return '否' } }
  453. }, {
  454. title: '知识产权编号',
  455. dataIndex: 'PropertyNumber',
  456. key: 'PropertyNumber'
  457. }
  458. ],
  459. dataSource: []
  460. };
  461. },
  462. componentWillMount() {
  463. this.loadData();
  464. },
  465. tableRowClick(record, index) {
  466. this.state.RowData = record;
  467. this.setState({
  468. showDesc: true
  469. });
  470. },
  471. delectRow() {
  472. let deletedIds = [];
  473. for (let idx = 0; idx < this.state.selectedRows.length; idx++) {
  474. let rowItem = this.state.selectedRows[idx];
  475. if (rowItem.id) {
  476. deletedIds.push(rowItem.id)
  477. }
  478. }
  479. this.setState({
  480. selectedRowKeys: [],
  481. loading: deletedIds.length > 0
  482. });
  483. $.ajax({
  484. method: "POST",
  485. dataType: "json",
  486. crossDomain: false,
  487. url: globalConfig.context + "/api/user/cognizance/deleteTechProduct",
  488. data: {
  489. ids: deletedIds
  490. }
  491. }).done(function (data) {
  492. if (!data.error.length) {
  493. message.success('删除成功!');
  494. this.setState({
  495. loading: false,
  496. });
  497. } else {
  498. message.warning(data.error[0].message);
  499. };
  500. this.loadData();
  501. }.bind(this));
  502. },
  503. closeDesc(e, s) {
  504. this.state.showDesc = e;
  505. if (s) {
  506. this.loadData();
  507. };
  508. },
  509. search() {
  510. this.loadData();
  511. },
  512. reset() {
  513. this.loadData();
  514. },
  515. render() {
  516. const rowSelection = {
  517. selectedRowKeys: this.state.selectedRowKeys,
  518. onChange: (selectedRowKeys, selectedRows) => {
  519. this.setState({
  520. selectedRows: selectedRows,
  521. selectedRowKeys: selectedRowKeys
  522. });
  523. }
  524. };
  525. const hasSelected = this.state.selectedRowKeys.length > 0;
  526. return (
  527. <div className="user-content" >
  528. <div className="content-title">
  529. <span>高新技术产品(服务)情况表</span>
  530. </div>
  531. <div className="user-search">
  532. <p>
  533. <Button style={{ background: "#ea0862", border: "none", color: "#fff" }}
  534. disabled={this.state.ButtonDisabled}
  535. onClick={this.tableRowClick}>添加<Icon type="plus" /></Button>
  536. <Button style={{ background: "#3fcf9e", border: "none", color: "#fff" }}
  537. disabled={!hasSelected}
  538. onClick={this.delectRow}>删除<Icon type="minus" /></Button>
  539. </p>
  540. </div>
  541. <div className="patent-table">
  542. <Spin spinning={this.state.loading}>
  543. <Table columns={this.state.columns}
  544. dataSource={this.state.dataSource}
  545. pagination={this.state.pagination}
  546. rowSelection={rowSelection}
  547. onRowClick={this.tableRowClick} />
  548. </Spin>
  549. </div>
  550. <TechProductDesc data={this.state.RowData}
  551. mockData={this.state.mockData}
  552. showDesc={this.state.showDesc} closeDesc={this.closeDesc} />
  553. </div >
  554. );
  555. }
  556. });
  557. export default TechProduct;