techProduct.jsx 23 KB

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