<template>
  <div class="projectClass">
    <template v-if="videoIsShowAdd">
      <div class="head-title">
        视频
        <el-button @click="videoIsShowAdd=false,clearMsg()" style="float:right;margin-top: -5px;" size="small" type="primary">
          添加视频
        </el-button>
      </div>
      <div class="content">
        <div>
          <div class="searchInput">
            <el-input style="display:inline-block;width:225px;height:30px" placeholder="请输入搜索内容" v-model="msg.Title"
              size="small" clearable @keyup.enter.native="msg.pageIndex=1,getList()">
            </el-input>
            <span class="el-icon-search" style="color:#979dad;font-size:14px;position:relative;top:1px"
              @click="msg.pageIndex=1,getList()"> </span>
          </div>
        </div>
        <el-table :data="dataList" v-loading="loading" border style="width: 100%;margin:20px 0">
          <el-table-column prop="Id" label="ID" width="100">
          </el-table-column>
          <el-table-column prop="Title" label="标题">
          </el-table-column>
          <el-table-column prop="SortNum" label="排序" width="250">
          </el-table-column>
          <el-table-column prop="VedioUrl" label="封面" width="200">
            <template slot-scope="scope">
              <img v-if="scope.row.VedioCoverImg" :src="getIconLink(scope.row.VedioCoverImg)" style="width:150px;height:150px;" />
            </template>
          </el-table-column>
          <el-table-column label="操作">
            <template slot-scope="scope">
              <img @click="EditprojectClass(scope.row)" class="operatImg" src="../../assets/img/userman/edit.png"
                alt="">
              <img @click="RemoveprojectClass(scope.row)" class="operatImg" src="../../assets/img/userman/del.png"
                alt="">
            </template>
          </el-table-column>
        </el-table>
        <el-pagination style="text-align:right" background @current-change="handleCurrentChange"
          :page-size="msg.pageSize" layout="prev, pager, next" :total="total">
        </el-pagination>
      </div>
    </template>
    <template v-else>
      <div class="head-title">
        <span @click="videoIsShowAdd=true" style="color:rgb(64, 158, 255);cursor:pointer;">视频</span><span
          style="margin:0 9px;color:#C0C4CC">/</span><span>视频编辑</span>
      </div>
      <div class="content">
        <div class="projectClass_condiv">
          <el-form :model="addMsg" :rules="rules" ref="addMsg" label-width="120px" style="padding:0 20px;">
            <el-form-item label="标题" prop="Title">
              <el-input v-model="addMsg.Title" size="small" maxlength="50" />
            </el-form-item>
            <el-form-item label="视频来源">
              <el-radio-group v-model="addMsg.SourceType">
                <el-radio :label="1">源地址</el-radio>
                <el-radio :label="2">腾讯</el-radio>
              </el-radio-group>
            </el-form-item>
            <el-form-item label="视频链接">
              <el-input placeholder="请输入链接" v-model="addMsg.VedioUrl" size="small">
                <el-button slot="append" @click="changeState1=true">选择文件</el-button>
              </el-input>
              <el-link class="box-grow-0" type="primary" style="font-size:12px" v-if='addMsg.VedioUrl'
                :underline="false" target="_blank" :href="addMsg.VedioUrl">视频预览
              </el-link>
            </el-form-item>
            <el-form-item label="封面图" prop="VedioCoverImg">
              <el-tooltip class="item" effect="dark" content="建议尺寸:750 * 400" placement="top">
                <el-button size="mini" @click="choicImg=true">选择图片</el-button>
              </el-tooltip>
              <div class="customize-share-title">
                <div class="zk_pic_box" flex="main:center cross:center"
                  :style="{backgroundImage:'url(' + getIconLink(addMsg.VedioCoverImg) + ')'}">
                  <i v-if="addMsg.VedioCoverImg==''" class="el-icon-picture-outline"></i>
                </div>
              </div>
            </el-form-item>
            <el-form-item label="排序">
              <el-input v-model="addMsg.SortNum" @keyup.native="checkInteger(addMsg,'SortNum')" size="small" maxlength="4" />
            </el-form-item>
            <el-form-item label="详情介绍">
              <el-input type="textarea" v-model="addMsg.VedioIntro" :rows="4" maxlength="200" />
            </el-form-item>
          </el-form>
        </div>
      </div>
      <el-button size="small" style="margin-top:20px;padding:9px 25px;" type="primary" @click="submitform('addMsg')">保存
      </el-button>
    </template>
    <!-- 选择图片文件 -->
    <el-dialog title="选择文件" :visible.sync="choicImg" width="1240px">
      <ChooseImg @SelectId="SelectId"></ChooseImg>
    </el-dialog>
    <!-- 选择视频 -->
    <el-dialog title="选择文件" :visible.sync="changeState1" width="1240px">
      <Choosevideo  @Selectvideo="Selectvideo"></Choosevideo>   
    </el-dialog>
  </div>
</template>
<script>
  import ChooseImg from "@/components/global/ChooseImg.vue";
  import Choosevideo from "@/components/global/Choosevideo.vue";
  export default {
    components: {
      ChooseImg,
      Choosevideo
    },
    data() {
      return {
        //是否线下链接弹窗
        loading: false,
        //选择视频
        changeState1:false,
        dataList: [],
        msg: {
          pageIndex: 1,
          pageSize: 15,
          Title: ""
        },
        total: 0,
        videoIsShowAdd: true,
        choicImg: false,
        addMsg: {
          Id: 0, //视频编号
          Title: '', //视频标题
          SourceType: 1, //视频来源(1-源地址，2-腾讯)
          VedioUrl: '', //视频链接
          VedioCoverImg: '', //封面图
          SortNum: '', //排序
          VedioIntro: '' //视频详情介绍
        },
        rules: {
          Title: [{
            required: true,
            message: '标题不能为空',
            trigger: 'change'
          }],
          VedioCoverImg: [{
            required: true,
            message: '封面图',
            trigger: 'change'
          }]
        },

      };
    },
    created() {

    },
    methods: {
      handleCurrentChange(val) {
        this.msg.pageIndex = val;
        this.getList();
      },
      //选择视频
      Selectvideo(val){
        this.addMsg.VedioUrl=val.Path;
        this.changeState1=false; 
      },
      getList() {
        this.apipost("/api/MContent/GetVideoPageList", this.msg, res => {
          if (res.data.resultCode == 1) {
            this.dataList = res.data.data.pageData;
            this.total = res.data.data.count;
          } else {
            this.Info(res.data.message);
          }
        })
      },
      submitform(addMsg) {
        //提交创建、修改表单
        this.$refs[addMsg].validate(valid => {
          if (valid) {
            this.saveMsg();
          } else {
            return false;
          }
        });
      },
      clearMsg() {
        this.addMsg.Id = 0;
        this.addMsg.Title = '';
        this.addMsg.SourceType = 1;
        this.addMsg.VedioUrl = '';
        this.addMsg.VedioCoverImg = '';
        this.addMsg.SortNum = 0;
        this.addMsg.VedioIntro = '';
      },
      //保存
      saveMsg() {
        this.apipost("/api/MContent/SetVideo", this.addMsg, res => {
          if (res.data.resultCode == 1) {
            this.videoIsShowAdd = true;
            this.getList();
            this.clearMsg();
            this.Success(res.data.message);
          } else {
            this.Info(res.data.message);
          }
        })
      },
      //选择图片
      SelectId(msg) {
        this.addMsg.VedioCoverImg = msg.url;
        this.choicImg = false;
      },
      //修改
      EditprojectClass(item) {
        this.videoIsShowAdd=false;
        this.apipost("/api/MContent/GetVideo", {
          Id: item.Id
        }, res => {
          if (res.data.resultCode == 1) {
            var jsonData = res.data.data;
            this.addMsg.Id = jsonData.Id;
            this.addMsg.Title = jsonData.Title;
            this.addMsg.SourceType = jsonData.SourceType;
            this.addMsg.VedioUrl = jsonData.VedioUrl;
            this.addMsg.VedioCoverImg = jsonData.VedioCoverImg;
            this.addMsg.SortNum = jsonData.SortNum;
            this.addMsg.VedioIntro = jsonData.VedioIntro;
          } else {
            this.Info(res.data.message);
          }
        })
      },
      //删除
      RemoveprojectClass(item) {
        var that = this;
        that.Confirm("是否要删除?", function () {
          that.apipost("/api/MContent/RemoveVideo", {
            Id: item.Id
          }, res => {
            if (res.data.resultCode == 1) {
              that.getList();
            } else {
              that.Info(res.data.message);
            }
          })
        })
      },
    },
    mounted() {
      this.getList();
    }
  };

</script>
<style>
  .projectClass .content .searchInput {
    border: 1px solid #DCDFE6;
    border-radius: 4px;
  }

  .projectClass .content .searchInput .el-input__inner {
    border: none;
    outline: none;
    height: 30px;
    line-height: 30px;
  }

  .projectClass .content .searchInput {
    line-height: normal;
    display: inline-table;
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    width: 250px;
    margin-right: 20px;
  }

  .projectClass .content {
    background: #fff;
    margin-top: 10px;
    padding: 20px;
    box-sizing: border-box;
  }

  .projectClass .operatImg {
    width: 32px;
    height: 32px;
    margin: 0 10px
  }

  .projectClass .projectClass_condiv {
    padding: 20px 0;
    background-color: #fff;
    margin-bottom: 20px;
    padding-right: 50%;
  }

</style>
