123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253 |
- import React from 'react';
- import $ from 'jquery/src/ajax';
- import {
- Icon,
- Modal,
- message,
- Spin,
- Upload,
- Input,
- Button,
- Form,
- Select
- } from 'antd';
- import { videoType } from '@/dataDic.js';
- import { getVideoType} from '@/tools.js';
- import VideoComponent from '@/crop/video';
- import Crop from '@/crop/cropBlock';
- const NewDetailForm = Form.create()(React.createClass({
- getInitialState() {
- return {
- visible: false,
- loading: false,
- auditStatus: 0,
- textFileList: [],
- videoImg: [],
- vedioUrl:[]
- };
- },
- loadData(id) {
- this.setState({
- loading: true
- });
- $.ajax({
- method: "get",
- dataType: "json",
- crossDomain: false,
- url: globalConfig.context + '/api/admin/policy/detail' ,
- data: {
- id: id
- },
- success: function (data) {
- let thisData = data.data,provice=[];
- if (!thisData) {
- if (data.error && data.error.length) {
- message.warning(data.error[0].message);
- };
- thisData = {};
- };
- let proArr=[];
- this.setState({
- id:thisData.id,
- data: thisData,
- auditStatus:thisData.auditStatus,
- videoUrl:[],
- videoImg: thisData.titleImg ? splitUrl(thisData.titleImg, ',', globalConfig.avatarHost + '/upload') : []
- });
- }.bind(this),
- }).always(function () {
- this.setState({
- loading: false
- });
- }.bind(this));
- },
- getPictureUrl(e) {
- this.setState({ pictureUrl: e });
- },
- handleSubmit(e,index) {
- e.preventDefault();
- this.props.form.validateFields((err, values) => {
- //url转化
- let thePictureUrl = [];
- if (this.state.pictureUrl.length) {
- let picArr = [];
- this.state.pictureUrl.map(function (item) {
- if ( item.response && item.response.data && item.response.data.length ){
- picArr.push(item.response.data);
- }
- });
- thePictureUrl = picArr.join(",");
- };
- if (!err) {
- this.setState({
- loading: true
- });
- $.ajax({
- method: "post",
- dataType: "json",
- async:true,
- url: this.props.data.id ? globalConfig.context + '/api/admin/policy/update' : globalConfig.context + '/api/admin/policy/apply',
- data: {
- id: this.props.data.id,
- type:0,
- title: values.title,
- author: values.author,
- titleImg: thePictureUrl.length?thePictureUrl:'',
- content:this.state.edit.content,
- hot:values.hot,
- source:values.source,
- sourceUrl:values.sourceUrl,
- keyword:values.keyword,
- auditStatus:index,
- summary: values.summary,
- }
- }).done(function (data) {
- this.setState({
- loading: false
- });
- if (!data.error.length) {
- message.success('操作成功!');
- this.setState({
- visible: false
- });
- this.props.handOk();
- } else {
- message.warning(data.error[0].message);
- }
- }.bind(this));
- }
- });
- },
- cancelFun(){
- this.state.edit={};
- this.props.closeDesc();
- },
- componentWillMount() {
- if (this.props.data.id) {
- this.loadData(this.props.data.id);
- } else {
- this.state.data = {};
- this.state.videoImg = [];
- this.state.videoUrl=[];
- };
- },
- componentWillReceiveProps(nextProps) {
- if (!this.props.visible && nextProps.visible) {
- if (nextProps.data.id) {
- this.loadData(nextProps.data.id);
- } else {
- this.state.data = {};
- this.state.videoImg = [];
- this.state.theData={};
- this.state.videoUrl=[];
- };
- this.props.form.resetFields();
- };
- },
- render() {
- const theData = this.state.data || {};
- const { getFieldDecorator } = this.props.form;
- const FormItem = Form.Item
- const formItemLayout = {
- labelCol: { span: 6 },
- wrapperCol: { span: 12 },
- };
- const formItemLayouts = {
- labelCol: { span: 3 },
- wrapperCol: { span: 18 },
- };
- return (
- <div className='login'>
- <Form layout="horizontal" onSubmit={(e)=>{this.handleSubmit(e,0)}} id="demand-form">
- <Spin spinning={this.state.loading}>
- <div className="clearfix">
- <FormItem className="half-item" {...formItemLayout} label="视频名称">
- {getFieldDecorator('title', {
- rules: [ { required: true, message: '此项为必填项!' } ],
- initialValue: theData.title
- })(<Input placeholder="请输入视频的名称" />)}
- </FormItem>
- <FormItem className="half-item" {...formItemLayout} label="视频类型">
- {getFieldDecorator('title1', {
- rules: [ { required: true, message: '此项为必填项!' } ],
- initialValue: theData.title1
- })(<Select placeholder="请选择视频类型">
- {videoType.map(item=>{
- return <Select.Option value={item.value}>{item.key}</Select.Option>
- })}
- </Select>)}
- </FormItem>
- </div>
- <div className="clearfix">
- <FormItem className="half-item" {...formItemLayout} label="视频文件">
- < VideoComponent
- fileList={(e)=>{this.setState({videoUrl:e})}}
- dataUrl={{
- url:'/api/user/demand/uploadPicture',
- keyWord:'demand_picture',
- type:'video',
- page:1
- }}
- videoUrl={this.state.videoUrl}
- visible={this.props.visible}
- />
- </FormItem>
- <FormItem className="half-item" {...formItemLayout} label="封面图片">
- <Crop
- getAllImg={(e)=>{this.setState({videoImg:e})}}
- number = {1}
- aspectRatio = {1/1}
- url ={globalConfig.context + '/api/user/uploadPicture64'}
- uploadData = {{sign:'user_picture'}}
- urlArr = {this.state.videoImg}
- />
- </FormItem>
- </div>
- <div className="clearfix">
- <FormItem labelCol={{ span: 3 }} wrapperCol={{ span: 18 }} label="视频简介">
- {getFieldDecorator('summary', {
- initialValue: theData.summary
- })(<Input type="textarea" rows={4} placeholder="输入视频简介" />)}
- </FormItem>
- </div>
- <div className="clearfix">
- <FormItem className="half-item" {...formItemLayout} label="发布人">
- <span>{theData.releaseStatus?'已发布':'管理员'}</span>
- </FormItem>
- {theData.createTime&&<FormItem className="half-item" {...formItemLayout} label="发布状态">
- <span>{theData.releaseStatus?'已发布':'未发布'}</span>
- </FormItem>}
- </div>
- <div className="clearfix">
- <FormItem wrapperCol={{ span: 12, offset: 3 }}>
- <Button className="set-submit" type="primary" htmlType="submit">
- 保存草稿
- </Button>
- <Button
- className="set-submit"
- type="ghost"
- onClick={(e) => {
- this.handleSubmit(e,2)
- }}
- >
- 发布视频
- </Button>
- <Button className="set-submit" type="ghost" onClick={this.cancelFun}>
- 取消
- </Button>
- </FormItem>
- </div>
- </Spin>
- </Form>
- </div>
- )
- }
- }));
- export default NewDetailForm;
|