achievementForm.jsx 20 KB

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