demandForm.jsx 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451
  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 PicturesWall = React.createClass({
  32. getInitialState() {
  33. return {
  34. previewVisible: false,
  35. previewImage: '',
  36. fileList: []
  37. };
  38. },
  39. handleCancel() {
  40. this.setState({ previewVisible: false });
  41. },
  42. handlePreview(file) {
  43. this.setState({
  44. previewImage: file.url || file.thumbUrl,
  45. previewVisible: true
  46. });
  47. },
  48. handleChange(info) {
  49. let fileList = info.fileList;
  50. this.setState({ fileList });
  51. this.props.fileList(fileList);
  52. },
  53. componentWillReceiveProps(nextProps) {
  54. this.state.fileList = nextProps.pictureUrl;
  55. },
  56. render() {
  57. const { previewVisible, previewImage, fileList } = this.state;
  58. const uploadButton = (
  59. <div>
  60. <Icon type="plus" />
  61. <div className="ant-upload-text">点击上传</div>
  62. </div>
  63. );
  64. return (
  65. <div className="clearfix">
  66. <Upload
  67. action={globalConfig.context + '/api/user/demand/uploadPicture'}
  68. data={{ sign: 'demand_picture', uid: this.props.uid }}
  69. listType="picture-card"
  70. fileList={fileList}
  71. onPreview={this.handlePreview}
  72. onChange={this.handleChange}
  73. >
  74. {fileList.length >= 5 ? null : uploadButton}
  75. </Upload>
  76. <Modal maskClosable={false} visible={previewVisible} footer={null} onCancel={this.handleCancel}>
  77. <img alt="example" style={{ width: '100%' }} src={previewImage} />
  78. </Modal>
  79. </div>
  80. );
  81. }
  82. });
  83. const DemandDetailForm = Form.create()(React.createClass({
  84. getInitialState() {
  85. return {
  86. visible: false,
  87. loading: false,
  88. auditStatus: 0,
  89. textFileList: [],
  90. videoFileList: [],
  91. pictureUrl: [],
  92. };
  93. },
  94. loadData(id) {
  95. this.setState({
  96. loading: true
  97. });
  98. $.ajax({
  99. method: "get",
  100. dataType: "json",
  101. crossDomain: false,
  102. url: globalConfig.context + '/api/user/demand/orgDemandDetail' ,
  103. data: {
  104. id: id
  105. },
  106. success: function (data) {
  107. let thisData = data.data;
  108. if (!thisData) {
  109. if (data.error && data.error.length) {
  110. message.warning(data.error[0].message);
  111. };
  112. thisData = {};
  113. };
  114. let ProvinceCityArr = [];
  115. let ProvinceS = thisData.locationProvince; //getprovince
  116. let citys = thisData.locationCity;
  117. let Areas = thisData.locationArea;
  118. ProvinceCityArr.push(ProvinceS, citys, Areas);
  119. this.setState({
  120. ProvinceCity:ProvinceCityArr,
  121. data: thisData,
  122. pictureUrl: thisData.pictureUrl ? splitUrl(thisData.pictureUrl, ',', globalConfig.avatarHost + '/upload') : []
  123. });
  124. }.bind(this),
  125. }).always(function () {
  126. this.setState({
  127. loading: false
  128. });
  129. }.bind(this));
  130. },
  131. getTagsArr(e) {
  132. this.setState({ tags: e });
  133. },
  134. getPictureUrl(e) {
  135. this.setState({ pictureUrl: e });
  136. },
  137. handleSubmit(e) {
  138. e.preventDefault();
  139. this.props.form.validateFields((err, values) => {
  140. console.log(values)
  141. //url转化
  142. let thePictureUrl = [];
  143. if (this.state.pictureUrl.length) {
  144. let picArr = [];
  145. this.state.pictureUrl.map(function (item) {
  146. if ( item.response && item.response.data && item.response.data.length ){
  147. picArr.push(item.response.data);
  148. }
  149. });
  150. thePictureUrl = picArr.join(",");
  151. };
  152. if (!err) {
  153. this.setState({
  154. loading: true
  155. });
  156. $.ajax({
  157. method: "POST",
  158. dataType: "json",
  159. crossDomain: false,
  160. url: this.props.data.id ? globalConfig.context + '/api/user/demand/update' : globalConfig.context + '/api/user/demand/apply',
  161. data: {
  162. id: this.props.data.id,
  163. dataCategory: Number(window.userData.type),
  164. serialNumber: this.props.data.serialNumber,
  165. name: values.name,
  166. keywords: this.state.tags,
  167. infoSources: 1,
  168. industryCategoryA: values.industryCategory ? values.industryCategory[0] : undefined,
  169. industryCategoryB: values.industryCategory ? values.industryCategory[1] : undefined,
  170. demandType: values.demandType,
  171. problemDes: values.problemDes,
  172. technicalRequirements: values.technicalRequirements,
  173. pictureUrl: thePictureUrl,
  174. textFileUrl: this.state.textFileUrl,
  175. videoUrl: values.videoUrl,
  176. fixedBudget: values.fixedBudget,
  177. fixedCycle: values.fixedCycle,
  178. peopleNumber: values.peopleNumber,
  179. fixedScheme: values.fixedScheme,
  180. costEscrow: values.costEscrow,
  181. budgetCost: values.budgetCost,
  182. releaseStatus: values.releaseStatus,
  183. principalId: values.principalId,
  184. validityPeriodFormattedDate: values.validityPeriod ? values.validityPeriod.format('YYYY-MM-DD') : undefined,
  185. //
  186. contacts: values.contacts,
  187. status: this.state.status,
  188. auditStatus: this.state.auditStatus
  189. }
  190. }).done(function (data) {
  191. this.state.auditStatus = 0;
  192. this.setState({
  193. loading: false
  194. });
  195. if (!data.error.length) {
  196. message.success('保存成功!');
  197. this.setState({
  198. visible: false
  199. });
  200. this.props.handleOk();
  201. } else {
  202. message.warning(data.error[0].message);
  203. }
  204. }.bind(this));
  205. }
  206. });
  207. },
  208. cancelFun(){
  209. this.props.closeDesc();
  210. },
  211. componentWillMount() {
  212. if (this.props.data.id) {
  213. this.loadData(this.props.data.id);
  214. } else {
  215. this.state.data = {};
  216. };
  217. },
  218. componentWillReceiveProps(nextProps) {
  219. if (!this.props.visible && nextProps.visible) {
  220. this.state.textFileList = [];
  221. this.state.videoFileList = [];
  222. if (nextProps.data.id) {
  223. this.loadData(nextProps.data.id);
  224. } else {
  225. this.state.data = {};
  226. this.state.demandType=undefined; //需求类型
  227. this.state.urgent=undefined;//加急需求
  228. this.state.offer=undefined;//是否悬赏
  229. this.state.hotDemand=undefined;
  230. this.state.solve=undefined;
  231. this.state.pictureUrl = [];
  232. };
  233. this.props.form.resetFields();
  234. };
  235. },
  236. render() {
  237. const theData = this.state.data || {};
  238. const { getFieldDecorator,getFieldsValue } = this.props.form;
  239. const FormItem = Form.Item
  240. const formItemLayout = {
  241. labelCol: { span: 6 },
  242. wrapperCol: { span: 12 },
  243. };
  244. let demandType =(getFieldsValue(['demandType']).demandType);
  245. return (
  246. <div className='login'>
  247. <Form layout="horizontal" onSubmit={this.handleSubmit} id="demand-form">
  248. <Spin spinning={this.state.loading}>
  249. <div className="clearfix">
  250. <FormItem labelCol={{ span: 3 }} wrapperCol={{ span: 18 }} label="发个需求吧">
  251. {getFieldDecorator('problemDes', {
  252. rules: [ { required: true, message: '此项为必填项!' } ],
  253. initialValue: theData.problemDes
  254. })(<Input type="textarea" rows={4} placeholder="亲,发个需求吧!让技术专家主动找到您." />)}
  255. </FormItem>
  256. <FormItem className="half-item" {...formItemLayout} label="标题">
  257. {getFieldDecorator('name', {
  258. rules: [ { required: true, message: '此项为必填项!' } ],
  259. initialValue: theData.name
  260. })(<Input placeholder="给您的需求配个标题吧." />)}
  261. </FormItem>
  262. </div>
  263. <FormItem labelCol={{ span: 3 }} wrapperCol={{ span: 18 }} label="行业领域">
  264. {getFieldDecorator('industryCategory', {
  265. rules: [ { type: 'array', required: true, message: '此项为必填项!' } ],
  266. initialValue: [ theData.industryCategoryA, theData.industryCategoryB ]
  267. })(<Cascader style={{ width: 300 }} options={IndustryObject} placeholder="请选择一个行业" />)}
  268. </FormItem>
  269. <div className="clearfix">
  270. <FormItem className="half-item" {...formItemLayout} label="需求类型">
  271. {getFieldDecorator('demandType', {
  272. rules: [ { required: true, message: '此项为必填项!' } ],
  273. initialValue:theData.demandType
  274. })(
  275. <Select style={{ width: 160 }} placeholder="请选择需求类型"
  276. >
  277. {this.props.demandTypeOption}
  278. </Select>
  279. )}
  280. </FormItem>
  281. {demandType=='5'||theData.demandType=='5'?
  282. <FormItem className="half-item" {...formItemLayout} label="人才需求酬劳">
  283. {getFieldDecorator('name', {
  284. rules: [ { required: false } ],
  285. initialValue: theData.namea
  286. })(<InputNumber min={0} max={999999} step={0.01} placeholder="输入酬劳."/>)}
  287. <span style={{ marginLeft: '20px' }}>元/月</span>
  288. </FormItem>:''}
  289. {demandType=='3'||theData.demandType=='3'?<div className="clearfix"><FormItem className="half-item" {...formItemLayout} label="资金需求额度">
  290. {getFieldDecorator('name', {
  291. rules: [ { required: false } ],
  292. initialValue: theData.namea
  293. })(<InputNumber min={0} max={999999} step={0.01} placeholder="输入资金需求额度."/>)}
  294. <span style={{ marginLeft: '20px' }}>万元</span>
  295. </FormItem>
  296. <FormItem className="half-item" {...formItemLayout} label="资金用途">
  297. {getFieldDecorator('namea', {
  298. rules: [ { required: false } ],
  299. initialValue: theData.namea
  300. })(
  301. <Select placeholder="选择资金用途" style={{ width: 160 }} >
  302. <Select.Option value="0" >研发</Select.Option>
  303. <Select.Option value="1" >扩大再生产</Select.Option>
  304. </Select>
  305. )}
  306. </FormItem>
  307. </div>:''
  308. }
  309. </div>
  310. <p style={{marginLeft:40,fontSize:18,marginBottom:15}}>您还可以说明</p>
  311. <div className="clearfix">
  312. <FormItem className="half-item" {...formItemLayout} label="加急">
  313. <Radio.Group value={this.state.urgent} onChange={(e)=>{this.setState({urgent:e.target.value})}}>
  314. <Radio value={1}>加急</Radio>
  315. <Radio value={0}>非加急</Radio>
  316. </Radio.Group>
  317. </FormItem>
  318. {this.state.urgent?<FormItem className="half-item" {...formItemLayout} label="日期">
  319. {getFieldDecorator('validitytime', {
  320. initialValue: theData.validitytime ? moment(theData.validitytime) : null
  321. })(<DatePicker />)}
  322. </FormItem>:''}
  323. </div>
  324. <div className="clearfix">
  325. <FormItem className="half-item" {...formItemLayout} label="悬赏需求">
  326. <Radio.Group value={this.state.offer} onChange={(e)=>{this.setState({offer:e.target.value})}}>
  327. <Radio value={0}>否</Radio>
  328. <Radio value={1}>是</Radio>
  329. </Radio.Group>
  330. </FormItem>
  331. {this.state.offer>=1&&<FormItem className="half-item" {...formItemLayout} label="悬赏金额">
  332. {getFieldDecorator('budgetCost', {
  333. initialValue: theData.budgetCost
  334. })(<InputNumber min={0} max={999999} step={0.01} placeholder="输入金额."/>)}
  335. <span style={{ marginLeft: '20px' }}>万元</span>
  336. </FormItem>}
  337. </div>
  338. <div className="clearfix">
  339. <FormItem className="half-item" {...formItemLayout} label="热点需求">
  340. <Radio.Group value={this.state.hotDemand} onChange={(e)=>{this.setState({hotDemand:e.target.value})}}>
  341. <Radio value={0}>否</Radio>
  342. <Radio value={1}>是</Radio>
  343. </Radio.Group>
  344. </FormItem>
  345. <FormItem className="half-item" {...formItemLayout} label="解决">
  346. <Radio.Group value={this.state.solve} onChange={(e)=>{this.setState({solve:e.target.value})}}>
  347. <Radio value={0}>未解决</Radio>
  348. <Radio value={1}>已解决</Radio>
  349. </Radio.Group>
  350. </FormItem>
  351. </div>
  352. <div className="clearfix">
  353. <FormItem
  354. className="half-item"
  355. {...formItemLayout}
  356. label="地区"
  357. >
  358. <Cascader
  359. options={areaSelect()}
  360. value={this.state.ProvinceCity}
  361. placeholder="选择地区"
  362. onChange={(e, pre) => {
  363. this.setState({ ProvinceCity: e });
  364. }}
  365. />
  366. </FormItem>
  367. </div>
  368. <FormItem labelCol={{ span: 3 }} wrapperCol={{ span: 18 }} label="需求文件(图片)">
  369. <PicturesWall
  370. uid={theData.employerId}
  371. fileList={this.getPictureUrl}
  372. pictureUrl={this.state.pictureUrl}
  373. visible={this.props.visible}
  374. />
  375. </FormItem>
  376. <div>
  377. <FormItem className="half-item" {...formItemLayout} label="发布状态">
  378. {getFieldDecorator('releaseState', {
  379. rules: [ { required: false } ],
  380. initialValue: theData.releaseState
  381. })(
  382. <Select placeholder="选择发布状态" style={{ width: 160 }} >
  383. <Select.Option value="0" >草稿</Select.Option>
  384. <Select.Option value="1" >发布审核</Select.Option>
  385. <Select.Option value="2" >已发布</Select.Option>
  386. <Select.Option value="3" >发布失败</Select.Option>
  387. <Select.Option value="4" >已撤销</Select.Option>
  388. </Select>
  389. )}
  390. </FormItem>
  391. <FormItem className="half-item" {...formItemLayout} label="发布时间">
  392. {getFieldDecorator('releaseTime', {
  393. initialValue: theData.releaseTime ? moment(theData.releaseTime) : null
  394. })(<DatePicker />)}
  395. </FormItem>
  396. </div>
  397. <div className="clearfix">
  398. <FormItem className="full-item"
  399. labelCol={{ span: 3 }}
  400. wrapperCol={{ span: 18 }} label="发布位置">
  401. {getFieldDecorator('releasePosition', {
  402. rules: [ { required: false } ],
  403. initialValue: theData.releasePosition
  404. })(
  405. <Checkbox.Group>
  406. <Row>
  407. <Col span={6}><Checkbox value="0">网站首页</Checkbox></Col>
  408. <Col span={6}><Checkbox value="1">网站需求主页</Checkbox></Col>
  409. <Col span={6}><Checkbox value="2">网站需求搜索页</Checkbox></Col>
  410. <Col span={6}><Checkbox value="3">APP首页</Checkbox></Col>
  411. <Col span={6}><Checkbox value="4">APP需求首页</Checkbox></Col>
  412. <Col span={6}><Checkbox value="5">APP需求搜索页</Checkbox></Col>
  413. </Row>
  414. </Checkbox.Group>
  415. )}
  416. </FormItem>
  417. </div>
  418. <div className="clearfix">
  419. <FormItem wrapperCol={{ span: 12, offset: 3 }}>
  420. <Button className="set-submit" type="primary" htmlType="submit">
  421. 保存
  422. </Button>
  423. {this.props.data&&this.props.data.id&&<Button
  424. className="set-submit"
  425. type="ghost"
  426. onClick={(e) => {
  427. this.state.auditStatus = 1;
  428. }}
  429. htmlType="submit"
  430. >
  431. 提交审核
  432. </Button>}
  433. <Button className="set-submit" type="ghost" onClick={this.cancelFun}>
  434. 取消
  435. </Button>
  436. </FormItem>
  437. </div>
  438. </Spin>
  439. </Form>
  440. </div>
  441. )
  442. }
  443. }));
  444. export default DemandDetailForm;