techDemandDesc.jsx 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625
  1. import React from 'react';
  2. import { Icon, Tooltip, Modal, message, Spin, Upload, Input, InputNumber, Select, DatePicker, Button, Radio, Form, Cascader, Tag } from 'antd';
  3. import moment from 'moment';
  4. import './techDemand.less';
  5. import ajax from 'jquery/src/ajax/xhr.js';
  6. import $ from 'jquery/src/ajax';
  7. import { IndustryObject } from '../../DicIndustryList.js';
  8. import { beforeUploadFile, splitUrl, companySearch } from '../../tools.js';
  9. const KeyWordTagGroup = React.createClass({
  10. getInitialState() {
  11. return {
  12. tags: [],
  13. inputVisible: false,
  14. inputValue: ''
  15. };
  16. },
  17. handleClose(removedTag) {
  18. const tags = this.state.tags.filter(tag => tag !== removedTag);
  19. this.props.tagsArr(tags);
  20. this.setState({ tags });
  21. },
  22. showInput() {
  23. this.setState({ inputVisible: true }, () => this.input.focus());
  24. },
  25. handleInputChange(e) {
  26. this.setState({ inputValue: e.target.value });
  27. },
  28. handleInputConfirm() {
  29. const state = this.state;
  30. const inputValue = state.inputValue;
  31. let tags = state.tags;
  32. if (inputValue && tags.indexOf(inputValue) === -1) {
  33. tags = [...tags, inputValue];
  34. }
  35. this.props.tagsArr(tags);
  36. this.setState({
  37. tags,
  38. inputVisible: false,
  39. inputValue: '',
  40. });
  41. },
  42. componentWillMount() {
  43. this.state.tags = this.props.keyWordArr;
  44. },
  45. componentWillReceiveProps(nextProps) {
  46. if (this.props.keyWordArr != nextProps.keyWordArr) {
  47. this.state.tags = nextProps.keyWordArr;
  48. };
  49. },
  50. render() {
  51. const { tags, inputVisible, inputValue } = this.state;
  52. return (
  53. <div className="keyWord-tips">
  54. {tags.map((tag, index) => {
  55. const isLongTag = tag.length > 10;
  56. const tagElem = (
  57. <Tag key={tag} closable={index !== -1} afterClose={() => this.handleClose(tag)}>
  58. {isLongTag ? `${tag.slice(0, 10)}...` : tag}
  59. </Tag>
  60. );
  61. return isLongTag ? <Tooltip title={tag}>{tagElem}</Tooltip> : tagElem;
  62. })}
  63. {inputVisible && (
  64. <Input
  65. ref={input => this.input = input}
  66. type="text"
  67. style={{ width: 78 }}
  68. value={inputValue}
  69. onChange={this.handleInputChange}
  70. onBlur={this.handleInputConfirm}
  71. onPressEnter={this.handleInputConfirm}
  72. />
  73. )}
  74. {!inputVisible && <Button className="addtips" type="dashed" disabled={tags.length > 9 ? true : false} onClick={this.showInput}>+ 新关键词</Button>}
  75. </div>
  76. );
  77. }
  78. });
  79. const PicturesWall = React.createClass({
  80. getInitialState() {
  81. return {
  82. previewVisible: false,
  83. previewImage: '',
  84. fileList: [],
  85. }
  86. },
  87. handleCancel() {
  88. this.setState({ previewVisible: false })
  89. },
  90. handlePreview(file) {
  91. this.setState({
  92. previewImage: file.url || file.thumbUrl,
  93. previewVisible: true,
  94. });
  95. },
  96. handleChange(info) {
  97. let fileList = info.fileList;
  98. this.setState({ fileList });
  99. this.props.fileList(fileList);
  100. },
  101. componentWillReceiveProps(nextProps) {
  102. this.state.fileList = nextProps.pictureUrl;
  103. },
  104. render() {
  105. const { previewVisible, previewImage, fileList } = this.state;
  106. const uploadButton = (
  107. <div>
  108. <Icon type="plus" />
  109. <div className="ant-upload-text">点击上传</div>
  110. </div>
  111. );
  112. return (
  113. <div className="clearfix">
  114. <Upload
  115. action={globalConfig.context + "/api/user/demand/uploadPicture"}
  116. data={{ 'sign': 'demand_picture' }}
  117. listType="picture-card"
  118. fileList={fileList}
  119. onPreview={this.handlePreview}
  120. onChange={this.handleChange} >
  121. {fileList.length >= 5 ? null : uploadButton}
  122. </Upload>
  123. <Modal maskClosable={false} visible={previewVisible} footer={null} onCancel={this.handleCancel}>
  124. <img alt="example" style={{ width: '100%' }} src={previewImage} />
  125. </Modal>
  126. </div>
  127. );
  128. }
  129. });
  130. const DemandDetailForm = Form.create()(React.createClass({
  131. getInitialState() {
  132. return {
  133. visible: false,
  134. loading: false,
  135. textFileList: [],
  136. videoFileList: [],
  137. pictureUrl: [],
  138. tags: []
  139. };
  140. },
  141. loadData(id) {
  142. this.setState({
  143. loading: true
  144. });
  145. $.ajax({
  146. method: "get",
  147. dataType: "json",
  148. crossDomain: false,
  149. url: globalConfig.context + (window.userData.type == 0 ? '/api/user/demand/userDemandDetail' : '/api/user/demand/orgDemandDetail'),
  150. data: {
  151. id: id
  152. },
  153. success: function (data) {
  154. let thisData = data.data;
  155. if (!thisData) {
  156. if (data.error && data.error.length) {
  157. message.warning(data.error[0].message);
  158. };
  159. thisData = {};
  160. };
  161. let d = new Date()
  162. if (thisData && thisData.dateOfBirthMonth && thisData.dateOfBirthYear) {
  163. d.setMonth(thisData.dateOfBirthMonth - 1);
  164. d.setYear(parseInt(thisData.dateOfBirthYear));
  165. };
  166. this.setState({
  167. data: thisData,
  168. tags: thisData.keyword ? thisData.keyword.split(",") : [],
  169. pictureUrl: thisData.pictureUrl ? splitUrl(thisData.pictureUrl, ',', globalConfig.avatarHost + '/upload') : []
  170. });
  171. }.bind(this),
  172. }).always(function () {
  173. this.setState({
  174. loading: false
  175. });
  176. }.bind(this));
  177. },
  178. getContactsList() {
  179. $.ajax({
  180. method: "get",
  181. dataType: "json",
  182. crossDomain: false,
  183. url: globalConfig.context + "/api/user/cognizance/getContacts",
  184. success: function (data) {
  185. let theOption = [];
  186. if (data.error.length || !data.data) {
  187. return;
  188. };
  189. for (let item in data.data) {
  190. let theData = data.data[item];
  191. theOption.push(
  192. <Select.Option value={item} key={theData}>{theData}</Select.Option>
  193. );
  194. };
  195. this.setState({
  196. contactsOption: theOption
  197. });
  198. }.bind(this),
  199. });
  200. },
  201. getTagsArr(e) {
  202. this.setState({ tags: e });
  203. },
  204. getPictureUrl(e) {
  205. this.setState({ pictureUrl: e });
  206. },
  207. handleSubmit(e) {
  208. e.preventDefault();
  209. this.props.form.validateFields((err, values) => {
  210. //keyword长度判断
  211. if (this.state.tags.length < 3) {
  212. message.warning('关键词数量不能小于3个!');
  213. };
  214. //url转化
  215. let thePictureUrl = [];
  216. if (this.state.pictureUrl.length) {
  217. let picArr = [];
  218. this.state.pictureUrl.map(function (item) {
  219. picArr.push(item.response.data);
  220. });
  221. thePictureUrl = picArr.join(",");
  222. };
  223. if (!err) {
  224. this.setState({
  225. loading: true
  226. });
  227. $.ajax({
  228. method: "POST",
  229. dataType: "json",
  230. crossDomain: false,
  231. url: this.props.data.id ? globalConfig.context + '/api/user/demand/update' : globalConfig.context + '/api/user/demand/apply',
  232. data: {
  233. id: this.props.data.id,
  234. dataCategory: window.userData.type ? Number(window.userData.type) : undefined,
  235. serialNumber: this.props.data.serialNumber,
  236. name: values.name,
  237. keyword: this.state.tags ? this.state.tags.join(",") : [],
  238. industryCategoryA: values.industryCategory ? values.industryCategory[0] : undefined,
  239. industryCategoryB: values.industryCategory ? values.industryCategory[1] : undefined,
  240. demandType: values.demandType,
  241. problemDes: values.problemDes,
  242. technicalRequirements: values.technicalRequirements,
  243. pictureUrl: thePictureUrl,
  244. textFileUrl: this.state.textFileUrl,
  245. videoUrl: values.videoUrl,
  246. fixedBudget: values.fixedBudget,
  247. fixedCycle: values.fixedCycle,
  248. peopleNumber: values.peopleNumber,
  249. fixedScheme: values.fixedScheme,
  250. costEscrow: values.costEscrow,
  251. budgetCost: values.budgetCost,
  252. releaseStatus: values.releaseStatus,
  253. principalId: values.principalId,
  254. validityPeriodFormattedDate: values.validityPeriod ? values.validityPeriod.format('YYYY-MM-DD') : undefined,
  255. //
  256. contacts: values.contacts,
  257. status: this.state.status
  258. }
  259. }).done(function (data) {
  260. if (!data.error.length) {
  261. message.success('保存成功!');
  262. this.setState({
  263. visible: false
  264. });
  265. this.props.handleOk();
  266. } else {
  267. message.warning(data.error[0].message);
  268. }
  269. }.bind(this));
  270. }
  271. });
  272. },
  273. componentWillMount() {
  274. if (window.userData.type == "1") {
  275. this.getContactsList();
  276. };
  277. if (this.props.data.id) {
  278. this.loadData(this.props.data.id);
  279. } else {
  280. this.state.data = {};
  281. };
  282. },
  283. componentWillReceiveProps(nextProps) {
  284. if (!this.props.visible && nextProps.visible) {
  285. this.state.textFileList = [];
  286. this.state.videoFileList = [];
  287. if (nextProps.data.id) {
  288. this.loadData(nextProps.data.id);
  289. } else {
  290. this.state.data = {};
  291. this.state.tags = [];
  292. this.state.pictureUrl = [];
  293. };
  294. this.props.form.resetFields();
  295. };
  296. },
  297. render() {
  298. const theData = this.state.data || {};
  299. const { getFieldDecorator } = this.props.form;
  300. const FormItem = Form.Item
  301. const formItemLayout = {
  302. labelCol: { span: 6 },
  303. wrapperCol: { span: 12 },
  304. };
  305. return (
  306. <Form horizontal onSubmit={this.handleSubmit} id="demand-form">
  307. <div className="clearfix">
  308. <FormItem className="half-item"
  309. {...formItemLayout}
  310. label="编号" >
  311. <span>{theData.serialNumber}</span>
  312. </FormItem>
  313. <FormItem className="half-item"
  314. {...formItemLayout}
  315. label="需求名称" >
  316. {getFieldDecorator('name', {
  317. rules: [{ required: true, message: '此项为必填项!' }],
  318. initialValue: theData.name
  319. })(
  320. <Input />
  321. )}
  322. </FormItem>
  323. {window.userData.type == "1" ? <FormItem className="half-item"
  324. {...formItemLayout}
  325. label="联系人" >
  326. {getFieldDecorator('contacts', {
  327. initialValue: theData.contacts
  328. })(
  329. <Select style={{ width: 260 }}
  330. placeholder="请选择联系人"
  331. notFoundContent="未获取到联系人列表"
  332. showSearch
  333. filterOption={companySearch}>
  334. {this.state.contactsOption}
  335. </Select>
  336. )}
  337. </FormItem> : <div></div>}
  338. </div>
  339. <div className="clearfix">
  340. <FormItem className="half-item"
  341. {...formItemLayout}
  342. label="是否发布" >
  343. {getFieldDecorator('releaseStatus', {
  344. initialValue: theData.releaseStatus
  345. })(
  346. <Radio.Group>
  347. <Radio value="0">未发布</Radio>
  348. <Radio value="1">发布</Radio>
  349. </Radio.Group>
  350. )}
  351. </FormItem>
  352. <FormItem className="half-item"
  353. {...formItemLayout}
  354. label="发布时间" >
  355. <span>{theData.releaseDateFormattedDate}</span>
  356. </FormItem>
  357. </div>
  358. <div className="clearfix">
  359. <FormItem className="half-item"
  360. {...formItemLayout}
  361. label="需求状态" >
  362. {(() => {
  363. if (theData.status > 1) {
  364. return <Radio.Group
  365. value={this.state.status}
  366. onChange={(e) => { this.setState({ status: e }); }}>
  367. <Radio value="2">未解决</Radio>
  368. <Radio value="3">已解决</Radio>
  369. </Radio.Group>
  370. } else {
  371. switch (theData.status) {
  372. case "0":
  373. return <span>草稿</span>;
  374. case "1":
  375. return <span>进行中</span>;
  376. };
  377. };
  378. })()}
  379. </FormItem>
  380. <FormItem className="half-item"
  381. {...formItemLayout}
  382. label="需求创建时间" >
  383. <span>{theData.createTimeFormattedDate}</span>
  384. </FormItem>
  385. </div>
  386. <FormItem
  387. labelCol={{ span: 3 }}
  388. wrapperCol={{ span: 20 }}
  389. label="关键词" >
  390. <KeyWordTagGroup
  391. keyWordArr={this.state.tags}
  392. tagsArr={this.getTagsArr}
  393. visible={this.props.visible} />
  394. </FormItem>
  395. <FormItem
  396. labelCol={{ span: 3 }}
  397. wrapperCol={{ span: 18 }}
  398. label="行业类别" >
  399. {getFieldDecorator('industryCategory', {
  400. rules: [{ type: 'array', required: true, message: '此项为必填项!' }],
  401. initialValue: [theData.industryCategoryA, theData.industryCategoryB]
  402. })(
  403. <Cascader style={{ width: 300 }} options={IndustryObject} placeholder="请选择一个行业" />
  404. )}
  405. </FormItem>
  406. <div className="clearfix">
  407. <FormItem className="half-item"
  408. {...formItemLayout}
  409. label="需求类型" >
  410. {getFieldDecorator('demandType', {
  411. rules: [{ required: true, message: '此项为必填项!' }],
  412. initialValue: theData.demandType
  413. })(
  414. <Select style={{ width: 160 }} placeholder="请选择需求类型">
  415. {this.props.demandTypeOption}
  416. </Select>
  417. )}
  418. </FormItem>
  419. </div>
  420. <FormItem
  421. labelCol={{ span: 3 }}
  422. wrapperCol={{ span: 18 }}
  423. label="问题说明" >
  424. {getFieldDecorator('problemDes', {
  425. rules: [{ required: true, message: '此项为必填项!' }],
  426. initialValue: theData.problemDes
  427. })(
  428. <Input type="textarea" rows={4} />
  429. )}
  430. </FormItem>
  431. <FormItem
  432. labelCol={{ span: 3 }}
  433. wrapperCol={{ span: 18 }}
  434. label="技术指标要求" >
  435. {getFieldDecorator('technicalRequirements', {
  436. initialValue: theData.technicalRequirements
  437. })(
  438. <Input type="textarea" rows={2} />
  439. )}
  440. </FormItem>
  441. <FormItem
  442. labelCol={{ span: 3 }}
  443. wrapperCol={{ span: 18 }}
  444. label="需求文件(图片)" >
  445. <PicturesWall
  446. uid={theData.uid}
  447. fileList={this.getPictureUrl}
  448. pictureUrl={this.state.pictureUrl}
  449. visible={this.props.visible} />
  450. </FormItem>
  451. <FormItem
  452. labelCol={{ span: 3 }}
  453. wrapperCol={{ span: 6 }}
  454. label="需求文件(文本)" >
  455. <Upload
  456. name="ratepay"
  457. action={globalConfig.context + "/api/user/demand/uploadTextFile"}
  458. data={{ 'sign': 'demand_text_file'}}
  459. beforeUpload={beforeUploadFile}
  460. fileList={this.state.textFileList}
  461. onChange={(info) => {
  462. if (info.file.status !== 'uploading') {
  463. console.log(info.file, info.fileList);
  464. }
  465. if (info.file.status === 'done') {
  466. if (!info.file.response.error.length) {
  467. message.success(`${info.file.name} 文件上传成功!`);
  468. } else {
  469. message.warning(info.file.response.error[0].message);
  470. return;
  471. };
  472. this.state.textFileUrl = info.file.response.data;
  473. } else if (info.file.status === 'error') {
  474. message.error(`${info.file.name} 文件上传失败。`);
  475. };
  476. this.setState({ textFileList: info.fileList.slice(-1) });
  477. }} >
  478. <Button><Icon type="upload" /> 上传需求文本文件 </Button>
  479. </Upload>
  480. <p style={{ marginTop: '10px' }}>{theData.textFileUrl ?
  481. <span className="download-file">
  482. <a onClick={() => { window.open(globalConfig.context + '/api/user/demand/download?id=' + this.props.data.id) }}>需求文件(文本文件)</a>
  483. </span>
  484. : <span><Icon type="exclamation-circle" style={{ color: '#ffbf00', marginRight: '6px' }} />未上传!</span>}</p>
  485. </FormItem>
  486. <FormItem
  487. labelCol={{ span: 3 }}
  488. wrapperCol={{ span: 18 }}
  489. label="需求文件(视频地址)" >
  490. {getFieldDecorator('videoUrl', {
  491. initialValue: theData.videoUrl
  492. })(
  493. <Input />
  494. )}
  495. </FormItem>
  496. <div className="clearfix">
  497. <FormItem className="half-item"
  498. {...formItemLayout}
  499. label="固定周期" >
  500. {getFieldDecorator('fixedCycle', {
  501. initialValue: theData.fixedCycle
  502. })(
  503. <Input />
  504. )}
  505. </FormItem>
  506. <FormItem className="half-item"
  507. {...formItemLayout}
  508. label="固定人数" >
  509. {getFieldDecorator('peopleNumber', {
  510. initialValue: theData.peopleNumber
  511. })(
  512. <InputNumber />
  513. )}
  514. <span style={{ marginLeft: '20px' }}>人</span>
  515. </FormItem>
  516. </div>
  517. <FormItem
  518. labelCol={{ span: 3 }}
  519. wrapperCol={{ span: 18 }}
  520. label="固定方案" >
  521. {getFieldDecorator('fixedScheme', {
  522. initialValue: theData.fixedScheme
  523. })(
  524. <Input type="textarea" rows={2} />
  525. )}
  526. </FormItem>
  527. <div className="clearfix">
  528. <FormItem className="half-item"
  529. {...formItemLayout}
  530. label="预算费用" >
  531. {getFieldDecorator('budgetCost', {
  532. initialValue: theData.budgetCost
  533. })(
  534. <InputNumber />
  535. )}
  536. <span style={{ marginLeft: '20px' }}>万元</span>
  537. </FormItem>
  538. <FormItem className="half-item"
  539. {...formItemLayout}
  540. label="费用托管" >
  541. {getFieldDecorator('costEscrow', {
  542. initialValue: theData.costEscrow
  543. })(
  544. <Radio.Group>
  545. <Radio value={0}>否</Radio>
  546. <Radio value={1}>是</Radio>
  547. </Radio.Group>
  548. )}
  549. </FormItem>
  550. <FormItem className="half-item"
  551. {...formItemLayout}
  552. label="有效期限" >
  553. {getFieldDecorator('validityPeriod', {
  554. initialValue: theData.validityPeriod ? moment(theData.validityPeriod) : null
  555. })(
  556. <DatePicker />
  557. )}
  558. </FormItem>
  559. </div>
  560. <FormItem wrapperCol={{ span: 12, offset: 3 }}>
  561. <Button className="set-submit" type="primary" htmlType="submit">保存</Button>
  562. <Button className="set-submit" type="ghost" onClick={this.props.closeDesc}>取消</Button>
  563. </FormItem>
  564. </Form >
  565. )
  566. }
  567. }));
  568. const DemandDetail = React.createClass({
  569. getInitialState() {
  570. return {
  571. visible: false
  572. };
  573. },
  574. showModal() {
  575. this.setState({
  576. visible: true,
  577. });
  578. },
  579. handleCancel(e) {
  580. this.setState({
  581. visible: false,
  582. });
  583. this.props.closeDesc(false);
  584. },
  585. handleOk(e) {
  586. this.setState({
  587. visible: false,
  588. });
  589. this.props.closeDesc(false, true);
  590. },
  591. componentWillReceiveProps(nextProps) {
  592. this.state.visible = nextProps.showDesc;
  593. },
  594. render() {
  595. if (this.props.data) {
  596. return (
  597. <div className="patent-desc">
  598. <Modal maskClosable={false} title="用户需求详情" visible={this.state.visible}
  599. onOk={this.checkPatentProcess} onCancel={this.handleCancel}
  600. width='1000px'
  601. footer=''
  602. className="admin-desc-content">
  603. <DemandDetailForm
  604. data={this.props.data}
  605. detailApiUrl={this.props.detailApiUrl}
  606. companyOption={this.props.companyOption}
  607. userOption={this.props.userOption}
  608. demandTypeOption={this.props.demandTypeOption}
  609. closeDesc={this.handleCancel}
  610. visible={this.state.visible}
  611. handleOk={this.handleOk} />
  612. </Modal>
  613. </div>
  614. );
  615. } else {
  616. return <div></div>
  617. }
  618. },
  619. });
  620. export default DemandDetail;