demandForm.jsx 18 KB

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