achievementForm.jsx 19 KB

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