demandForm.jsx 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549
  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 { splitUrl } from '@/tools.js';
  27. import {industry} from '@/industryList';
  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.setState({
  322. publishPagesArr:['app_demand_list','web_demand_list']
  323. })
  324. };
  325. },
  326. componentWillReceiveProps(nextProps) {
  327. if (!this.props.visible && nextProps.visible) {
  328. this.state.textFileList = [];
  329. this.state.videoFileList = [];
  330. if (nextProps.data.id) {
  331. this.loadData(nextProps.data.id);
  332. } else {
  333. this.state.data = {};
  334. this.state.isUrgent=undefined;//加急需求
  335. this.state.isHot=undefined;//是否悬赏
  336. this.state.status=undefined;
  337. this.state.pictureUrl = [];
  338. this.state.tags = [];
  339. this.setState({
  340. publishPagesArr:['app_demand_list','web_demand_list']
  341. })
  342. };
  343. this.props.form.resetFields();
  344. };
  345. },
  346. render() {
  347. const theData = this.state.data || {};
  348. const { getFieldDecorator,getFieldsValue } = this.props.form;
  349. const FormItem = Form.Item
  350. const formItemLayout = {
  351. labelCol: { span: 6 },
  352. wrapperCol: { span: 12 },
  353. };
  354. let demandType =(getFieldsValue(['demandType']).demandType);
  355. return (
  356. <div className='login'>
  357. <Form layout="horizontal" onSubmit={(e)=>{this.handleSubmit(e,0)}} id="demand-form">
  358. <Spin spinning={this.state.loading}>
  359. <div className="clearfix">
  360. <FormItem labelCol={{ span: 3 }} wrapperCol={{ span: 18 }} label="发个需求吧">
  361. {getFieldDecorator('problemDes', {
  362. rules: [ { required: true, message: '此项为必填项!' } ],
  363. initialValue: theData.problemDes
  364. })(<Input type="textarea" rows={4} placeholder="亲,发个需求吧!让技术专家主动找到您." maxLength={512}/>)}
  365. </FormItem>
  366. <FormItem className="half-item" {...formItemLayout} label="标题">
  367. {getFieldDecorator('name', {
  368. rules: [ { required: true, message: '此项为必填项!' } ],
  369. initialValue: theData.name
  370. })(<Input placeholder="给您的需求配个标题吧." maxLength={128} />)}
  371. </FormItem>
  372. </div>
  373. <div className="clearfix">
  374. <FormItem
  375. labelCol={{ span: 3 }}
  376. wrapperCol={{ span: 18 }}
  377. label={<span><strong style={{color:'red'}}>*</strong>关键词</span>} >
  378. <KeyWordTagGroup
  379. keyWordArr={this.state.tags}
  380. tagsArr={(e)=>{this.setState({tags:e})}}
  381. />
  382. </FormItem>
  383. </div>
  384. <FormItem labelCol={{ span: 3 }} wrapperCol={{ span: 18 }} label="行业领域">
  385. {getFieldDecorator('industryCategory', {
  386. rules: [ { type: 'array', required: true, message: '此项为必填项!' } ],
  387. initialValue: [ theData.industryCategoryA, theData.industryCategoryB ]
  388. })(<Cascader style={{ width: 300 }} options={industry} placeholder="请选择一个行业" />)}
  389. </FormItem>
  390. <div className="clearfix">
  391. <FormItem className="half-item" {...formItemLayout} label="需求类型">
  392. {getFieldDecorator('demandType', {
  393. rules: [ { required: true, message: '此项为必填项!' } ],
  394. initialValue:(theData.demandType||theData.demandType=='0'?theData.demandType.toString():undefined)
  395. })(
  396. <Select style={{ width: 160 }} placeholder="请选择需求类型"
  397. >
  398. {this.props.demandTypeOption}
  399. </Select>
  400. )}
  401. </FormItem>
  402. {demandType=='5'||theData.demandType=='5'?
  403. <FormItem className="half-item" {...formItemLayout} label="人才酬劳">
  404. {getFieldDecorator('budgetCost', {
  405. rules: [ { required: false } ],
  406. initialValue: theData.budgetCost?theData.budgetCost:undefined
  407. })(<InputNumber min={0} max={999999} step={0.01} placeholder="输入酬劳."/>)}
  408. <span style={{ marginLeft: '5px' }}>万元</span>
  409. </FormItem>:''}
  410. {demandType=='3'||theData.demandType=='3'?<div className="clearfix"><FormItem className="half-item" {...formItemLayout} label="资金需求额度">
  411. {getFieldDecorator('crowdCost', {
  412. rules: [ { required: false } ],
  413. initialValue: theData.crowdCost
  414. })(<InputNumber min={0} max={999999} step={0.01} placeholder="输入资金需求额度."/>)}
  415. <span style={{ marginLeft: '5px' }}>万元</span>
  416. </FormItem>
  417. <FormItem className="half-item" {...formItemLayout} label="资金用途">
  418. {getFieldDecorator('researchType', {
  419. rules: [ { required: false } ],
  420. initialValue: theData.researchType||theData.researchType=='0'?theData.researchType.toString():undefined
  421. })(
  422. <Select placeholder="选择资金用途" style={{ width: 160 }} >
  423. <Select.Option value="0" >研发</Select.Option>
  424. <Select.Option value="1" >扩大再生产</Select.Option>
  425. </Select>
  426. )}
  427. </FormItem>
  428. </div>:''
  429. }
  430. </div>
  431. <p style={{marginLeft:40,fontSize:18,marginBottom:15}}>您还可以说明</p>
  432. <div className="clearfix">
  433. <FormItem className="half-item" {...formItemLayout} label="加急">
  434. <Radio.Group value={this.state.isUrgent} onChange={(e)=>{this.setState({isUrgent:e.target.value})}}>
  435. <Radio value={0}>非加急</Radio>
  436. <Radio value={1}>加急</Radio>
  437. </Radio.Group>
  438. </FormItem>
  439. {this.state.isUrgent?<div className="clearfix">
  440. <FormItem className="half-item" {...formItemLayout} label="日期">
  441. {getFieldDecorator('urgentDays', {
  442. initialValue: theData.urgentDays
  443. })(<InputNumber min={0} max={999999} step={0} placeholder="输入天数."/>)}
  444. <span style={{ marginLeft: '5px' }}>天</span>
  445. </FormItem>
  446. <FormItem className="half-item" {...formItemLayout} label="加急金额">
  447. {getFieldDecorator('urgentMoney', {
  448. initialValue: theData.urgentMoney?theData.urgentMoney:undefined
  449. })(<InputNumber min={0} max={999999} step={0.01} placeholder="输入金额."/>)}
  450. <span style={{ marginLeft: '5px' }}>万元</span>
  451. </FormItem>
  452. </div>:''}
  453. </div>
  454. <div className="clearfix">
  455. <FormItem className="half-item" {...formItemLayout} label="热点需求">
  456. <Radio.Group value={this.state.isHot} onChange={(e)=>{this.setState({isHot:e.target.value})}}>
  457. <Radio value={0}>否</Radio>
  458. <Radio value={1}>是</Radio>
  459. </Radio.Group>
  460. </FormItem>
  461. <FormItem className="half-item" {...formItemLayout} label="解决">
  462. <Radio.Group value={this.state.status} onChange={(e)=>{this.setState({status:e.target.value})}}>
  463. <Radio value={0}>进行中</Radio>
  464. <Radio value={1}>未解决</Radio>
  465. <Radio value={2}>已解决</Radio>
  466. </Radio.Group>
  467. </FormItem>
  468. </div>
  469. <FormItem labelCol={{ span: 3 }} wrapperCol={{ span: 18 }} label="需求(大图)">
  470. <PicturesWall
  471. fileList={this.getPictureUrl}
  472. pictureUrl={this.state.pictureUrl}
  473. visible={this.props.visible}
  474. />
  475. </FormItem>
  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 className="clearfix">
  484. <FormItem className="full-item"
  485. labelCol={{ span: 3 }}
  486. wrapperCol={{ span: 18 }} label="发布位置">
  487. {getFieldDecorator('publishPages', {
  488. rules: [ { required: false } ],
  489. initialValue: this.state.publishPagesArr
  490. })(
  491. <Checkbox.Group>
  492. <Row>
  493. <Col span={6}><Checkbox value="web_index">网站首页</Checkbox></Col>
  494. <Col span={6}><Checkbox value="web_demand_main">网站需求主页</Checkbox></Col>
  495. <Col span={6}><Checkbox value="web_demand_list" disabled>网站需求搜索页</Checkbox></Col>
  496. <Col span={6}><Checkbox value="app_index">APP首页</Checkbox></Col>
  497. <Col span={6}><Checkbox value="app_demand_main">APP需求首页</Checkbox></Col>
  498. <Col span={6}><Checkbox value="app_demand_list" disabled>APP需求搜索页</Checkbox></Col>
  499. <Col span={6}><Checkbox value="web_demand_trading_index">知识产权交易首页</Checkbox></Col>
  500. </Row>
  501. </Checkbox.Group>
  502. )}
  503. </FormItem>
  504. </div>
  505. {theData.auditInfo&&<div className="clearfix">
  506. <FormItem labelCol={{ span: 3 }} wrapperCol={{ span: 18 }} label="审核信息">
  507. <span>{theData.auditInfo}</span>
  508. </FormItem>
  509. </div>}
  510. <div className="clearfix">
  511. <FormItem wrapperCol={{ span: 12, offset: 3 }}>
  512. <Button className="set-submit" type="primary" htmlType="submit">
  513. 保存草稿
  514. </Button>
  515. <Button
  516. className="set-submit"
  517. type="ghost"
  518. onClick={(e) => {
  519. if(this.props.data.id){
  520. this.submission(e,1)
  521. }else{
  522. this.handleSubmit(e,1)
  523. }
  524. }}
  525. >
  526. 提交审核
  527. </Button>
  528. <Button className="set-submit" type="ghost" onClick={this.cancelFun}>
  529. 取消
  530. </Button>
  531. </FormItem>
  532. </div>
  533. </Spin>
  534. </Form>
  535. </div>
  536. )
  537. }
  538. }));
  539. export default DemandDetailForm;