<?php
/**
 * 视频编辑
 * $Id: media_edit_input.php,v 1.1 2020/01/03 11:18:46  Exp $
 * @author lixq
 * @package manager.public_html
 **/

?>
<div id="change">
	<p class="edit_title">视频上传</p>
	<form id="form" name="media_upload" action="media_edit_result.php" method="post" enctype="multipart/form-data">
		<input name="post_max" type="hidden" value="<?=ini_get('post_max_size')?>">
		<input name="id" type="hidden" value="<?=$id?>">
		<input name="upload_max" type="hidden" value="<?=ini_get('upload_max_filesize')?>">
	<div class="edit_content">
		<p>视频名称</p>
		<el-input v-model="title" name="title" class="input_200"></el-input><br />
		<p>视频标签</p>
		<el-input v-model="media_tags" name="media_tags" class="input_200 popselect" readonly onfocus="doCheckPopup('media_upload','media_tags','tags','pop_tag_list.php');"></el-input>
		<input type="hidden" name="tags" value="<?=$tags?>" />
		<el-button type="primary" class="height_30" @click="selectClear('media_upload', 'media_tags', 'tags');">清空</el-button>
		<el-button type="primary" class="height_30" @click="popAddTag()">添加标签</el-button>
		<br />
		<p>讲师姓名</p>
		<el-input v-model="teacher" name="teacher" class="input_200"></el-input><br />
		<p>视频封面图</p>
		<a href='javascript:void(0);' class="el-button el-button--primary blueButton">选择文件</a>
			<input id="image_file" class="myFileUpload" name="front_image" type="file" accept="image/*"/>
		<div id="img_thumbnail">
    	<img id="imgshow" height="150px" alt="学校封面图" />
		</div>
		<p>视频类型</p>
		<template>
  		<el-radio v-model="media_type" name="media_type" label="0">单个</el-radio>
  		<el-radio v-model="media_type" name="media_type" label="1">合集</el-radio>
		</template>
		<div v-if="is_course_show">
  		<p>选择合集</p>
  		<el-input v-model="course_name" name="course_name" class="input_200 popselect" readonly onfocus="doRadioPopup('media_upload','course_name','course_id','pop_media_list.php');"></el-input>
  		<input type="hidden" name="course_id" value="<?=$course_id?>" />
  		<el-button type="primary" class="height_30" @click="selectClear('media_upload', 'course_name', 'course_id');">清空</el-button>
  		<el-button type="primary" class="height_30" @click="popAddCourse()">创建合集</el-button>
  		<br />
		</div>
		<p>视频种类</p>
		<template>
  		<el-radio v-model="media_kind" name="media_kind" label="false">志愿免费</el-radio>
  		<el-radio v-model="media_kind" name="media_kind" label="true">公益收费</el-radio>
		</template>
		<div v-if="is_price_show">
  		<p>收费价格</p>
  		<el-input v-model="price" name="price" type="number" class="input_200"></el-input><br />
  		<br />
		</div>
		
		
		<br/><br/>
		<el-button type="danger" @click="submit()" class="edit_btn">编辑</el-button>
		<el-button type="danger" @click="back()" class="edit_btn">返回</el-button><br/><br/>
	</div>
	</form>
</div>

<script type="text/javascript">
	var v = new Vue({
		el:'#change',
		data:{
		  title:'<?=$title?>',
		  media_tags:'<?=$tags?>',
		  media_type:'<?=$media_type?>',
		  teacher:'<?=$teacher?>',
		  media_kind:'<?=$media_kind?>',
		  price:'<?=$price?>',
		  course_name:'<?=$course_name?>',
		  is_course_show:<?=$media_type == '0'?'false':'true'?>,
		  is_price_show:<?=$media_kind == 'true'?'true':'false'?>,
		  front_image:'<?=$front_image?>'
		},
		watch:{
		  media_type(val,oldval){
				if(val == "0"){
				  this.is_course_show = false;
				}else{
					this.is_course_show = true;
				}
		  },
		  media_kind(val,oldval){
				if(val == 'false'){
				  this.is_price_show = false;
				}else{
					this.is_price_show = true;
				}
		  }
		},
		methods:{
		  back:function(){
			  window.history.go(-1);
			},
			submit:function(){
				if(!this.title){
					this.$message({
		            type: 'error',
		            message: '请输入视频名称!'
		          });
		          return;
				}
				if($("input[name='tags']").val().length < 1){
					this.$message({
		            type: 'error',
		            message: '请选择视频标签!'
		          });
		          return;
				}
				if(this.media_type == '1' && $("input[name='course_id']").val() == '0'){
				  this.$message({
            type: 'error',
            message: '请选择合集名称!'
          });
          return;
				}
				if(this.media_kind == 'true' && !this.price){
				  this.$message({
            type: 'error',
            message: '请输入收费价格!'
          });
          return;
				}
				if(this.media_kind == 'true' && !isPointNumber(this.price)){
				  this.$message({
            type: 'error',
            message: '请输入正确格式收费价格!'
          });
          return;
				}
				
				$('#form').submit();
			},
			
		}
	})
	window.onload = function(){
  	$('#image_file').change(function(){
      var file = $('#image_file').get(0).files[0];
      if(file.type !== 'image/png'&&file.type !=='image/gif'&&file.type !=='image/jpg'&&file.type !=='image/jpeg'){
        v.$message({
          type: 'error',
          message: '上传文件只能是图片格式!'
        });
        return;
      }
			if(file.size / 1024 / 1024 > 2){
			  v.$message({
          type: 'error',
          message: '上传文件大小不能超过 2MB!'
        });
        return;
			}
      var reader = new FileReader();
      reader.readAsDataURL(file);
      reader.onload=function(e){
        $('#imgshow').get(0).src = e.target.result;
      }
      $('#img_thumbnail').css("visibility","visible");
    })
    if(<?=$front_image?1:0 ?>){
		  $('#imgshow').get(0).src = '<?=$front_image?>';
		  $('#img_thumbnail').css("visibility","visible");
		}
	}
</script>


