techProduct.jsx 22 KB

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