newForm.jsx 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385
  1. import React from 'react';
  2. import $ from 'jquery/src/ajax';
  3. import {
  4. Icon,
  5. Modal,
  6. message,
  7. Spin,
  8. Upload,
  9. Input,
  10. Button,
  11. Radio,
  12. Form,
  13. Checkbox,
  14. Cascader,
  15. Row,
  16. Col
  17. } from 'antd';
  18. import { splitUrl} from '@/tools.js';
  19. import {areaSelect } from '@/NewDicProvinceList';
  20. import Editors from '@/richTextEditors';
  21. const PicturesWall = React.createClass({
  22. getInitialState() {
  23. return {
  24. previewVisible: false,
  25. previewImage: '',
  26. fileList: [],
  27. tags: []
  28. };
  29. },
  30. handleCancel() {
  31. this.setState({ previewVisible: false });
  32. },
  33. handlePreview(file) {
  34. this.setState({
  35. previewImage: file.url || file.thumbUrl,
  36. previewVisible: true
  37. });
  38. },
  39. handleChange(info) {
  40. let fileList = info.fileList;
  41. this.setState({ fileList });
  42. this.props.fileList(fileList);
  43. },
  44. componentWillReceiveProps(nextProps) {
  45. this.state.fileList = nextProps.pictureUrl;
  46. },
  47. render() {
  48. const { previewVisible, previewImage, fileList } = this.state;
  49. const uploadButton = (
  50. <div>
  51. <Icon type="plus" />
  52. <div className="ant-upload-text">点击上传</div>
  53. </div>
  54. );
  55. return (
  56. <div className="clearfix">
  57. <Upload
  58. action={globalConfig.context + '/api/user/demand/uploadPicture'}
  59. data={{ sign: 'demand_picture'}}
  60. listType="picture-card"
  61. fileList={fileList}
  62. onPreview={this.handlePreview}
  63. onChange={this.handleChange}
  64. >
  65. {fileList.length >= 3 ? null : uploadButton}
  66. </Upload>
  67. <Modal maskClosable={false} visible={previewVisible} footer={null} onCancel={this.handleCancel}>
  68. <img alt="example" style={{ width: '100%' }} src={previewImage} />
  69. </Modal>
  70. </div>
  71. );
  72. }
  73. });
  74. const NewDetailForm = Form.create()(React.createClass({
  75. getInitialState() {
  76. return {
  77. visible: false,
  78. loading: false,
  79. auditStatus: 0,
  80. textFileList: [],
  81. videoFileList: [],
  82. pictureUrl: [],
  83. tags:[]
  84. };
  85. },
  86. loadData(id) {
  87. this.setState({
  88. loading: true
  89. });
  90. $.ajax({
  91. method: "get",
  92. dataType: "json",
  93. crossDomain: false,
  94. url: globalConfig.context + '/api/user/achievement/achievementDetail' ,
  95. data: {
  96. id: id
  97. },
  98. success: function (data) {
  99. let thisData = data.data;
  100. if (!thisData) {
  101. if (data.error && data.error.length) {
  102. message.warning(data.error[0].message);
  103. };
  104. thisData = {};
  105. };
  106. this.setState({
  107. id:thisData.id,
  108. data: thisData,
  109. publishPages:thisData.publishPages.length?thisData.publishPages:['app_achievement_list','web_achievement_list'],
  110. auditStatus:thisData.auditStatus,
  111. pictureUrl: thisData.technicalPictureUrl ? splitUrl(thisData.technicalPictureUrl, ',', globalConfig.avatarHost + '/upload') : []
  112. });
  113. }.bind(this),
  114. }).always(function () {
  115. this.setState({
  116. loading: false
  117. });
  118. }.bind(this));
  119. },
  120. getPictureUrl(e) {
  121. this.setState({ pictureUrl: e });
  122. },
  123. handleSubmit(e,index) {
  124. e.preventDefault();
  125. console.log(this.state.edit)
  126. this.props.form.validateFields((err, values) => {
  127. //url转化
  128. let thePictureUrl = [];
  129. if (this.state.pictureUrl.length) {
  130. let picArr = [];
  131. this.state.pictureUrl.map(function (item) {
  132. if ( item.response && item.response.data && item.response.data.length ){
  133. picArr.push(item.response.data);
  134. }
  135. });
  136. thePictureUrl = picArr.join(",");
  137. };
  138. if (!err) {
  139. this.setState({
  140. loading: true
  141. });
  142. $.ajax({
  143. method: "post",
  144. dataType: "json",
  145. async:true,
  146. url: this.props.data.id ? globalConfig.context + '/api/user/achievement/update' : globalConfig.context + '/api/user/achievement/apply',
  147. data: {
  148. id: this.props.data.id,
  149. name: values.name,
  150. fieldA: values.industryCategory ? values.industryCategory[0] : undefined,
  151. fieldB: values.industryCategory ? values.industryCategory[1] : undefined,
  152. dataCategory: values.dataCategory,
  153. category: values.category,
  154. technicalPictureUrl: thePictureUrl,
  155. introduction:values.introduction,
  156. maturity:values.maturity,
  157. innovation:values.innovation,
  158. transferMode:values.transferMode,
  159. auditStatus:index,
  160. patentCase: values.patentCase,
  161. teamDes: values.teamDes,
  162. parameter: values.parameter,
  163. boutique: values.boutique,
  164. isHot:values.isHot,
  165. publishPages:values.publishPages,
  166. }
  167. }).done(function (data) {
  168. this.setState({
  169. loading: false
  170. });
  171. if (!data.error.length) {
  172. message.success('操作成功!');
  173. this.setState({
  174. visible: false
  175. });
  176. this.props.handOk();
  177. } else {
  178. message.warning(data.error[0].message);
  179. }
  180. }.bind(this));
  181. }
  182. });
  183. },
  184. submission(e,index){
  185. this.handleSubmit(e,index);
  186. $.ajax({
  187. method: "POST",
  188. dataType: "json",
  189. crossDomain: false,
  190. async:true,
  191. url: globalConfig.context + "/api/user/achievement/commit",
  192. data: {
  193. id: this.state.id,
  194. }
  195. }).done(function (data) {
  196. if (!data.error.length) {
  197. this.setState({
  198. loading: false,
  199. });
  200. } else {
  201. message.warning(data.error[0].message);
  202. };
  203. }.bind(this));
  204. },
  205. cancelFun(){
  206. this.props.closeDesc();
  207. },
  208. componentWillMount() {
  209. if (this.props.data.id) {
  210. this.loadData(this.props.data.id);
  211. } else {
  212. this.state.data = {};
  213. this.state.tags = [];
  214. this.setState({
  215. publishPages:['app_achievement_list','web_achievement_list']
  216. })
  217. };
  218. },
  219. componentWillReceiveProps(nextProps) {
  220. if (!this.props.visible && nextProps.visible) {
  221. this.state.textFileList = [];
  222. this.state.videoFileList = [];
  223. if (nextProps.data.id) {
  224. this.loadData(nextProps.data.id);
  225. } else {
  226. this.state.data = {};
  227. this.state.pictureUrl = [];
  228. this.state.theData={};
  229. this.setState({
  230. publishPages:['app_achievement_list','web_achievement_list']
  231. })
  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. this.state.edit ={};
  245. return (
  246. <div className='login'>
  247. <Form layout="horizontal" onSubmit={(e)=>{this.handleSubmit(e,0)}} id="demand-form">
  248. <Spin spinning={this.state.loading}>
  249. <div className="clearfix">
  250. <FormItem className="half-item" {...formItemLayout} label="标题">
  251. {getFieldDecorator('name', {
  252. rules: [ { required: true, message: '此项为必填项!' } ],
  253. initialValue: theData.name
  254. })(<Input placeholder="请输入您的新闻标题" />)}
  255. </FormItem>
  256. </div>
  257. <div className="clearfix">
  258. <FormItem className="half-item" {...formItemLayout} label="热门">
  259. {getFieldDecorator('hot', {
  260. rules: [ { required: true, message: '此项为必填项!' } ],
  261. initialValue: theData.hot
  262. })(
  263. <Radio.Group>
  264. <Radio value={0}>否</Radio>
  265. <Radio value={1}>是</Radio>
  266. </Radio.Group>
  267. )}
  268. </FormItem>
  269. <FormItem className="half-item" {...formItemLayout} label="新闻来源">
  270. {getFieldDecorator('name', {
  271. rules: [ { required: true, message: '此项为必填项!' } ],
  272. initialValue: theData.name
  273. })(<Input placeholder="请输入新闻来源" />)}
  274. </FormItem>
  275. <FormItem className="half-item" {...formItemLayout} label="来源链接">
  276. {getFieldDecorator('url', {
  277. initialValue: theData.url
  278. })(<Input placeholder="请输入新闻来源链接" />)}
  279. </FormItem>
  280. <FormItem className="half-item"
  281. {...formItemLayout}
  282. label="省-市-区"
  283. >
  284. {getFieldDecorator('ProvinceCity', {
  285. rules: [ { required: true, message: '此项为必填项!' } ],
  286. initialValue: theData.ProvinceCity
  287. })(
  288. <Cascader options={areaSelect()} placeholder="选择城市" />
  289. )}
  290. </FormItem>
  291. </div>
  292. <div className="clearfix">
  293. <FormItem labelCol={{ span: 3 }} wrapperCol={{ span: 18 }} label="新闻图片">
  294. <PicturesWall
  295. fileList={this.getPictureUrl}
  296. pictureUrl={this.state.pictureUrl}
  297. visible={this.props.visible}
  298. />
  299. </FormItem>
  300. </div>
  301. <div className="clearfix">
  302. <FormItem labelCol={{ span: 3 }} wrapperCol={{ span: 18 }} label="新闻简介">
  303. {getFieldDecorator('introduction', {
  304. rules: [ { required: true, message: '此项为必填项!' } ],
  305. initialValue: theData.introduction
  306. })(<Input type="textarea" rows={4} placeholder="输入新闻简介" />)}
  307. </FormItem>
  308. </div>
  309. <div className="clearfix">
  310. <FormItem labelCol={{ span: 3 }} wrapperCol={{ span: 18 }} label={<span><i style={{color:"red",fontSize:14}}> * </i>新闻正文</span>}>
  311. <Editors textContent={this.state.edit.content}
  312. uploadUrl={'/api/admin/news/upload'}
  313. uploadSign={'news_content_picture'}
  314. handleRichText={(value) => { this.state.edit.content = value; }}
  315. visible={this.state.visible} />
  316. </FormItem>
  317. </div>
  318. {theData.auditInfo&&<div className="clearfix">
  319. <FormItem labelCol={{ span: 3 }} wrapperCol={{ span: 18 }} label="审核信息">
  320. <span>{theData.auditInfo}</span>
  321. </FormItem>
  322. </div>}
  323. {theData.createTime&&<div className="clearfix">
  324. <FormItem labelCol={{ span: 3 }} wrapperCol={{ span: 18 }} label="发布时间">
  325. <span>{theData.createTime}</span>
  326. </FormItem>
  327. </div>}
  328. <div className="clearfix">
  329. <FormItem className="full-item"
  330. labelCol={{ span: 3 }}
  331. wrapperCol={{ span: 18 }} label="发布位置">
  332. {getFieldDecorator('publishPages', {
  333. rules: [ { required: false } ],
  334. initialValue: this.state.publishPages
  335. })(
  336. <Checkbox.Group>
  337. <Row>
  338. <Col span={6}><Checkbox value="web_index">网站新闻首页</Checkbox></Col>
  339. <Col span={6}><Checkbox value="web_achievement_main">网站科技服务主页</Checkbox></Col>
  340. <Col span={6}><Checkbox value="web_achievement_list" disabled>app政策主页</Checkbox></Col>
  341. <Col span={6}><Checkbox value="app_index">APP科技服务首页</Checkbox></Col>
  342. </Row>
  343. </Checkbox.Group>
  344. )}
  345. </FormItem>
  346. </div>
  347. <div className="clearfix">
  348. <FormItem wrapperCol={{ span: 12, offset: 3 }}>
  349. {this.props.data&&!this.props.data.id&&<Button className="set-submit" type="primary" htmlType="submit">
  350. 保存草稿
  351. </Button>}
  352. <Button
  353. className="set-submit"
  354. type="ghost"
  355. onClick={(e) => {
  356. if(this.props.data.id){
  357. this.submission(e,1)
  358. }else{
  359. this.handleSubmit(e,1)
  360. }
  361. }}
  362. >
  363. 发布新闻
  364. </Button>
  365. <Button className="set-submit" type="ghost" onClick={this.cancelFun}>
  366. 取消
  367. </Button>
  368. </FormItem>
  369. </div>
  370. </Spin>
  371. </Form>
  372. </div>
  373. )
  374. }
  375. }));
  376. export default NewDetailForm;