techProduct.jsx 25 KB

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