demandForm.jsx 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529
  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. pictureUrl: [],
  160. tags:[]
  161. };
  162. },
  163. loadData(id) {
  164. this.setState({
  165. loading: true
  166. });
  167. $.ajax({
  168. method: "get",
  169. dataType: "json",
  170. crossDomain: false,
  171. url: globalConfig.context + '/api/user/demand/demandDetail' ,
  172. data: {
  173. id: id
  174. },
  175. success: function (data) {
  176. let thisData = data.data;
  177. if (!thisData) {
  178. if (data.error && data.error.length) {
  179. message.warning(data.error[0].message);
  180. };
  181. thisData = {};
  182. };
  183. let publishPagesArr = [];
  184. thisData.publishPages.map(item=>{
  185. publishPagesArr.push(item.publishPage)
  186. })
  187. this.setState({
  188. id:thisData.id,
  189. tags: thisData.keyword ? thisData.keyword.split(",") : [],
  190. data: thisData,
  191. auditStatus:thisData.auditStatus,
  192. publishPagesArr:publishPagesArr,
  193. isHot:thisData.isHot,
  194. isUrgent:thisData.isUrgent,
  195. status:thisData.status,
  196. isHot:thisData.isHot,
  197. pictureUrl: thisData.pictureUrl ? splitUrl(thisData.pictureUrl, ',', globalConfig.avatarHost + '/upload') : []
  198. });
  199. }.bind(this),
  200. }).always(function () {
  201. this.setState({
  202. loading: false
  203. });
  204. }.bind(this));
  205. },
  206. getTagsArr(e) {
  207. this.setState({ tags: e });
  208. },
  209. getPictureUrl(e) {
  210. this.setState({ pictureUrl: e });
  211. },
  212. handleSubmit(e,index) {
  213. e.preventDefault();
  214. this.props.form.validateFields((err, values) => {
  215. //url转化
  216. let thePictureUrl = [];
  217. if (this.state.pictureUrl.length) {
  218. let picArr = [];
  219. this.state.pictureUrl.map(function (item) {
  220. if ( item.response && item.response.data && item.response.data.length ){
  221. picArr.push(item.response.data);
  222. }
  223. });
  224. thePictureUrl = picArr.join(",");
  225. };
  226. if(!this.state.tags.length){
  227. message.warning('请填写关键词.')
  228. return false;
  229. }
  230. if (!err) {
  231. this.setState({
  232. loading: true
  233. });
  234. $.ajax({
  235. method: "post",
  236. dataType: "json",
  237. async:true,
  238. url: this.props.data.id ? globalConfig.context + '/api/user/demand/updateDemand' : globalConfig.context + '/api/user/demand/apply',
  239. data: {
  240. id: this.props.data.id,
  241. name: values.name,
  242. industryCategoryA: values.industryCategory ? values.industryCategory[0] : undefined,
  243. industryCategoryB: values.industryCategory ? values.industryCategory[1] : undefined,
  244. demandType: values.demandType,
  245. problemDes: values.problemDes,
  246. pictureUrl: thePictureUrl,
  247. crowdCost:values.crowdCost,
  248. keyword: this.state.tags ? this.state.tags.join(",") : [],
  249. keywords: this.state.tags,
  250. budgetCost:values.budgetCost,
  251. urgentDays:this.state.isUrgent?values.urgentDays:0,
  252. urgentMoney:this.state.isUrgent?values.urgentMoney:0,
  253. auditStatus:index,
  254. status: this.state.status,
  255. isUrgent: this.state.isUrgent,
  256. isHot:this.state.isHot,
  257. publishPages:values.publishPages,
  258. researchType:values.researchType
  259. }
  260. }).done(function (data) {
  261. this.setState({
  262. loading: false
  263. });
  264. if (!data.error.length) {
  265. message.success('操作成功!');
  266. this.setState({
  267. visible: false
  268. });
  269. this.props.handOk();
  270. } else {
  271. message.warning(data.error[0].message);
  272. }
  273. }.bind(this));
  274. }
  275. });
  276. },
  277. submission(e,index){
  278. this.handleSubmit(e,index);
  279. $.ajax({
  280. method: "POST",
  281. dataType: "json",
  282. crossDomain: false,
  283. async:true,
  284. url: globalConfig.context + "/api/user/demand/publishDemand",
  285. data: {
  286. id: this.state.id,
  287. auditStatus:index
  288. }
  289. }).done(function (data) {
  290. if (!data.error.length) {
  291. this.setState({
  292. loading: false,
  293. });
  294. } else {
  295. message.warning(data.error[0].message);
  296. };
  297. }.bind(this));
  298. },
  299. cancelFun(){
  300. this.props.closeDesc();
  301. },
  302. componentWillMount() {
  303. if (this.props.data.id) {
  304. this.loadData(this.props.data.id);
  305. } else {
  306. this.state.data = {};
  307. this.state.tags = [];
  308. this.setState({
  309. publishPagesArr:['app_demand_list','web_demand_list']
  310. })
  311. };
  312. },
  313. componentWillReceiveProps(nextProps) {
  314. if (!this.props.visible && nextProps.visible) {
  315. this.state.textFileList = [];
  316. this.state.videoFileList = [];
  317. if (nextProps.data.id) {
  318. this.loadData(nextProps.data.id);
  319. } else {
  320. this.state.data = {};
  321. this.state.isUrgent=undefined;//加急需求
  322. this.state.isHot=undefined;//是否悬赏
  323. this.state.status=undefined;
  324. this.state.pictureUrl = [];
  325. this.state.tags = [];
  326. this.setState({
  327. publishPagesArr:['app_demand_list','web_demand_list']
  328. })
  329. };
  330. this.props.form.resetFields();
  331. };
  332. },
  333. render() {
  334. const theData = this.state.data || {};
  335. const { getFieldDecorator,getFieldsValue } = this.props.form;
  336. const FormItem = Form.Item
  337. const formItemLayout = {
  338. labelCol: { span: 6 },
  339. wrapperCol: { span: 12 },
  340. };
  341. let demandType =(getFieldsValue(['demandType']).demandType);
  342. return (
  343. <div className='login'>
  344. <Form layout="horizontal" onSubmit={(e)=>{this.handleSubmit(e,0)}} id="demand-form">
  345. <Spin spinning={this.state.loading}>
  346. <div className="clearfix">
  347. <FormItem labelCol={{ span: 3 }} wrapperCol={{ span: 18 }} label="发个需求吧">
  348. {getFieldDecorator('problemDes', {
  349. rules: [ { required: true, message: '此项为必填项!' } ],
  350. initialValue: theData.problemDes
  351. })(<Input type="textarea" rows={4} placeholder="亲,发个需求吧!让技术专家主动找到您." />)}
  352. </FormItem>
  353. <FormItem className="half-item" {...formItemLayout} label="标题">
  354. {getFieldDecorator('name', {
  355. rules: [ { required: true, message: '此项为必填项!' } ],
  356. initialValue: theData.name
  357. })(<Input placeholder="给您的需求配个标题吧." />)}
  358. </FormItem>
  359. </div>
  360. <div className="clearfix">
  361. <FormItem
  362. labelCol={{ span: 3 }}
  363. wrapperCol={{ span: 18 }}
  364. label={<span><strong style={{color:'red'}}>*</strong>关键词</span>} >
  365. <KeyWordTagGroup
  366. keyWordArr={this.state.tags}
  367. tagsArr={(e)=>{this.setState({tags:e})}}
  368. />
  369. </FormItem>
  370. </div>
  371. <FormItem labelCol={{ span: 3 }} wrapperCol={{ span: 18 }} label="行业领域">
  372. {getFieldDecorator('industryCategory', {
  373. rules: [ { type: 'array', required: true, message: '此项为必填项!' } ],
  374. initialValue: [ theData.industryCategoryA, theData.industryCategoryB ]
  375. })(<Cascader style={{ width: 300 }} options={industry} placeholder="请选择一个行业" />)}
  376. </FormItem>
  377. <div className="clearfix">
  378. <FormItem className="half-item" {...formItemLayout} label="需求类型">
  379. {getFieldDecorator('demandType', {
  380. rules: [ { required: true, message: '此项为必填项!' } ],
  381. initialValue:(theData.demandType||theData.demandType=='0'?theData.demandType.toString():undefined)
  382. })(
  383. <Select style={{ width: 160 }} placeholder="请选择需求类型"
  384. >
  385. {this.props.demandTypeOption}
  386. </Select>
  387. )}
  388. </FormItem>
  389. {demandType=='5'||theData.demandType=='5'?
  390. <FormItem className="half-item" {...formItemLayout} label="人才酬劳">
  391. {getFieldDecorator('budgetCost', {
  392. rules: [ { required: false } ],
  393. initialValue: theData.budgetCost
  394. })(<InputNumber min={0} max={999999} step={0.01} placeholder="输入酬劳."/>)}
  395. <span style={{ marginLeft: '5px' }}>万元</span>
  396. </FormItem>:''}
  397. {demandType=='3'||theData.demandType=='3'?<div className="clearfix"><FormItem className="half-item" {...formItemLayout} label="资金需求额度">
  398. {getFieldDecorator('crowdCost', {
  399. rules: [ { required: false } ],
  400. initialValue: theData.crowdCost
  401. })(<InputNumber min={0} max={999999} step={0.01} placeholder="输入资金需求额度."/>)}
  402. <span style={{ marginLeft: '5px' }}>万元</span>
  403. </FormItem>
  404. <FormItem className="half-item" {...formItemLayout} label="资金用途">
  405. {getFieldDecorator('researchType', {
  406. rules: [ { required: false } ],
  407. initialValue: theData.researchType||theData.researchType=='0'?theData.researchType.toString():undefined
  408. })(
  409. <Select placeholder="选择资金用途" style={{ width: 160 }} >
  410. <Select.Option value="0" >研发</Select.Option>
  411. <Select.Option value="1" >扩大再生产</Select.Option>
  412. </Select>
  413. )}
  414. </FormItem>
  415. </div>:''
  416. }
  417. </div>
  418. <p style={{marginLeft:40,fontSize:18,marginBottom:15}}>您还可以说明</p>
  419. <div className="clearfix">
  420. <FormItem className="half-item" {...formItemLayout} label="加急">
  421. <Radio.Group value={this.state.isUrgent} onChange={(e)=>{this.setState({isUrgent:e.target.value})}}>
  422. <Radio value={0}>非加急</Radio>
  423. <Radio value={1}>加急</Radio>
  424. </Radio.Group>
  425. </FormItem>
  426. {this.state.isUrgent?<div className="clearfix">
  427. <FormItem className="half-item" {...formItemLayout} label="日期">
  428. {getFieldDecorator('urgentDays', {
  429. initialValue: theData.urgentDays
  430. })(<InputNumber min={0} max={999999} step={0} placeholder="输入天数."/>)}
  431. <span style={{ marginLeft: '5px' }}>天</span>
  432. </FormItem>
  433. <FormItem className="half-item" {...formItemLayout} label="加急金额">
  434. {getFieldDecorator('urgentMoney', {
  435. initialValue: theData.urgentMoney
  436. })(<InputNumber min={0} max={999999} step={0.01} placeholder="输入金额."/>)}
  437. <span style={{ marginLeft: '5px' }}>万元</span>
  438. </FormItem>
  439. </div>:''}
  440. </div>
  441. <div className="clearfix">
  442. <FormItem className="half-item" {...formItemLayout} label="热点需求">
  443. <Radio.Group value={this.state.isHot} onChange={(e)=>{this.setState({isHot:e.target.value})}}>
  444. <Radio value={0}>否</Radio>
  445. <Radio value={1}>是</Radio>
  446. </Radio.Group>
  447. </FormItem>
  448. <FormItem className="half-item" {...formItemLayout} label="解决">
  449. <Radio.Group value={this.state.status} onChange={(e)=>{this.setState({status:e.target.value})}}>
  450. <Radio value={0}>进行中</Radio>
  451. <Radio value={1}>未解决</Radio>
  452. <Radio value={2}>已解决</Radio>
  453. </Radio.Group>
  454. </FormItem>
  455. </div>
  456. <FormItem labelCol={{ span: 3 }} wrapperCol={{ span: 18 }} label="需求文件(图片)">
  457. <PicturesWall
  458. uid={theData.employerId}
  459. fileList={this.getPictureUrl}
  460. pictureUrl={this.state.pictureUrl}
  461. visible={this.props.visible}
  462. />
  463. </FormItem>
  464. <div className="clearfix">
  465. <FormItem className="full-item"
  466. labelCol={{ span: 3 }}
  467. wrapperCol={{ span: 18 }} label="发布位置">
  468. {getFieldDecorator('publishPages', {
  469. rules: [ { required: false } ],
  470. initialValue: this.state.publishPagesArr
  471. })(
  472. <Checkbox.Group>
  473. <Row>
  474. <Col span={6}><Checkbox value="web_index">网站首页</Checkbox></Col>
  475. <Col span={6}><Checkbox value="web_demand_main">网站需求主页</Checkbox></Col>
  476. <Col span={6}><Checkbox value="web_demand_list" disabled>网站需求搜索页</Checkbox></Col>
  477. <Col span={6}><Checkbox value="app_index">APP首页</Checkbox></Col>
  478. <Col span={6}><Checkbox value="app_demand_main">APP需求首页</Checkbox></Col>
  479. <Col span={6}><Checkbox value="app_demand_list" disabled>APP需求搜索页</Checkbox></Col>
  480. </Row>
  481. </Checkbox.Group>
  482. )}
  483. </FormItem>
  484. </div>
  485. {theData.auditInfo&&<div className="clearfix">
  486. <FormItem labelCol={{ span: 3 }} wrapperCol={{ span: 18 }} label="审核信息">
  487. <span>{theData.auditInfo}</span>
  488. </FormItem>
  489. </div>}
  490. <div className="clearfix">
  491. <FormItem wrapperCol={{ span: 12, offset: 3 }}>
  492. <Button className="set-submit" type="primary" htmlType="submit">
  493. 保存草稿
  494. </Button>
  495. <Button
  496. className="set-submit"
  497. type="ghost"
  498. onClick={(e) => {
  499. if(this.props.data.id){
  500. this.submission(e,1)
  501. }else{
  502. this.handleSubmit(e,1)
  503. }
  504. }}
  505. >
  506. 提交审核
  507. </Button>
  508. <Button className="set-submit" type="ghost" onClick={this.cancelFun}>
  509. 取消
  510. </Button>
  511. </FormItem>
  512. </div>
  513. </Spin>
  514. </Form>
  515. </div>
  516. )
  517. }
  518. }));
  519. export default DemandDetailForm;