proForm.jsx 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292
  1. import React from 'react';
  2. import $ from 'jquery/src/ajax';
  3. import {
  4. message,
  5. Spin,
  6. Input,
  7. Button,
  8. Radio,
  9. Form,
  10. Select,
  11. } from 'antd';
  12. import {productType} from '@/dataDic.js';
  13. import Editors from '@/richTextEditors';
  14. import Crop from '@/crop/cropBlock';
  15. import KeyWordTagGroup from '@/crop/keyword';
  16. const NewDetailForm = Form.create()(React.createClass({
  17. getInitialState() {
  18. return {
  19. visible: false,
  20. loading: false,
  21. auditStatus: 0,
  22. textFileList: [],
  23. videoFileList: [],
  24. pictureUrl: [],
  25. tags:[],
  26. edit:{},
  27. edits:{}
  28. };
  29. },
  30. loadData(id) {
  31. this.setState({
  32. loading: true
  33. });
  34. $.ajax({
  35. method: "get",
  36. dataType: "json",
  37. crossDomain: false,
  38. url: globalConfig.context + '/api/admin/news/detail' ,
  39. data: {
  40. id: id
  41. },
  42. success: function (data) {
  43. let thisData = data.data;
  44. if (!thisData) {
  45. if (data.error && data.error.length) {
  46. message.warning(data.error[0].message);
  47. };
  48. thisData = {};
  49. };
  50. this.setState({
  51. type:thisData.type,
  52. id:thisData.id,
  53. data: thisData,
  54. tags:thisData.keywords||[],
  55. auditStatus:thisData.auditStatus,
  56. edit:thisData.content,
  57. pictureUrl: thisData.coverUrl ? thisData.coverUrl.split(',') : []
  58. });
  59. }.bind(this),
  60. }).always(function () {
  61. this.setState({
  62. loading: false
  63. });
  64. }.bind(this));
  65. },
  66. handleSubmit(e,index) {
  67. e.preventDefault();
  68. this.props.form.validateFields((err, values) => {
  69. if (!this.state.pictureUrl.length) {
  70. message.warning('请上传专栏图片!');
  71. return false;
  72. };
  73. if((this.state.edit)==undefined||!this.state.edit||(this.state.edit)=='<p><br></p>'){
  74. message.warning('请填写专栏正文');
  75. return false;
  76. }
  77. if (!err) {
  78. this.setState({
  79. loading: true
  80. });
  81. $.ajax({
  82. method: "post",
  83. dataType: "json",
  84. async:true,
  85. url: this.props.data.id ? globalConfig.context + '/api/admin/news/updateNews' : globalConfig.context + '/api/admin/news/apply',
  86. data: {
  87. id: this.props.data.id,
  88. title: values.title,
  89. author: values.author,
  90. titleImg: this.state.pictureUrl.join(','),
  91. content:this.state.edit,
  92. hot:values.hot,
  93. source:values.source,
  94. sourceUrl:values.sourceUrl,
  95. keyword:values.keyword,
  96. auditStatus:index,
  97. keyword: this.state.tags ? this.state.tags.join(",") : '',
  98. keywords: this.state.tags,
  99. summary: values.summary,
  100. }
  101. }).done(function (data) {
  102. this.setState({
  103. loading: false
  104. });
  105. if (!data.error.length) {
  106. message.success('操作成功!');
  107. this.setState({
  108. visible: false
  109. });
  110. this.props.handOk();
  111. } else {
  112. message.warning(data.error[0].message);
  113. }
  114. }.bind(this));
  115. }
  116. });
  117. },
  118. cancelFun(){
  119. this.props.closeDesc();
  120. },
  121. componentWillMount() {
  122. if (this.props.data.id) {
  123. this.loadData(this.props.data.id);
  124. } else {
  125. this.state.visible=true;
  126. this.state.data = {};
  127. this.state.tags=[];
  128. this.state.edit='<p><br></p>';
  129. this.state.pictureUrl = [];
  130. };
  131. },
  132. componentWillReceiveProps(nextProps) {
  133. if (!this.props.visible && nextProps.visible) {
  134. this.state.textFileList = [];
  135. this.state.videoFileList = [];
  136. if (nextProps.data.id) {
  137. this.loadData(nextProps.data.id);
  138. } else {
  139. this.state.visible=true;
  140. this.state.data = {};
  141. this.state.tags=[];
  142. this.state.edit='<p><br></p>';
  143. this.state.pictureUrl = [];
  144. this.state.theData={};
  145. };
  146. this.props.form.resetFields();
  147. };
  148. },
  149. render() {
  150. const theData = this.state.data || {};
  151. const { getFieldDecorator } = this.props.form;
  152. const FormItem = Form.Item
  153. const formItemLayout = {
  154. labelCol: { span: 6 },
  155. wrapperCol: { span: 12 },
  156. };
  157. return (
  158. <div className='login'>
  159. <Form layout="horizontal" onSubmit={(e)=>{this.handleSubmit(e,0)}} id="demand-form">
  160. <Spin spinning={this.state.loading}>
  161. <div className="clearfix">
  162. <FormItem className="half-item" {...formItemLayout} label="标题">
  163. {getFieldDecorator('title', {
  164. rules: [ { required: true, message: '此项为必填项!' } ],
  165. initialValue: theData.title
  166. })(<Input placeholder="请输入您的专栏标题" />)}
  167. </FormItem>
  168. <FormItem className="half-item" {...formItemLayout} label="产品类型">
  169. {getFieldDecorator('productType', {
  170. rules: [ { required: true, message: '此项为必填项!' } ],
  171. initialValue: theData.productType!=undefined?String(theData.type):theData.type
  172. })(
  173. <Select placeholder="产品类型">
  174. {
  175. productType.map(item=>{
  176. return <Select.Option value={item.value}>{item.key}</Select.Option>
  177. })
  178. }
  179. </Select>
  180. )}
  181. </FormItem>
  182. <FormItem className="half-item" {...formItemLayout} label="专栏来源">
  183. {getFieldDecorator('source', {
  184. rules: [ { required: true, message: '此项为必填项!' } ],
  185. initialValue: theData.source
  186. })(<Input placeholder="请输入来源" />)}
  187. </FormItem>
  188. <FormItem className="half-item" {...formItemLayout} label="来源链接">
  189. {getFieldDecorator('sourceUrl', {
  190. initialValue: theData.sourceUrl
  191. })(<Input placeholder="请输入来源链接" />)}
  192. </FormItem>
  193. </div>
  194. <div className="clearfix">
  195. <FormItem labelCol={{ span: 3 }} wrapperCol={{ span: 18 }} label="关键字">
  196. {getFieldDecorator('keyword', {
  197. initialValue: theData.keyword
  198. })(<KeyWordTagGroup
  199. keyWordArr={this.state.tags}
  200. tagsArr={(e)=>{this.setState({tags:e})}}
  201. />)}
  202. </FormItem>
  203. </div>
  204. <div className="clearfix">
  205. <FormItem labelCol={{ span: 3 }} wrapperCol={{ span: 18 }} label="专栏图片">
  206. <Crop
  207. getAllImg={(e)=>{this.setState({pictureUrl:e})}}
  208. number = {1}
  209. aspectRatio = {2/1}
  210. url ={globalConfig.context + '/api/admin/video/upload'}
  211. uploadData = {{sign:'video_cover'}}
  212. urlArr = {this.state.pictureUrl}
  213. />
  214. </FormItem>
  215. </div>
  216. <div className="clearfix">
  217. <FormItem labelCol={{ span: 3 }} wrapperCol={{ span: 18 }} label="简介">
  218. {getFieldDecorator('summary', {
  219. rules: [ { required: true, message: '此项为必填项!' } ],
  220. initialValue: theData.summary
  221. })(<Input type="textarea" rows={4} placeholder="输入简介" />)}
  222. </FormItem>
  223. </div>
  224. <div className="clearfix">
  225. <FormItem labelCol={{ span: 3 }} wrapperCol={{ span: 18 }} label={<span><i style={{color:"red",fontSize:14}}> * </i>专栏正文</span>}>
  226. <Editors textContent={this.state.edit}
  227. uploadUrl={'/api/user/demand/uploadPicture'}
  228. uploadSign={'demand_picture'}
  229. handleRichText={(value) => { this.state.edit = value; }}
  230. visible={this.state.visible} />
  231. </FormItem>
  232. </div>
  233. <div className="clearfix">
  234. <FormItem labelCol={{ span: 3 }} wrapperCol={{ span: 18 }} label="是否发布">
  235. <span>{theData.releaseStatus?'已发布':'未发布'}</span>
  236. </FormItem>
  237. </div>
  238. <div className="clearfix">
  239. <FormItem className="half-item" {...formItemLayout} label="置顶">
  240. {getFieldDecorator('hot', {
  241. initialValue: theData.hot
  242. })(
  243. <Radio.Group>
  244. <Radio value={0}>否</Radio>
  245. <Radio value={1}>是</Radio>
  246. </Radio.Group>
  247. )}
  248. </FormItem>
  249. <FormItem className="half-item" {...formItemLayout} label="推荐">
  250. {getFieldDecorator('hot1', {
  251. initialValue: theData.hot1
  252. })(
  253. <Radio.Group>
  254. <Radio value={0}>否</Radio>
  255. <Radio value={1}>是</Radio>
  256. </Radio.Group>
  257. )}
  258. </FormItem>
  259. </div>
  260. <div className="clearfix">
  261. <FormItem wrapperCol={{ span: 12, offset: 3 }}>
  262. <Button className="set-submit" type="primary" htmlType="submit">
  263. 保存草稿
  264. </Button>
  265. <Button
  266. className="set-submit"
  267. type="ghost"
  268. onClick={(e) => {
  269. this.handleSubmit(e,2)
  270. }}
  271. >
  272. 发布新闻
  273. </Button>
  274. <Button className="set-submit" type="ghost" onClick={this.cancelFun}>
  275. 取消
  276. </Button>
  277. </FormItem>
  278. </div>
  279. </Spin>
  280. </Form>
  281. </div>
  282. )
  283. }
  284. }));
  285. export default NewDetailForm;