techProduct.jsx 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588
  1. import React from 'react';
  2. import { Switch, 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 { getPreview, getTechField, getTechnicalSource, beforeUploadFile, newDownloadFile, getProportion, saveProportion } from '../../../../tools.js';
  6. import moment from 'moment';
  7. import ajax from 'jquery/src/ajax/xhr.js';
  8. import $ from 'jquery/src/ajax';
  9. const TechProductDescFrom = Form.create()(React.createClass({
  10. getInitialState() {
  11. return {
  12. loading: false,
  13. targetKeys: [],
  14. selectedKeys: [],
  15. technicalSourceOption: [],
  16. };
  17. },
  18. componentWillMount() {
  19. let _me = this;
  20. technicalSourceList.map(function (item) {
  21. _me.state.technicalSourceOption.push(
  22. <Select.Option value={item.value} key={10000 + item.value}>{item.key}</Select.Option>
  23. )
  24. });
  25. this.state.targetKeys = this.props.data.intellectualPropertyNumber || [];
  26. },
  27. componentWillReceiveProps(nextProps) {
  28. if (!this.props.visible && nextProps.visible && nextProps.data && this.props.resetForm) {
  29. this.state.targetKeys = nextProps.data.intellectualPropertyNumber || [];
  30. this.props.form.resetFields();
  31. this.state.fileList = [];
  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/admin/techProduct",
  44. data: {
  45. id: this.props.data.id,
  46. uid: this.props.uid,
  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 ? 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 />
  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: 200,
  183. height: 200,
  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. <p style={{ lineHeight: "32px" }}>知识产权获得情况及其对产品(服务)在技术上发挥的支持作用(限400字)*</p>
  218. <FormItem className="half-item"
  219. labelCol={{ span: 0 }}
  220. wrapperCol={{ span: 22 }}
  221. >
  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/admin/uploadTecProduct"}
  234. data={{ 'sign': 'tech_product', 'uid': this.props.uid }}
  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 ?
  258. <span className="download-file">
  259. <a onClick={newDownloadFile.bind(null, this.props.data.id, 'tech_product', '/api/admin/downloadTecProduct')}>{theData.accountDownloadFileName}</a>
  260. <a onClick={() => {
  261. var newTab = window.open('about:blank'); getPreview(theData.id, 'techProduct', 'tech_product', function (data) { newTab.location.href = data; });
  262. }}><Icon style={{ fontSize: '16px' }} type="eye-o" /></a>
  263. </span>
  264. : <span><Icon type="exclamation-circle" style={{ color: '#ffbf00', marginRight: '6px' }} />未上传!</span>}</p>
  265. </div>
  266. <FormItem style={{ marginTop: '20px' }}>
  267. <Button className="set-submit" type="primary" htmlType="submit">保存</Button>
  268. <Button type="ghost" style={{ marginLeft: '20px' }} onClick={this.props.closeModal}>取消</Button>
  269. </FormItem>
  270. </Form >
  271. );
  272. },
  273. }));
  274. const TechProductDesc = React.createClass({
  275. getInitialState() {
  276. return {
  277. visible: false,
  278. loading: false
  279. };
  280. },
  281. componentWillReceiveProps(nextProps) {
  282. this.state.visible = nextProps.showDesc
  283. },
  284. showModal() {
  285. this.setState({
  286. visible: true,
  287. resetForm: false
  288. });
  289. },
  290. handleOk() {
  291. this.setState({
  292. visible: false,
  293. resetForm: true
  294. });
  295. this.props.closeDesc(false, true);
  296. },
  297. handleCancel(e) {
  298. this.setState({
  299. visible: false,
  300. resetForm: true
  301. });
  302. this.props.closeDesc(false);
  303. },
  304. spinChange(e) {
  305. this.setState({
  306. loading: e
  307. });
  308. },
  309. render() {
  310. return (
  311. <div className="patent-addNew">
  312. <Modal maskClosable={false} title="上年度高新技术产品(服务)情况表" visible={this.state.visible}
  313. onOk={this.handleOk} onCancel={this.handleCancel}
  314. width='800px'
  315. footer='' >
  316. <Spin spinning={this.state.loading} className='spin-box'>
  317. <TechProductDescFrom
  318. data={this.props.data}
  319. uid={this.props.uid}
  320. visible={this.state.visible}
  321. resetForm={this.state.resetForm}
  322. mockData={this.props.mockData}
  323. spinState={this.spinChange} closeModal={this.handleCancel} clickOk={this.handleOk} />
  324. </Spin>
  325. </Modal>
  326. </div>
  327. );
  328. },
  329. });
  330. const TechProduct = React.createClass({
  331. loadData(pageNo) {
  332. this.state.data = [];
  333. this.setState({
  334. loading: true
  335. });
  336. $.when($.ajax({
  337. method: "post",
  338. dataType: "json",
  339. crossDomain: false,
  340. url: globalConfig.context + "/api/admin/techProductList",
  341. data: {
  342. pageNo: pageNo || 1,
  343. pageSize: this.state.pagination.pageSize,
  344. uid: this.props.data.uid
  345. }
  346. }), $.ajax({
  347. method: "post",
  348. dataType: "json",
  349. crossDomain: false,
  350. url: globalConfig.context + "/api/admin/intellectualList",
  351. data: {
  352. pageNo: pageNo || 1,
  353. pageSize: 99,
  354. uid: this.props.data.uid
  355. }
  356. })).done((data1, data2) => {
  357. let data = data1[0];
  358. let intellectualList = data2[0];
  359. if (data.error.length || !data.data || !data.data.list) {
  360. message.warning(data.error[0].message);
  361. return;
  362. };
  363. if (intellectualList.error.length || !intellectualList.data || !intellectualList.data.list) {
  364. message.warning(intellectualList.error[0].message);
  365. return;
  366. };
  367. let theArr = [];
  368. for (let i = 0; i < intellectualList.data.list.length; i++) {
  369. theArr.push({
  370. key: intellectualList.data.list[i].intellectualPropertyNumber,
  371. name: intellectualList.data.list[i].intellectualPropertyName
  372. });
  373. };
  374. this.state.mockData = theArr;
  375. for (let i = 0; i < data.data.list.length; i++) {
  376. let thisdata = data.data.list[i];
  377. this.state.data.push({
  378. key: i,
  379. id: thisdata.id,
  380. uid: thisdata.uid,
  381. mockData: this.state.mockData,
  382. serialNumber: thisdata.serialNumber,
  383. productName: thisdata.productName,
  384. techField: [thisdata.technicalField1, thisdata.technicalField2, thisdata.technicalField3],
  385. technicalField: getTechField(thisdata.technicalField1, thisdata.technicalField2, thisdata.technicalField3),
  386. technicalField1: thisdata.technicalField1,
  387. technicalField2: thisdata.technicalField2,
  388. technicalField3: thisdata.technicalField3,
  389. technicalSource: String(thisdata.technicalSource),
  390. lastYearRevenue: thisdata.lastYearRevenue,
  391. mainProduct: thisdata.mainProduct,
  392. PropertyNumber: thisdata.intellectualPropertyNumber,
  393. intellectualPropertyNumber: thisdata.intellectualPropertyNumber ? thisdata.intellectualPropertyNumber.split(",") : [],
  394. keyTechnology: thisdata.keyTechnology,
  395. competitiveEdge: thisdata.competitiveEdge,
  396. conditionEffect: thisdata.conditionEffect,
  397. year: thisdata.year,
  398. createTime: thisdata.createTime,
  399. accountDownloadFileName: thisdata.accountDownloadFileName,
  400. accountUrl: thisdata.accountUrl
  401. });
  402. };
  403. this.state.pagination.current = data.data.pageNo;
  404. this.state.pagination.total = data.data.totalCount;
  405. this.setState({
  406. dataSource: this.state.data,
  407. pagination: this.state.pagination
  408. });
  409. }).always(function () {
  410. this.setState({
  411. loading: false
  412. });
  413. }.bind(this));
  414. let _me = this;
  415. getProportion(this.props.data.uid, function (data) { _me.setState({ proportion: data }); });
  416. },
  417. getInitialState() {
  418. return {
  419. selectedRowKeys: [],
  420. selectedRows: [],
  421. loading: false,
  422. pagination: {
  423. defaultCurrent: 1,
  424. defaultPageSize: 10,
  425. showQuickJumper: true,
  426. pageSize: 10,
  427. onChange: function (page) {
  428. this.loadData(page);
  429. }.bind(this),
  430. showTotal: function (total) {
  431. return '共' + total + '条数据';
  432. }
  433. },
  434. columns: [
  435. {
  436. title: '产品编号',
  437. dataIndex: 'serialNumber',
  438. key: 'serialNumber'
  439. }, {
  440. title: '产品(服务)名称',
  441. dataIndex: 'productName',
  442. key: 'productName'
  443. }, {
  444. title: '技术领域',
  445. dataIndex: 'technicalField',
  446. key: 'technicalField'
  447. }, {
  448. title: '技术来源',
  449. dataIndex: 'technicalSource',
  450. key: 'technicalSource',
  451. render: (text) => { return getTechnicalSource(text) }
  452. }, {
  453. title: '上年度销售收入(万元)',
  454. dataIndex: 'lastYearRevenue',
  455. key: 'lastYearRevenue'
  456. }, {
  457. title: '是否主要产品(服务)',
  458. dataIndex: 'mainProduct',
  459. key: 'mainProduct',
  460. render: (text) => { if (text == "1") { return '是' } else { return '否' } }
  461. }, {
  462. title: '知识产权编号',
  463. dataIndex: 'PropertyNumber',
  464. key: 'PropertyNumber'
  465. }
  466. ],
  467. dataSource: []
  468. };
  469. },
  470. componentWillMount() {
  471. this.loadData();
  472. },
  473. tableRowClick(record, index) {
  474. this.state.RowData = record;
  475. this.setState({
  476. showDesc: true
  477. });
  478. },
  479. delectRow() {
  480. let deletedIds = [];
  481. for (let idx = 0; idx < this.state.selectedRows.length; idx++) {
  482. let rowItem = this.state.selectedRows[idx];
  483. if (rowItem.id) {
  484. deletedIds.push(rowItem.id)
  485. }
  486. }
  487. this.setState({
  488. selectedRowKeys: [],
  489. loading: deletedIds.length > 0
  490. });
  491. $.ajax({
  492. method: "POST",
  493. dataType: "json",
  494. crossDomain: false,
  495. url: globalConfig.context + "/api/admin/deleteTechProduct",
  496. data: {
  497. ids: deletedIds
  498. }
  499. }).done(function (data) {
  500. if (!data.error.length) {
  501. message.success('删除成功!');
  502. this.setState({
  503. loading: false,
  504. });
  505. } else {
  506. message.warning(data.error[0].message);
  507. };
  508. this.loadData();
  509. }.bind(this));
  510. },
  511. closeDesc(e, s) {
  512. this.state.showDesc = e;
  513. if (s) {
  514. this.loadData();
  515. };
  516. },
  517. search() {
  518. this.loadData();
  519. },
  520. reset() {
  521. this.loadData();
  522. },
  523. render() {
  524. const rowSelection = {
  525. selectedRowKeys: this.state.selectedRowKeys,
  526. onChange: (selectedRowKeys, selectedRows) => {
  527. this.setState({
  528. selectedRows: selectedRows,
  529. selectedRowKeys: selectedRowKeys
  530. });
  531. }
  532. };
  533. const hasSelected = this.state.selectedRowKeys.length > 0;
  534. return (
  535. <div className="user-content" >
  536. <div className="content-title">
  537. <span>高新技术产品(服务)情况表</span>
  538. <span className="proportion"> 是否已完成:</span>
  539. <Switch
  540. checked={this.state.proportion && this.state.proportion.techProject == 1 ? true : false}
  541. checkedChildren={'已完成'}
  542. unCheckedChildren={'未完成'}
  543. onChange={(e) => {
  544. e ? this.state.proportion.techProject = 1 : this.state.proportion.techProject = 0;
  545. saveProportion(this.state.proportion.id, this.props.data.uid, 'techProject', this.state.proportion.techProject);
  546. this.setState({ proportion: this.state.proportion });
  547. }} />
  548. </div>
  549. <div className="user-search">
  550. <p>
  551. <Button style={{ background: "#ea0862", border: "none", color: "#fff" }}
  552. onClick={this.tableRowClick}>添加<Icon type="plus" /></Button>
  553. <Button style={{ background: "#3fcf9e", border: "none", color: "#fff" }}
  554. disabled={!hasSelected}
  555. onClick={this.delectRow}>删除<Icon type="minus" /></Button>
  556. </p>
  557. </div>
  558. <div className="patent-table">
  559. <Spin spinning={this.state.loading}>
  560. <Table columns={this.state.columns}
  561. dataSource={this.state.dataSource}
  562. pagination={this.state.pagination}
  563. rowSelection={rowSelection}
  564. onRowClick={this.tableRowClick} />
  565. </Spin>
  566. </div>
  567. <TechProductDesc
  568. data={this.state.RowData}
  569. uid={this.props.data.uid}
  570. mockData={this.state.mockData}
  571. showDesc={this.state.showDesc} closeDesc={this.closeDesc} />
  572. </div >
  573. );
  574. }
  575. });
  576. export default TechProduct;