techProduct.jsx 23 KB

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