techProduct.jsx 26 KB

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