achievementForm.jsx 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577
  1. import React from 'react';
  2. import $ from 'jquery/src/ajax';
  3. import {
  4. Icon,
  5. Tooltip,
  6. Modal,
  7. message,
  8. Spin,
  9. Upload,
  10. Input,
  11. Select,
  12. Button,
  13. Radio,
  14. Form,
  15. Cascader,
  16. Tag,
  17. Checkbox,
  18. Row,
  19. Col
  20. } from 'antd';
  21. import {industry} from '@/industryList';
  22. import {achievementType,achievementCategoryList,maturityList,innovationList,transaction} from '@/dataDic';
  23. import { splitUrl} from '@/tools.js';
  24. import SpinContainer from "../../SpinContainer";
  25. const KeyWordTagGroup = React.createClass({
  26. getInitialState() {
  27. return {
  28. tags: [],
  29. inputVisible: false,
  30. inputValue: ''
  31. };
  32. },
  33. handleClose(removedTag) {
  34. const tags = this.state.tags.filter(tag => tag !== removedTag);
  35. this.props.tagsArr(tags);
  36. this.setState({ tags });
  37. },
  38. showInput() {
  39. this.setState({ inputVisible: true }, () => this.input.focus());
  40. },
  41. handleInputChange(e) {
  42. this.setState({ inputValue: e.target.value });
  43. },
  44. handleInputConfirm() {
  45. const state = this.state;
  46. const inputValue = state.inputValue;
  47. let tags = state.tags;
  48. if (inputValue && tags.indexOf(inputValue) === -1 && inputValue.replace(/(^\s*)|(\s*$)/g, "").length != 0) {
  49. tags = [...tags, inputValue.replace(/(^\s*)|(\s*$)/g, "")];
  50. }
  51. this.props.tagsArr(tags);
  52. this.setState({
  53. tags,
  54. inputVisible: false,
  55. inputValue: '',
  56. });
  57. },
  58. componentWillMount() {
  59. this.state.tags = this.props.keyWordArr;
  60. },
  61. componentWillReceiveProps(nextProps) {
  62. if (this.props.keyWordArr != nextProps.keyWordArr) {
  63. this.state.tags = nextProps.keyWordArr;
  64. };
  65. },
  66. render() {
  67. const { tags, inputVisible, inputValue } = this.state;
  68. return (
  69. <div className="keyWord-tips">
  70. {tags.map((tag, index) => {
  71. const isLongTag = tag.length > 10;
  72. const tagElem = (
  73. <Tag key={tag} closable={index !== -1} afterClose={() => this.handleClose(tag)}>
  74. {isLongTag ? `${tag.slice(0, 10)}...` : tag}
  75. </Tag>
  76. );
  77. return isLongTag ? <Tooltip title={tag}>{tagElem}</Tooltip> : tagElem;
  78. })}
  79. {inputVisible && (
  80. <Input
  81. ref={input => this.input = input}
  82. type="text"
  83. style={{ width: 78 }}
  84. value={inputValue}
  85. onChange={this.handleInputChange}
  86. onBlur={this.handleInputConfirm}
  87. onPressEnter={this.handleInputConfirm}
  88. />
  89. )}
  90. {!inputVisible && <Button className="addtips" type="dashed" disabled={tags.length > 9 ? true : false} onClick={this.showInput}>+ 新关键词</Button>}
  91. </div>
  92. );
  93. }
  94. });
  95. const PicturesWall = React.createClass({
  96. getInitialState() {
  97. return {
  98. previewVisible: false,
  99. previewImage: '',
  100. fileList: [],
  101. tags: []
  102. };
  103. },
  104. handleCancel() {
  105. this.setState({ previewVisible: false });
  106. },
  107. handlePreview(file) {
  108. this.setState({
  109. previewImage: file.url || file.thumbUrl,
  110. previewVisible: true
  111. });
  112. },
  113. handleChange(info) {
  114. let fileList = info.fileList;
  115. this.setState({ fileList });
  116. this.props.fileList(fileList);
  117. },
  118. componentWillReceiveProps(nextProps) {
  119. this.state.fileList = nextProps.pictureUrl;
  120. },
  121. render() {
  122. const { previewVisible, previewImage, fileList } = this.state;
  123. const uploadButton = (
  124. <div>
  125. <Icon type="plus" />
  126. <div className="ant-upload-text">点击上传</div>
  127. </div>
  128. );
  129. return (
  130. <div className="clearfix">
  131. <Upload
  132. action={globalConfig.context + '/api/user/demand/uploadPicture'}
  133. data={{ sign: 'demand_picture'}}
  134. listType="picture-card"
  135. fileList={fileList}
  136. onPreview={this.handlePreview}
  137. onChange={this.handleChange}
  138. >
  139. {fileList.length >= 5 ? null : uploadButton}
  140. </Upload>
  141. <Modal maskClosable={false} visible={previewVisible} footer={null} onCancel={this.handleCancel}>
  142. <img alt="example" style={{ width: '100%' }} src={previewImage} />
  143. </Modal>
  144. </div>
  145. );
  146. }
  147. });
  148. const DemandDetailForm = Form.create()(React.createClass({
  149. getInitialState() {
  150. return {
  151. visible: false,
  152. loading: false,
  153. auditStatus: 0,
  154. textFileList: [],
  155. videoFileList: [],
  156. pictureUrl: [],
  157. pictureUrlMin:[],
  158. tags:[]
  159. };
  160. },
  161. loadData(id) {
  162. this.setState({
  163. loading: true
  164. });
  165. $.ajax({
  166. method: "get",
  167. dataType: "json",
  168. crossDomain: false,
  169. url: globalConfig.context + '/api/user/achievement/achievementDetail' ,
  170. data: {
  171. id: id
  172. },
  173. success: function (data) {
  174. let thisData = data.data;
  175. if (!thisData) {
  176. if (data.error && data.error.length) {
  177. message.warning(data.error[0].message);
  178. };
  179. thisData = {};
  180. };
  181. this.setState({
  182. id:thisData.id,
  183. tags: thisData.keywords,
  184. data: thisData,
  185. publishPages:thisData.publishPages.length?thisData.publishPages:['app_achievement_list','web_achievement_list'],
  186. auditStatus:thisData.auditStatus,
  187. pictureUrl: thisData.technicalPictureUrl ? splitUrl(thisData.technicalPictureUrl, ',', globalConfig.avatarHost + '/upload') : [],
  188. pictureUrlMin: thisData.pictureUrlMin ? splitUrl(thisData.pictureUrlMin, ',', globalConfig.avatarHost + '/upload') : []
  189. });
  190. }.bind(this),
  191. }).always(function () {
  192. this.setState({
  193. loading: false
  194. });
  195. }.bind(this));
  196. },
  197. getTagsArr(e) {
  198. this.setState({ tags: e });
  199. },
  200. getPictureUrl(e) {
  201. this.setState({ pictureUrl: e });
  202. },
  203. handleSubmit(e,index) {
  204. e.preventDefault();
  205. this.props.form.validateFields((err, values) => {
  206. //url转化
  207. let thePictureUrl = [];
  208. if (this.state.pictureUrl.length) {
  209. let picArr = [];
  210. this.state.pictureUrl.map(function (item) {
  211. if ( item.response && item.response.data && item.response.data.length ){
  212. picArr.push(item.response.data);
  213. }
  214. });
  215. thePictureUrl = picArr.join(",");
  216. };
  217. let thepictureUrlMin = [];
  218. if (this.state.pictureUrlMin.length) {
  219. let picArr = [];
  220. this.state.pictureUrlMin.map(function (item) {
  221. if ( item.response && item.response.data && item.response.data.length ){
  222. picArr.push(item.response.data);
  223. }
  224. });
  225. thepictureUrlMin = picArr.join(",");
  226. };
  227. if(!this.state.tags.length){
  228. message.warning('请填写关键词.')
  229. return false;
  230. }
  231. if (!err) {
  232. this.setState({
  233. loading: true
  234. });
  235. $.ajax({
  236. method: "post",
  237. dataType: "json",
  238. async:true,
  239. url: this.props.data.id ? globalConfig.context + '/api/user/achievement/update' : globalConfig.context + '/api/user/achievement/apply',
  240. data: {
  241. id: this.props.data.id,
  242. name: values.name,
  243. fieldA: values.industryCategory ? values.industryCategory[0] : undefined,
  244. fieldB: values.industryCategory ? values.industryCategory[1] : undefined,
  245. dataCategory: values.dataCategory,
  246. category: values.category,
  247. technicalPictureUrl: thePictureUrl.length?thePictureUrl:'',
  248. pictureUrlMin: thepictureUrlMin.length?thepictureUrlMin:'',
  249. introduction:values.introduction,
  250. keyword: this.state.tags ? this.state.tags.join(",") : [],
  251. keywords: this.state.tags,
  252. maturity:values.maturity,
  253. innovation:values.innovation,
  254. transferMode:values.transferMode,
  255. auditStatus:index,
  256. patentCase: values.patentCase,
  257. teamDes: values.teamDes,
  258. parameter: values.parameter,
  259. boutique: values.boutique,
  260. isHot:values.isHot,
  261. publishPages:values.publishPages,
  262. }
  263. }).done(function (data) {
  264. this.setState({
  265. loading: false
  266. });
  267. if (!data.error.length) {
  268. message.success('操作成功!');
  269. this.setState({
  270. visible: false
  271. });
  272. this.props.handOk();
  273. } else {
  274. message.warning(data.error[0].message);
  275. }
  276. }.bind(this));
  277. }
  278. });
  279. },
  280. submission(e,index){
  281. this.handleSubmit(e,index);
  282. $.ajax({
  283. method: "POST",
  284. dataType: "json",
  285. crossDomain: false,
  286. async:true,
  287. url: globalConfig.context + "/api/user/achievement/commit",
  288. data: {
  289. id: this.state.id,
  290. }
  291. }).done(function (data) {
  292. if (!data.error.length) {
  293. this.setState({
  294. loading: false,
  295. });
  296. } else {
  297. message.warning(data.error[0].message);
  298. };
  299. }.bind(this));
  300. },
  301. cancelFun(){
  302. this.props.closeDesc();
  303. },
  304. componentWillMount() {
  305. if (this.props.data.id) {
  306. this.loadData(this.props.data.id);
  307. } else {
  308. this.state.data = {};
  309. this.state.tags = [];
  310. this.setState({
  311. publishPages:['app_achievement_list','web_achievement_list']
  312. })
  313. };
  314. },
  315. componentWillReceiveProps(nextProps) {
  316. if (!this.props.visible && nextProps.visible) {
  317. this.state.textFileList = [];
  318. this.state.videoFileList = [];
  319. if (nextProps.data.id) {
  320. this.loadData(nextProps.data.id);
  321. } else {
  322. this.state.data = {};
  323. this.state.pictureUrl = [];
  324. this.state.pictureUrlMin=[];
  325. this.state.tags = [];
  326. this.setState({
  327. publishPages:['app_achievement_list','web_achievement_list']
  328. })
  329. };
  330. this.props.form.resetFields();
  331. };
  332. },
  333. render() {
  334. const theData = this.state.data || {};
  335. const { getFieldDecorator } = this.props.form;
  336. const FormItem = Form.Item
  337. const formItemLayout = {
  338. labelCol: { span: 6 },
  339. wrapperCol: { span: 12 },
  340. };
  341. return (
  342. <div className='login'>
  343. <Form layout="horizontal" onSubmit={(e)=>{this.handleSubmit(e,0)}} id="demand-form">
  344. <SpinContainer spinning={this.state.loading}>
  345. <div className="clearfix">
  346. <FormItem className="half-item" {...formItemLayout} label="标题">
  347. {getFieldDecorator('name', {
  348. rules: [ { required: true, message: '此项为必填项!' } ],
  349. initialValue: theData.name
  350. })(<Input placeholder="给您的成果配个标题吧." maxLength={200}/>)}
  351. </FormItem>
  352. </div>
  353. <div className="clearfix">
  354. <FormItem labelCol={{ span: 3 }} wrapperCol={{ span: 18 }} label="发个成果吧">
  355. {getFieldDecorator('introduction', {
  356. rules: [ { required: true, message: '此项为必填项!' } ],
  357. initialValue: theData.introduction
  358. })(<Input type="textarea" rows={4} placeholder="请详细介绍您的技术成果情况,包括但不限于:能解决什么问题、重大技术性突破、取得的奖励情况." />)}
  359. </FormItem>
  360. <FormItem labelCol={{ span: 3 }} wrapperCol={{ span: 18 }} label="知识产权情况">
  361. {getFieldDecorator('patentCase', {
  362. initialValue: theData.patentCase
  363. })(<Input type="textarea" rows={4} placeholder="请输入您的知识产权情况." maxLength={300}/>)}
  364. </FormItem>
  365. <FormItem labelCol={{ span: 3 }} wrapperCol={{ span: 18 }} label="技术参数">
  366. {getFieldDecorator('parameter', {
  367. initialValue: theData.parameter
  368. })(<Input type="textarea" rows={4} placeholder="请输入您的技术成果参数." maxLength={1024}/>)}
  369. </FormItem>
  370. <FormItem labelCol={{ span: 3 }} wrapperCol={{ span: 18 }} label="团队情况">
  371. {getFieldDecorator('teamDes', {
  372. initialValue: theData.teamDes
  373. })(<Input type="textarea" rows={4} placeholder="请输入您的团队情况." maxLength={300}/>)}
  374. </FormItem>
  375. </div>
  376. <div className="clearfix">
  377. <FormItem
  378. labelCol={{ span: 3 }}
  379. wrapperCol={{ span: 18 }}
  380. label={<span><span style={{color:'red'}}> * </span>关键词</span>} >
  381. <KeyWordTagGroup
  382. keyWordArr={this.state.tags}
  383. tagsArr={(e)=>{this.setState({tags:e})}}
  384. />
  385. </FormItem>
  386. </div>
  387. <FormItem labelCol={{ span: 3 }} wrapperCol={{ span: 18 }} label="行业领域">
  388. {getFieldDecorator('industryCategory', {
  389. rules: [ { type: 'array', required: true, message: '此项为必填项!' } ],
  390. initialValue: [ theData.fieldA, theData.fieldB ]
  391. })(<Cascader style={{ width: 300 }} options={industry} placeholder="请选择一个行业" />)}
  392. </FormItem>
  393. <div className="clearfix">
  394. <FormItem className="half-item" {...formItemLayout} label="成果类型">
  395. {getFieldDecorator('dataCategory', {
  396. rules: [ { required: true, message: '此项为必填项!' } ],
  397. initialValue:(theData.dataCategory||theData.dataCategory=='0'?theData.dataCategory.toString():undefined)
  398. })(
  399. <Select style={{ width: 160 }} placeholder="请选择成果类型"
  400. >
  401. {
  402. achievementType.map(function (item) {
  403. return <Select.Option value={item.value} key={item.key}>{item.key}</Select.Option>
  404. })
  405. }
  406. </Select>
  407. )}
  408. </FormItem>
  409. <FormItem className="half-item" {...formItemLayout} label="知识产权类型">
  410. {getFieldDecorator('category', {
  411. rules: [ { required: true, message: '此项为必填项!' } ],
  412. initialValue:(theData.category||theData.category=='0'?theData.category.toString():undefined)
  413. })(
  414. <Select style={{ width: 160 }} placeholder="请选择知识产权类型"
  415. >
  416. {
  417. achievementCategoryList.map(function (item) {
  418. return <Select.Option value={item.value} key={item.key}>{item.key}</Select.Option>
  419. })
  420. }
  421. </Select>
  422. )}
  423. </FormItem>
  424. <FormItem className="half-item" {...formItemLayout} label="创新度">
  425. {getFieldDecorator('innovation', {
  426. initialValue:(theData.innovation||theData.innovation=='0'?theData.innovation.toString():undefined)
  427. })(
  428. <Select style={{ width: 160 }} placeholder="请选择创新度"
  429. >
  430. {
  431. innovationList.map(function (item) {
  432. return <Select.Option value={item.value} key={item.key}>{item.key}</Select.Option>
  433. })
  434. }
  435. </Select>
  436. )}
  437. </FormItem>
  438. <FormItem className="half-item" {...formItemLayout} label="成熟度">
  439. {getFieldDecorator('maturity', {
  440. initialValue:(theData.maturity||theData.maturity=='0'?theData.maturity.toString():undefined)
  441. })(
  442. <Select style={{ width: 160 }} placeholder="请选择成熟度"
  443. >
  444. {
  445. maturityList.map(function (item) {
  446. return <Select.Option value={item.value} key={item.key}>{item.key}</Select.Option>
  447. })
  448. }
  449. </Select>
  450. )}
  451. </FormItem>
  452. <FormItem className="half-item" {...formItemLayout} label="交易形式">
  453. {getFieldDecorator('transferMode', {
  454. initialValue:(theData.transferMode||theData.transferMode=='0'?theData.transferMode.toString():undefined)
  455. })(
  456. <Select style={{ width: 160 }} placeholder="请选择交易形式"
  457. >
  458. {
  459. transaction.map(function (item) {
  460. return <Select.Option value={item.value} key={item.key}>{item.key}</Select.Option>
  461. })
  462. }
  463. </Select>
  464. )}
  465. </FormItem>
  466. </div>
  467. <div className="clearfix">
  468. <FormItem labelCol={{ span: 3 }} wrapperCol={{ span: 18 }} label="成果(大图)">
  469. <PicturesWall
  470. fileList={this.getPictureUrl}
  471. pictureUrl={this.state.pictureUrl}
  472. visible={this.props.visible}
  473. />
  474. </FormItem>
  475. </div>
  476. <div className="clearfix">
  477. <FormItem labelCol={{ span: 3 }} wrapperCol={{ span: 18 }} label="成果(小图)">
  478. <PicturesWall
  479. fileList={(e)=>{this.setState({pictureUrlMin:e})}}
  480. pictureUrl={this.state.pictureUrlMin}
  481. visible={this.props.visible}
  482. />
  483. </FormItem>
  484. </div>
  485. <div className="clearfix">
  486. <FormItem className="half-item" {...formItemLayout} label="精品成果">
  487. {getFieldDecorator('boutique', {
  488. initialValue: theData.boutique
  489. })(
  490. <Radio.Group>
  491. <Radio value={0}>非精品</Radio>
  492. <Radio value={1}>精品</Radio>
  493. </Radio.Group>
  494. )
  495. }
  496. </FormItem>
  497. <FormItem className="half-item" {...formItemLayout} label="热点成果">
  498. {getFieldDecorator('isHot', {
  499. initialValue: theData.isHot
  500. })(
  501. <Radio.Group>
  502. <Radio value={0}>非热点</Radio>
  503. <Radio value={1}>热点</Radio>
  504. </Radio.Group>
  505. )
  506. }
  507. </FormItem>
  508. </div>
  509. <div className="clearfix">
  510. <FormItem className="full-item"
  511. labelCol={{ span: 3 }}
  512. wrapperCol={{ span: 18 }} label="发布位置">
  513. {getFieldDecorator('publishPages', {
  514. rules: [ { required: false } ],
  515. initialValue: this.state.publishPages
  516. })(
  517. <Checkbox.Group>
  518. <Row>
  519. <Col span={6}><Checkbox value="web_index">网站首页</Checkbox></Col>
  520. <Col span={6}><Checkbox value="web_achievement_main">网站成果主页</Checkbox></Col>
  521. <Col span={6}><Checkbox value="web_achievement_list" disabled>网站成果搜索页</Checkbox></Col>
  522. <Col span={6}><Checkbox value="app_index">APP首页</Checkbox></Col>
  523. <Col span={6}><Checkbox value="app_achievement_main">APP成果首页</Checkbox></Col>
  524. <Col span={6}><Checkbox value="app_achievement_list" disabled>APP成果搜索页</Checkbox></Col>
  525. <Col span={6}><Checkbox value="web_achievement_trading_index">知识产权交易首页</Checkbox></Col>
  526. <Col span={6}><Checkbox value="app_achievement_trading_index">app成果知识产权交易页面</Checkbox></Col>
  527. </Row>
  528. </Checkbox.Group>
  529. )}
  530. </FormItem>
  531. </div>
  532. {theData.auditInfo&&<div className="clearfix">
  533. <FormItem labelCol={{ span: 3 }} wrapperCol={{ span: 18 }} label="审核信息">
  534. <span>{theData.auditInfo}</span>
  535. </FormItem>
  536. </div>}
  537. <div className="clearfix">
  538. <FormItem wrapperCol={{ span: 12, offset: 3 }}>
  539. <Button className="set-submit" type="primary" htmlType="submit">
  540. 保存草稿
  541. </Button>
  542. <Button
  543. className="set-submit"
  544. type="ghost"
  545. onClick={(e) => {
  546. if(this.props.data.id){
  547. this.submission(e,1)
  548. }else{
  549. this.handleSubmit(e,1)
  550. }
  551. }}
  552. >
  553. 提交审核
  554. </Button>
  555. <Button className="set-submit" type="ghost" onClick={this.cancelFun}>
  556. 取消
  557. </Button>
  558. </FormItem>
  559. </div>
  560. </SpinContainer>
  561. </Form>
  562. </div>
  563. )
  564. }
  565. }));
  566. export default DemandDetailForm;