<template>
  <div>
    <el-dialog
        title="添加"
        class="dialog-mini"
        width="500px"
        @close="close"
        :visible.sync="dialogformVisible"
      >
        <el-form :model="ruleForm" :rules="rules" ref="form" style="max-height: 500px;overflow: auto;" label-width="90px" size="small">
          <el-form-item label="公园名称"  prop="parkName">
            <el-input v-model="ruleForm.parkName"></el-input>
          </el-form-item>
          <el-form-item label="公园简介"  prop="description">
            <el-input v-model="ruleForm.description" type="textarea" :rows="6"></el-input>
          </el-form-item>
          <el-form-item label="视频" prop="videoUrl">
            <el-upload
                class="avatar-uploader"
                ref="upload"
                action="string"
                list-type="picture-card"
                :multiple="false"
                :show-file-list="false"
                :http-request="UploadCoverImage"
            >   
              <div style="width: 100%;height:100%;position:relative" v-if="ruleForm.videoUrl">
                <span class="closebox" @click.stop="ruleForm.videoUrl = ''">
                  <i class="el-icon-close" style="color: #fff;font-size: 18px;"></i>
                </span>
                
                <video style="width: 100%;height:100%;object-fit:fill;" :src="ruleForm.videoUrl" poster="false.png" autoplay="false" controls="controls" loop="-1">
                    <p>你的浏览器不支持video标签.</p>
               </video>
              </div>
                
              <i class="el-icon-plus avatar-uploader-icon"></i>
            </el-upload>
          </el-form-item>
          
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button size="mini" @click="close" >取 消</el-button>
          <el-button size="mini" type="primary" @click="submitBtn('form')">确 定</el-button>
        </div>
      </el-dialog>
      
      
  
  </div>      
  </template>
  
  <script>
  
  import {postMethodCommon,postMethodFiles } from "@/api/common"; 
  
  
  export default {
      name: "shujutianbao",
      components:{
         
      },
      data() {
          return {
            dialogformVisible: true,
            ruleForm:{
               id: 0,
               parkName: '',
               description: '',
               videoUrl:''
            },
            rules:{
              parkName: [
                { required: true, message: '请输入公园名称', trigger: 'blur' }
              ],
              videoUrl: [
                { required: true, message: '请上传视频', trigger: 'blur' }
              ]
            }
          }
      },
    
      created() {
           
      },
      mounted(){
          
      },
      methods: {
        close(){
          this.$emit("close")
        },
        submitBtn(formName){
          this.$refs[formName].validate((valid) => {
            if (valid) {
              this.submitClick();
            } else {
              console.log('error submit!!');
              return false;
            }
          });
        },
        UploadCoverImage(param) {
          const formData = new FormData();
          formData.append("formFiles", param.file);
           
          postMethodFiles('/ParkData/UploadImage',formData).then(res =>{
              if (res.data.code == 200) {
                this.ruleForm.videoUrl = process.env.VUE_APP_BASE_IMG_URL + '/' + res.data.result
                 
                this.$message({
                  type:"success",
                  message: res.data.message
                })
              } else {
                  this.$message({
                    type:"error",
                    message: res.data.message
                  })
              }
          }).catch( err =>{
            console.log('err',err)
          })
        },
   
        submitClick(){
          postMethodCommon("/ParkData/AddParkData",this.ruleForm).then(res =>{
            if(res.code == 200){
              this.$emit("addSuccess");
              this.$message({
                type:"success",
                message: res.message
              })
            }
          })
        },
      }
  }
  </script>
  
  <style>
  .el-dialog__headerbtn{
    top: 0 !important;
  }
   
  .avatar-uploader .el-upload {
    border: 1px dashed #d9d9d9;
    border-radius: 6px;
    cursor: pointer;
    position: relative;
    overflow: hidden;
    width: 300px;
    height: 180px;
    line-height: 180px;
  }
  .avatar-uploader .el-upload:hover {
    border-color: #409EFF;
  }
  .avatar-uploader-icon {
    font-size: 28px;
    color: #8c939d;
    width: 120px;
    height: 120px;
    line-height: 120px !important;
    text-align: center;
  }
  /* 滚动条 */
  ::-webkit-scrollbar {
    width: 4px;
    height: 4px;
  }
  ::-webkit-scrollbar-thumb {
    height: 50px;
    background-color: #eee;
    -webkit-border-radius: 10px;
  }
  .closebox{
    position: absolute;
    width: 28px;
    height: 28px;
    border-radius: 28px;
    background: #8c939d;
    line-height: 31px;
    right: 0;
    top: 0;
    z-index: 9;

  }
  </style>
  