techProduct.jsx 22 KB

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