achievementForm.jsx 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552
  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. tags:[]
  157. };
  158. },
  159. loadData(id) {
  160. this.setState({
  161. loading: true
  162. });
  163. $.ajax({
  164. method: "get",
  165. dataType: "json",
  166. crossDomain: false,
  167. url: globalConfig.context + '/api/user/achievement/achievementDetail' ,
  168. data: {
  169. id: id
  170. },
  171. success: function (data) {
  172. let thisData = data.data;
  173. if (!thisData) {
  174. if (data.error && data.error.length) {
  175. message.warning(data.error[0].message);
  176. };
  177. thisData = {};
  178. };
  179. this.setState({
  180. id:thisData.id,
  181. tags: thisData.keywords,
  182. data: thisData,
  183. publishPages:thisData.publishPages.length?thisData.publishPages:['app_achievement_list','web_achievement_list'],
  184. auditStatus:thisData.auditStatus,
  185. pictureUrl: thisData.technicalPictureUrl ? splitUrl(thisData.technicalPictureUrl, ',', globalConfig.avatarHost + '/upload') : []
  186. });
  187. }.bind(this),
  188. }).always(function () {
  189. this.setState({
  190. loading: false
  191. });
  192. }.bind(this));
  193. },
  194. getTagsArr(e) {
  195. this.setState({ tags: e });
  196. },
  197. getPictureUrl(e) {
  198. this.setState({ pictureUrl: e });
  199. },
  200. handleSubmit(e,index) {
  201. e.preventDefault();
  202. this.props.form.validateFields((err, values) => {
  203. //url转化
  204. let thePictureUrl = [];
  205. if (this.state.pictureUrl.length) {
  206. let picArr = [];
  207. this.state.pictureUrl.map(function (item) {
  208. if ( item.response && item.response.data && item.response.data.length ){
  209. picArr.push(item.response.data);
  210. }
  211. });
  212. thePictureUrl = picArr.join(",");
  213. };
  214. if(!this.state.tags.length){
  215. message.warning('请填写关键词.')
  216. return false;
  217. }
  218. if (!err) {
  219. this.setState({
  220. loading: true
  221. });
  222. $.ajax({
  223. method: "post",
  224. dataType: "json",
  225. async:true,
  226. url: this.props.data.id ? globalConfig.context + '/api/user/achievement/update' : globalConfig.context + '/api/user/achievement/apply',
  227. data: {
  228. id: this.props.data.id,
  229. name: values.name,
  230. fieldA: values.industryCategory ? values.industryCategory[0] : undefined,
  231. fieldB: values.industryCategory ? values.industryCategory[1] : undefined,
  232. dataCategory: values.dataCategory,
  233. category: values.category,
  234. technicalPictureUrl: thePictureUrl,
  235. introduction:values.introduction,
  236. keyword: this.state.tags ? this.state.tags.join(",") : [],
  237. keywords: this.state.tags,
  238. maturity:values.maturity,
  239. innovation:values.innovation,
  240. transferMode:values.transferMode,
  241. auditStatus:index,
  242. patentCase: values.patentCase,
  243. teamDes: values.teamDes,
  244. parameter: values.parameter,
  245. boutique: values.boutique,
  246. isHot:values.isHot,
  247. publishPages:values.publishPages,
  248. }
  249. }).done(function (data) {
  250. this.setState({
  251. loading: false
  252. });
  253. if (!data.error.length) {
  254. message.success('操作成功!');
  255. this.setState({
  256. visible: false
  257. });
  258. this.props.handOk();
  259. } else {
  260. message.warning(data.error[0].message);
  261. }
  262. }.bind(this));
  263. }
  264. });
  265. },
  266. submission(e,index){
  267. this.handleSubmit(e,index);
  268. $.ajax({
  269. method: "POST",
  270. dataType: "json",
  271. crossDomain: false,
  272. async:true,
  273. url: globalConfig.context + "/api/user/achievement/commit",
  274. data: {
  275. id: this.state.id,
  276. }
  277. }).done(function (data) {
  278. if (!data.error.length) {
  279. this.setState({
  280. loading: false,
  281. });
  282. } else {
  283. message.warning(data.error[0].message);
  284. };
  285. }.bind(this));
  286. },
  287. cancelFun(){
  288. this.props.closeDesc();
  289. },
  290. componentWillMount() {
  291. if (this.props.data.id) {
  292. this.loadData(this.props.data.id);
  293. } else {
  294. this.state.data = {};
  295. this.state.tags = [];
  296. this.setState({
  297. publishPages:['app_achievement_list','web_achievement_list']
  298. })
  299. };
  300. },
  301. componentWillReceiveProps(nextProps) {
  302. if (!this.props.visible && nextProps.visible) {
  303. this.state.textFileList = [];
  304. this.state.videoFileList = [];
  305. if (nextProps.data.id) {
  306. this.loadData(nextProps.data.id);
  307. } else {
  308. this.state.data = {};
  309. this.state.pictureUrl = [];
  310. this.state.tags = [];
  311. this.setState({
  312. publishPages:['app_achievement_list','web_achievement_list']
  313. })
  314. };
  315. this.props.form.resetFields();
  316. };
  317. },
  318. render() {
  319. const theData = this.state.data || {};
  320. const { getFieldDecorator } = this.props.form;
  321. const FormItem = Form.Item
  322. const formItemLayout = {
  323. labelCol: { span: 6 },
  324. wrapperCol: { span: 12 },
  325. };
  326. return (
  327. <div className='login'>
  328. <Form layout="horizontal" onSubmit={(e)=>{this.handleSubmit(e,0)}} id="demand-form">
  329. <Spin spinning={this.state.loading}>
  330. <div className="clearfix">
  331. <FormItem className="half-item" {...formItemLayout} label="标题">
  332. {getFieldDecorator('name', {
  333. rules: [ { required: true, message: '此项为必填项!' } ],
  334. initialValue: theData.name
  335. })(<Input placeholder="给您的成果配个标题吧." maxLength={200}/>)}
  336. </FormItem>
  337. </div>
  338. <div className="clearfix">
  339. <FormItem labelCol={{ span: 3 }} wrapperCol={{ span: 18 }} label="发个成果吧">
  340. {getFieldDecorator('introduction', {
  341. rules: [ { required: true, message: '此项为必填项!' } ],
  342. initialValue: theData.introduction
  343. })(<Input type="textarea" rows={4} placeholder="请详细介绍您的技术成果情况,包括但不限于:能解决什么问题、重大技术性突破、取得的奖励情况." />)}
  344. </FormItem>
  345. <FormItem labelCol={{ span: 3 }} wrapperCol={{ span: 18 }} label="知识产权情况">
  346. {getFieldDecorator('patentCase', {
  347. initialValue: theData.patentCase
  348. })(<Input type="textarea" rows={4} placeholder="请输入您的知识产权情况." maxLength={300}/>)}
  349. </FormItem>
  350. <FormItem labelCol={{ span: 3 }} wrapperCol={{ span: 18 }} label="技术参数">
  351. {getFieldDecorator('parameter', {
  352. initialValue: theData.parameter
  353. })(<Input type="textarea" rows={4} placeholder="请输入您的技术成果参数." maxLength={1024}/>)}
  354. </FormItem>
  355. <FormItem labelCol={{ span: 3 }} wrapperCol={{ span: 18 }} label="团队情况">
  356. {getFieldDecorator('teamDes', {
  357. initialValue: theData.teamDes
  358. })(<Input type="textarea" rows={4} placeholder="请输入您的团队情况." maxLength={300}/>)}
  359. </FormItem>
  360. </div>
  361. <div className="clearfix">
  362. <FormItem
  363. labelCol={{ span: 3 }}
  364. wrapperCol={{ span: 18 }}
  365. label={<span><span style={{color:'red'}}> * </span>关键词</span>} >
  366. <KeyWordTagGroup
  367. keyWordArr={this.state.tags}
  368. tagsArr={(e)=>{this.setState({tags:e})}}
  369. />
  370. </FormItem>
  371. </div>
  372. <FormItem labelCol={{ span: 3 }} wrapperCol={{ span: 18 }} label="行业领域">
  373. {getFieldDecorator('industryCategory', {
  374. rules: [ { type: 'array', required: true, message: '此项为必填项!' } ],
  375. initialValue: [ theData.fieldA, theData.fieldB ]
  376. })(<Cascader style={{ width: 300 }} options={industry} placeholder="请选择一个行业" />)}
  377. </FormItem>
  378. <div className="clearfix">
  379. <FormItem className="half-item" {...formItemLayout} label="成果类型">
  380. {getFieldDecorator('dataCategory', {
  381. rules: [ { required: true, message: '此项为必填项!' } ],
  382. initialValue:(theData.dataCategory||theData.dataCategory=='0'?theData.dataCategory.toString():undefined)
  383. })(
  384. <Select style={{ width: 160 }} placeholder="请选择成果类型"
  385. >
  386. {
  387. achievementType.map(function (item) {
  388. return <Select.Option value={item.value} key={item.key}>{item.key}</Select.Option>
  389. })
  390. }
  391. </Select>
  392. )}
  393. </FormItem>
  394. <FormItem className="half-item" {...formItemLayout} label="知识产权类型">
  395. {getFieldDecorator('category', {
  396. rules: [ { required: true, message: '此项为必填项!' } ],
  397. initialValue:(theData.category||theData.category=='0'?theData.category.toString():undefined)
  398. })(
  399. <Select style={{ width: 160 }} placeholder="请选择知识产权类型"
  400. >
  401. {
  402. achievementCategoryList.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('innovation', {
  411. initialValue:(theData.innovation||theData.innovation=='0'?theData.innovation.toString():undefined)
  412. })(
  413. <Select style={{ width: 160 }} placeholder="请选择创新度"
  414. >
  415. {
  416. innovationList.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('maturity', {
  425. initialValue:(theData.maturity||theData.maturity=='0'?theData.maturity.toString():undefined)
  426. })(
  427. <Select style={{ width: 160 }} placeholder="请选择成熟度"
  428. >
  429. {
  430. maturityList.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('transferMode', {
  439. initialValue:(theData.transferMode||theData.transferMode=='0'?theData.transferMode.toString():undefined)
  440. })(
  441. <Select style={{ width: 160 }} placeholder="请选择交易形式"
  442. >
  443. {
  444. transaction.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. </div>
  452. <div className="clearfix">
  453. <FormItem labelCol={{ span: 3 }} wrapperCol={{ span: 18 }} label="成果文件(图片)">
  454. <PicturesWall
  455. fileList={this.getPictureUrl}
  456. pictureUrl={this.state.pictureUrl}
  457. visible={this.props.visible}
  458. />
  459. </FormItem>
  460. </div>
  461. <div className="clearfix">
  462. <FormItem className="half-item" {...formItemLayout} label="精品成果">
  463. {getFieldDecorator('boutique', {
  464. initialValue: theData.boutique
  465. })(
  466. <Radio.Group>
  467. <Radio value={0}>非精品</Radio>
  468. <Radio value={1}>精品</Radio>
  469. </Radio.Group>
  470. )
  471. }
  472. </FormItem>
  473. <FormItem className="half-item" {...formItemLayout} label="热点成果">
  474. {getFieldDecorator('isHot', {
  475. initialValue: theData.isHot
  476. })(
  477. <Radio.Group>
  478. <Radio value={0}>非热点</Radio>
  479. <Radio value={1}>热点</Radio>
  480. </Radio.Group>
  481. )
  482. }
  483. </FormItem>
  484. </div>
  485. <div className="clearfix">
  486. <FormItem className="full-item"
  487. labelCol={{ span: 3 }}
  488. wrapperCol={{ span: 18 }} label="发布位置">
  489. {getFieldDecorator('publishPages', {
  490. rules: [ { required: false } ],
  491. initialValue: this.state.publishPages
  492. })(
  493. <Checkbox.Group>
  494. <Row>
  495. <Col span={6}><Checkbox value="web_index">网站首页</Checkbox></Col>
  496. <Col span={6}><Checkbox value="web_achievement_main">网站成果主页</Checkbox></Col>
  497. <Col span={6}><Checkbox value="web_achievement_list" disabled>网站成果搜索页</Checkbox></Col>
  498. <Col span={6}><Checkbox value="app_index">APP首页</Checkbox></Col>
  499. <Col span={6}><Checkbox value="app_achievement_main">APP成果首页</Checkbox></Col>
  500. <Col span={6}><Checkbox value="app_achievement_list" disabled>APP成果搜索页</Checkbox></Col>
  501. <Col span={6}><Checkbox value="web_achievement_trading_index">知识产权交易首页</Checkbox></Col>
  502. </Row>
  503. </Checkbox.Group>
  504. )}
  505. </FormItem>
  506. </div>
  507. {theData.auditInfo&&<div className="clearfix">
  508. <FormItem labelCol={{ span: 3 }} wrapperCol={{ span: 18 }} label="审核信息">
  509. <span>{theData.auditInfo}</span>
  510. </FormItem>
  511. </div>}
  512. <div className="clearfix">
  513. <FormItem wrapperCol={{ span: 12, offset: 3 }}>
  514. <Button className="set-submit" type="primary" htmlType="submit">
  515. 保存草稿
  516. </Button>
  517. <Button
  518. className="set-submit"
  519. type="ghost"
  520. onClick={(e) => {
  521. if(this.props.data.id){
  522. this.submission(e,1)
  523. }else{
  524. this.handleSubmit(e,1)
  525. }
  526. }}
  527. >
  528. 提交审核
  529. </Button>
  530. <Button className="set-submit" type="ghost" onClick={this.cancelFun}>
  531. 取消
  532. </Button>
  533. </FormItem>
  534. </div>
  535. </Spin>
  536. </Form>
  537. </div>
  538. )
  539. }
  540. }));
  541. export default DemandDetailForm;