videoForm.jsx 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257
  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. Form,
  12. Select
  13. } from 'antd';
  14. import { videoType } from '@/dataDic.js';
  15. import { getVideoType} from '@/tools.js';
  16. import VideoComponent from '@/crop/video';
  17. const NewDetailForm = Form.create()(React.createClass({
  18. getInitialState() {
  19. return {
  20. visible: false,
  21. loading: false,
  22. auditStatus: 0,
  23. textFileList: [],
  24. pictureUrl: [],
  25. vedioUrl:[]
  26. };
  27. },
  28. loadData(id) {
  29. this.setState({
  30. loading: true
  31. });
  32. $.ajax({
  33. method: "get",
  34. dataType: "json",
  35. crossDomain: false,
  36. url: globalConfig.context + '/api/admin/policy/detail' ,
  37. data: {
  38. id: id
  39. },
  40. success: function (data) {
  41. let thisData = data.data,provice=[];
  42. if (!thisData) {
  43. if (data.error && data.error.length) {
  44. message.warning(data.error[0].message);
  45. };
  46. thisData = {};
  47. };
  48. let proArr=[];
  49. this.setState({
  50. id:thisData.id,
  51. data: thisData,
  52. auditStatus:thisData.auditStatus,
  53. videoUrl:[],
  54. pictureUrl: thisData.titleImg ? splitUrl(thisData.titleImg, ',', globalConfig.avatarHost + '/upload') : []
  55. });
  56. }.bind(this),
  57. }).always(function () {
  58. this.setState({
  59. loading: false
  60. });
  61. }.bind(this));
  62. },
  63. getPictureUrl(e) {
  64. this.setState({ pictureUrl: e });
  65. },
  66. handleSubmit(e,index) {
  67. e.preventDefault();
  68. this.props.form.validateFields((err, values) => {
  69. //url转化
  70. let thePictureUrl = [];
  71. if (this.state.pictureUrl.length) {
  72. let picArr = [];
  73. this.state.pictureUrl.map(function (item) {
  74. if ( item.response && item.response.data && item.response.data.length ){
  75. picArr.push(item.response.data);
  76. }
  77. });
  78. thePictureUrl = picArr.join(",");
  79. };
  80. if (!err) {
  81. this.setState({
  82. loading: true
  83. });
  84. $.ajax({
  85. method: "post",
  86. dataType: "json",
  87. async:true,
  88. url: this.props.data.id ? globalConfig.context + '/api/admin/policy/update' : globalConfig.context + '/api/admin/policy/apply',
  89. data: {
  90. id: this.props.data.id,
  91. type:0,
  92. title: values.title,
  93. author: values.author,
  94. titleImg: thePictureUrl.length?thePictureUrl:'',
  95. content:this.state.edit.content,
  96. hot:values.hot,
  97. source:values.source,
  98. sourceUrl:values.sourceUrl,
  99. keyword:values.keyword,
  100. auditStatus:index,
  101. summary: values.summary,
  102. province: (values.ProvinceCity)[0],
  103. publishPages:publishPages
  104. }
  105. }).done(function (data) {
  106. this.setState({
  107. loading: false
  108. });
  109. if (!data.error.length) {
  110. message.success('操作成功!');
  111. this.setState({
  112. visible: false
  113. });
  114. this.props.handOk();
  115. } else {
  116. message.warning(data.error[0].message);
  117. }
  118. }.bind(this));
  119. }
  120. });
  121. },
  122. cancelFun(){
  123. this.state.edit={};
  124. this.props.closeDesc();
  125. },
  126. componentWillMount() {
  127. if (this.props.data.id) {
  128. this.loadData(this.props.data.id);
  129. } else {
  130. this.state.data = {};
  131. this.state.pictureUrl = [];
  132. this.state.videoUrl=[];
  133. };
  134. },
  135. componentWillReceiveProps(nextProps) {
  136. if (!this.props.visible && nextProps.visible) {
  137. if (nextProps.data.id) {
  138. this.loadData(nextProps.data.id);
  139. } else {
  140. this.state.data = {};
  141. this.state.pictureUrl = [];
  142. this.state.theData={};
  143. this.state.videoUrl=[];
  144. };
  145. this.props.form.resetFields();
  146. };
  147. },
  148. render() {
  149. const theData = this.state.data || {};
  150. const { getFieldDecorator } = this.props.form;
  151. const FormItem = Form.Item
  152. const formItemLayout = {
  153. labelCol: { span: 6 },
  154. wrapperCol: { span: 12 },
  155. };
  156. const formItemLayouts = {
  157. labelCol: { span: 3 },
  158. wrapperCol: { span: 18 },
  159. };
  160. return (
  161. <div className='login'>
  162. <Form layout="horizontal" onSubmit={(e)=>{this.handleSubmit(e,0)}} id="demand-form">
  163. <Spin spinning={this.state.loading}>
  164. <div className="clearfix">
  165. <FormItem className="half-item" {...formItemLayout} label="视频名称">
  166. {getFieldDecorator('title', {
  167. rules: [ { required: true, message: '此项为必填项!' } ],
  168. initialValue: theData.title
  169. })(<Input placeholder="请输入视频的名称" />)}
  170. </FormItem>
  171. <FormItem className="half-item" {...formItemLayout} label="视频类型">
  172. {getFieldDecorator('title1', {
  173. rules: [ { required: true, message: '此项为必填项!' } ],
  174. initialValue: theData.title1
  175. })(<Select placeholder="请选择视频类型">
  176. {videoType.map(item=>{
  177. return <Select.Option value={item.value}>{item.key}</Select.Option>
  178. })}
  179. </Select>)}
  180. </FormItem>
  181. </div>
  182. <div className="clearfix">
  183. <FormItem className="half-item" {...formItemLayout} label="视频文件">
  184. < VideoComponent
  185. fileList={(e)=>{this.setState({videoUrl:e})}}
  186. dataUrl={{
  187. url:'/api/user/demand/uploadPicture',
  188. keyWord:'demand_picture',
  189. type:'video',
  190. page:1
  191. }}
  192. videoUrl={this.state.videoUrl}
  193. visible={this.props.visible}
  194. />
  195. </FormItem>
  196. <FormItem className="half-item" {...formItemLayout} label="封面图片">
  197. <VideoComponent
  198. fileList={this.getPictureUrl}
  199. videoUrl={this.state.pictureUrl}
  200. dataUrl={{
  201. url:'/api/user/demand/uploadPicture',
  202. keyWord:'demand_picture',
  203. type:'image',
  204. page:1
  205. }}
  206. visible={this.props.visible}
  207. />
  208. </FormItem>
  209. </div>
  210. <div className="clearfix">
  211. <FormItem labelCol={{ span: 3 }} wrapperCol={{ span: 18 }} label="视频简介">
  212. {getFieldDecorator('summary', {
  213. initialValue: theData.summary
  214. })(<Input type="textarea" rows={4} placeholder="输入视频简介" />)}
  215. </FormItem>
  216. </div>
  217. <div className="clearfix">
  218. <FormItem className="half-item" {...formItemLayout} label="发布人">
  219. <span>{theData.releaseStatus?'已发布':'管理员'}</span>
  220. </FormItem>
  221. {theData.createTime&&<FormItem className="half-item" {...formItemLayout} label="发布状态">
  222. <span>{theData.releaseStatus?'已发布':'未发布'}</span>
  223. </FormItem>}
  224. </div>
  225. <div className="clearfix">
  226. <FormItem wrapperCol={{ span: 12, offset: 3 }}>
  227. <Button className="set-submit" type="primary" htmlType="submit">
  228. 保存草稿
  229. </Button>
  230. <Button
  231. className="set-submit"
  232. type="ghost"
  233. onClick={(e) => {
  234. this.handleSubmit(e,2)
  235. }}
  236. >
  237. 发布视频
  238. </Button>
  239. <Button className="set-submit" type="ghost" onClick={this.cancelFun}>
  240. 取消
  241. </Button>
  242. </FormItem>
  243. </div>
  244. </Spin>
  245. </Form>
  246. </div>
  247. )
  248. }
  249. }));
  250. export default NewDetailForm;