<template>
  <div>
    <div style="width: 80%; margin: 40px auto">
      <h3>企业简介</h3>
      <el-input
        type="textarea"
        :rows="8"
        placeholder="请输入简介内容"
        v-model="introContent"
        @blur="updateCom"
      >
      </el-input>
    </div>
    <div style="width: 80%; margin: 40px auto">
      <h3 style="width: 40%; float: left">企业视频简介</h3>
      <el-upload
        accept=".mp4,.avi,.rmvb,.wmv,.mkv,.bd,.mpg"
        ref="chosenfile"
        class="upload-demo"
        action="#"
        :on-preview="handlePreview"
        :on-remove="handleRemove"
        :before-remove="beforeRemove"
        multiple
        :limit="1"
        :on-exceed="handleExceed"
        :auto-upload="false"
        :on-change="videochange"
        :file-list="fileList"
        style="width: 25%; float: right"
      >
        <el-button
          @click="chooseFile"
          slot="trigger"
          size="small"
          type="primary"
          >请选取小于100M的视频文件</el-button
        >
        <el-button
          style="margin-left: 10px"
          size="small"
          type="success"
          @click="submitUpload"
          >上传到服务器</el-button
        >
      </el-upload>
    </div>
    <div style="width: 80%; margin: 40px auto; clear: both">
      <video
        style="width: 100%"
        v-show="videoShow"
        controls
        :src="playUrl"
      ></video>
    </div>
  </div>
</template>
<script>
import { create, getCom, getComVideo } from "@/api/company.js";
import { createComVideo } from "@/api/company1.js";
export default {
  data() {
    return {
      videoShow: false,
      playUrl: "",
      introContent: "",
      fileList: [],
      reviewReportFile: null,
    };
  },

  created() {},
  mounted() {
    this.getCompanyIntor();
    this.getVideo();
  },
  methods: {
    videochange(e) {
      this.reviewReportFile = null;
      if (e) {
        this.reviewReportFile = e.raw;
      }
    },
    handleRemove(file, fileList) {
      this.clickbutton = 1;
    },
    handlePreview(file) {
      // this.pdfprevshow = true;
    },
    handleExceed(files, fileList) {
      this.$message.warning(
        `当前限制选择 1 个文件，本次选择了 ${files.length} 个文件，共选择了 ${
          files.length + fileList.length
        } 个文件`
      );
    },
    beforeRemove(file, fileList) {
      return this.$confirm(`确定移除 ${file.name}？`);
    },
    chooseFile() {
      this.reviewReportFile = null;
      this.uploadFilePath = "";
    },
    // 获取企业简介
    getCompanyIntor() {
      getCom().then((res) => {
        console.log(res.data.comProfile);
        this.introContent = res.data.comProfile;
      });
    },
    //更新企业简介
    updateCom() {
      let introCon = this.introContent;
      create({ comProfile: introCon, comTitle: "企业简介" }).then((res) => {
        if ((res.code = 200)) {
          this.$modal.msgSuccess("修改成功");
          this.getCompanyIntor();
        }
      });
    },
    //提交视频
    submitUpload() {
      let that = this;
      const formdata = new FormData();
      formdata.append("comVideo", that.reviewReportFile);
      createComVideo(formdata)
        .then((res) => {
          if ((res.code = 200)) {
            this.$modal.msgSuccess("上传成功");
          }
        })
        .then(() => {
          this.getVideo();
        });
    },
    //获取视频信息
    getVideo() {
      this.videoShow = false;
      getComVideo()
        .then((res) => {
          console.log(res);
          if ((res.code = 200)) {
            
            // let url = "http://172.21.117.45:9088//" + res.data.filename;
            let url = "http://121.199.5.225:9088//" + res.data.filename;
            // let url = "http://8.142.46.126:90//" + res.data.filename;
            // let url = "http://192.168.0.233:90//" + res.data.filename;
            // let url = "http://192.168.3.216:90//" + res.data.filename;
            let name = res.data.filename;
            console.log(name);
            this.playUrl = url;

            this.fileList = [{ name, url }];
          }
        })
        .then(() => {
          this.videoShow = true;
        });
    },
    handleRemove(file, fileList) {},
    handlePreview(file) {},
  },
};
</script>
