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