techProduct.jsx 23 KB

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