techProduct.jsx 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587
  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. visible={this.state.visible}
  320. resetForm={this.state.resetForm}
  321. mockData={this.props.mockData}
  322. spinState={this.spinChange} closeModal={this.handleCancel} clickOk={this.handleOk} />
  323. </Modal>
  324. </Spin>
  325. </div>
  326. );
  327. },
  328. });
  329. const TechProduct = React.createClass({
  330. loadData(pageNo) {
  331. this.state.data = [];
  332. this.setState({
  333. loading: true
  334. });
  335. $.when($.ajax({
  336. method: "post",
  337. dataType: "json",
  338. crossDomain: false,
  339. url: globalConfig.context + "/api/admin/techProductList",
  340. data: {
  341. pageNo: pageNo || 1,
  342. pageSize: this.state.pagination.pageSize,
  343. uid: this.props.data.uid
  344. }
  345. }), $.ajax({
  346. method: "post",
  347. dataType: "json",
  348. crossDomain: false,
  349. url: globalConfig.context + "/api/admin/intellectualList",
  350. data: {
  351. pageNo: pageNo || 1,
  352. pageSize: 99,
  353. uid: this.props.data.uid
  354. }
  355. })).done((data1, data2) => {
  356. let data = data1[0];
  357. let intellectualList = data2[0];
  358. if (data.error.length || !data.data || !data.data.list) {
  359. message.warning(data.error[0].message);
  360. return;
  361. };
  362. if (intellectualList.error.length || !intellectualList.data || !intellectualList.data.list) {
  363. message.warning(intellectualList.error[0].message);
  364. return;
  365. };
  366. let theArr = [];
  367. for (let i = 0; i < intellectualList.data.list.length; i++) {
  368. theArr.push({
  369. key: intellectualList.data.list[i].intellectualPropertyNumber,
  370. name: intellectualList.data.list[i].intellectualPropertyName
  371. });
  372. };
  373. this.state.mockData = theArr;
  374. for (let i = 0; i < data.data.list.length; i++) {
  375. let thisdata = data.data.list[i];
  376. this.state.data.push({
  377. key: i,
  378. id: thisdata.id,
  379. uid: thisdata.uid,
  380. mockData: this.state.mockData,
  381. serialNumber: thisdata.serialNumber,
  382. productName: thisdata.productName,
  383. techField: [Number(thisdata.technicalField1), Number(thisdata.technicalField2), Number(thisdata.technicalField3)],
  384. technicalField: getTechField(thisdata.technicalField1, thisdata.technicalField2, thisdata.technicalField3),
  385. technicalField1: thisdata.technicalField1,
  386. technicalField2: thisdata.technicalField2,
  387. technicalField3: thisdata.technicalField3,
  388. technicalSource: String(thisdata.technicalSource),
  389. lastYearRevenue: thisdata.lastYearRevenue,
  390. mainProduct: thisdata.mainProduct,
  391. PropertyNumber: thisdata.intellectualPropertyNumber,
  392. intellectualPropertyNumber: thisdata.intellectualPropertyNumber ? thisdata.intellectualPropertyNumber.split(",") : [],
  393. keyTechnology: thisdata.keyTechnology,
  394. competitiveEdge: thisdata.competitiveEdge,
  395. conditionEffect: thisdata.conditionEffect,
  396. year: thisdata.year,
  397. createTime: thisdata.createTime,
  398. accountDownloadFileName: thisdata.accountDownloadFileName,
  399. accountUrl: thisdata.accountUrl
  400. });
  401. };
  402. this.state.pagination.current = data.data.pageNo;
  403. this.state.pagination.total = data.data.totalCount;
  404. this.setState({
  405. dataSource: this.state.data,
  406. pagination: this.state.pagination
  407. });
  408. }).always(function () {
  409. this.setState({
  410. loading: false
  411. });
  412. }.bind(this));
  413. let _me = this;
  414. getProportion(this.props.data.uid, function (data) { _me.setState({ proportion: data }); });
  415. },
  416. getInitialState() {
  417. return {
  418. selectedRowKeys: [],
  419. selectedRows: [],
  420. loading: false,
  421. pagination: {
  422. defaultCurrent: 1,
  423. defaultPageSize: 10,
  424. showQuickJumper: true,
  425. pageSize: 10,
  426. onChange: function (page) {
  427. this.loadData(page);
  428. }.bind(this),
  429. showTotal: function (total) {
  430. return '共' + total + '条数据';
  431. }
  432. },
  433. columns: [
  434. {
  435. title: '产品编号',
  436. dataIndex: 'serialNumber',
  437. key: 'serialNumber'
  438. }, {
  439. title: '产品(服务)名称',
  440. dataIndex: 'productName',
  441. key: 'productName'
  442. }, {
  443. title: '技术领域',
  444. dataIndex: 'technicalField',
  445. key: 'technicalField'
  446. }, {
  447. title: '技术来源',
  448. dataIndex: 'technicalSource',
  449. key: 'technicalSource',
  450. render: (text) => { return getTechnicalSource(text) }
  451. }, {
  452. title: '上年度销售收入(万元)',
  453. dataIndex: 'lastYearRevenue',
  454. key: 'lastYearRevenue'
  455. }, {
  456. title: '是否主要产品(服务)',
  457. dataIndex: 'mainProduct',
  458. key: 'mainProduct',
  459. render: (text) => { if (text == "1") { return '是' } else { return '否' } }
  460. }, {
  461. title: '知识产权编号',
  462. dataIndex: 'PropertyNumber',
  463. key: 'PropertyNumber'
  464. }
  465. ],
  466. dataSource: []
  467. };
  468. },
  469. componentWillMount() {
  470. this.loadData();
  471. },
  472. tableRowClick(record, index) {
  473. this.state.RowData = record;
  474. this.setState({
  475. showDesc: true
  476. });
  477. },
  478. delectRow() {
  479. let deletedIds = [];
  480. for (let idx = 0; idx < this.state.selectedRows.length; idx++) {
  481. let rowItem = this.state.selectedRows[idx];
  482. if (rowItem.id) {
  483. deletedIds.push(rowItem.id)
  484. }
  485. }
  486. this.setState({
  487. selectedRowKeys: [],
  488. loading: deletedIds.length > 0
  489. });
  490. $.ajax({
  491. method: "POST",
  492. dataType: "json",
  493. crossDomain: false,
  494. url: globalConfig.context + "/api/admin/deleteTechProduct",
  495. data: {
  496. ids: deletedIds
  497. }
  498. }).done(function (data) {
  499. if (!data.error.length) {
  500. message.success('保存成功!');
  501. this.setState({
  502. loading: false,
  503. });
  504. } else {
  505. message.warning(data.error[0].message);
  506. };
  507. this.loadData();
  508. }.bind(this));
  509. },
  510. closeDesc(e, s) {
  511. this.state.showDesc = e;
  512. if (s) {
  513. this.loadData();
  514. };
  515. },
  516. search() {
  517. this.loadData();
  518. },
  519. reset() {
  520. this.loadData();
  521. },
  522. render() {
  523. const rowSelection = {
  524. selectedRowKeys: this.state.selectedRowKeys,
  525. onChange: (selectedRowKeys, selectedRows) => {
  526. this.setState({
  527. selectedRows: selectedRows,
  528. selectedRowKeys: selectedRowKeys
  529. });
  530. }
  531. };
  532. const hasSelected = this.state.selectedRowKeys.length > 0;
  533. return (
  534. <div className="user-content" >
  535. <div className="content-title">
  536. <span>高新技术产品(服务)情况表</span>
  537. <span className="proportion"> 是否已完成:</span>
  538. <Switch
  539. checked={this.state.proportion && this.state.proportion.techProject == 1 ? true : false}
  540. checkedChildren={'已完成'}
  541. unCheckedChildren={'未完成'}
  542. onChange={(e) => {
  543. e ? this.state.proportion.techProject = 1 : this.state.proportion.techProject = 0;
  544. saveProportion(this.state.proportion.id, this.props.data.uid, 'techProject', this.state.proportion.techProject);
  545. this.setState({ proportion: this.state.proportion });
  546. }} />
  547. </div>
  548. <div className="user-search">
  549. <p>
  550. <Button style={{ background: "#ea0862", border: "none", color: "#fff" }}
  551. onClick={this.tableRowClick}>添加<Icon type="plus" /></Button>
  552. <Button style={{ background: "#3fcf9e", border: "none", color: "#fff" }}
  553. disabled={!hasSelected}
  554. onClick={this.delectRow}>删除<Icon type="minus" /></Button>
  555. </p>
  556. </div>
  557. <div className="patent-table">
  558. <Spin spinning={this.state.loading}>
  559. <Table columns={this.state.columns}
  560. dataSource={this.state.dataSource}
  561. pagination={this.state.pagination}
  562. rowSelection={rowSelection}
  563. onRowClick={this.tableRowClick} />
  564. </Spin>
  565. </div>
  566. <TechProductDesc
  567. data={this.state.RowData}
  568. uid={this.props.data.uid}
  569. mockData={this.state.mockData}
  570. showDesc={this.state.showDesc} closeDesc={this.closeDesc} />
  571. </div >
  572. );
  573. }
  574. });
  575. export default TechProduct;