demandForm.jsx 19 KB

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