achievementForm.jsx 18 KB

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