<template>
  <div class="pdf" v-show="fileType === 'pdf'">
    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          size="mini"
          @click="handleAdd"
          v-hasPermi="['system:menu:add']"
        >转收文</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          size="mini"
          @click="handleAdd"
          v-hasPermi="['system:menu:add']"
        >转本部门</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          size="mini"
          @click="handleAdd"
          v-hasPermi="['system:menu:add']"
        >分发范围</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          size="mini"
          @click="handleAdd"
          v-hasPermi="['system:menu:add']"
        >阅读情况</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          size="mini"
          @click="handleAdd"
          v-hasPermi="['system:menu:add']"
        >收藏公文</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          size="mini"
          @click="pdfdele"
          v-hasPermi="['system:menu:add']"
        >退回</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          size="mini"
          @click="handleAdd"
          v-hasPermi="['system:menu:add']"
        >收文签收</el-button>
      </el-col>
    </el-row>
    <div>
      <p style="font-size: 28px; font-weight: 700;">正文:</p>
       <a v-if="shouwe" :href="src" download="测试">{{name}}</a>
       <span v-if="!shouwe" @click="down">{{name}}</span>
    </div>
    <p style="font-size: 28px; font-weight: 700;">附件:</p>
    <p style="text-align: right; font-size: 20px; color: #1890FF;"><a :href="src"  target="_blank" >全屏</a></p>
    <iframe :src="src" frameborder="0" style="width: 100%; height: 100vh;"></iframe>
  </div>
</template>
<script>
import Pdf from 'vue-pdf'
import { listRoles,pdfDwon,timeu,weit} from "@/api/system/isses";
export default {
  components: {
    Pdf
  },
  data() {
    return {
      dialogVisible: true,
      // src: `${window.location.origin}/ceshi.pdf`,
      src:'',
      fileType:'pdf',
      name:'',
      forew:{
       table:'',
       fixedData:{
         id:-1
       }
      },
      juegh:{
        preview:false,
        absolutePath:''
      },
      shouwe:true,
      wfor:{
        table: "",
        objId:0,
        fixedData:{
          status:'Y',
          receive_time :''
        }
      }
    }
  },
  created() {
    console.log(this.$route.query.tables)
    this.forew.table = 'boman_message';
    this.forew.fixedData.id = this.$route.query.id - 0;
    this.wfor.objId = this.$route.query.index - 0;
    this.wfor.messageId = this.$route.query.id - 0;
    // this.wfor.table = this.$route.query.tables;
    // 获取当前时间戳
    var  date1 =new Date();
    // let tmie = Date.parse(date1) / 1000
    let tmie = this.dateFormat()
    // console.log(tmie)
    this.wfor.receiveTime = tmie
    if(this.$route.query.teiwog == 'weidu'){
      this.weideu()
    }
    this.getList()
    this.timeta()
  },
  methods: {
    handleAdd(){},
    // 路径
    getList() {
      this.loading = true;
      console.log(this.forew)
      listRoles(this.forew).then(
        res => {
          console.log(34)
          console.log(res)
          let pdflis = []
          if(res.data !== undefined){
            if(res.data.message_upload !== null && res.data.message_upload !==''){
              pdflis = JSON.parse(res.data.message_upload)
              this.src = pdflis[0].url
              this.name = res.data.message_title
              this.juegh.absolutePath = pdflis[0].absolutePath
            }
            console.log(this.src.split('.'))
          }
        }
      );
    },
    pdfdele(){
    this.$router.go(-1)
    },
    // 下载
    down(){
      pdfDwon(this.juegh).then(response => {
        if (response.resultCode == 0) {
          this.msgSuccess('提交成功');
        }
        this.$store.dispatch('tagsView/delView', this.$route);
        // this.reload();
      });
    },
    // 判断时间是否在30分钟以内
    timeta(){
      timeu(this.forew.fixedData.id).then(response => {
        console.log(response)
        if(response.code == 200){
          this.shouwe =  true
        }else{
          this.shouwe =  false
        }
        // if (response.resultCode == 0) {
        //   this.msgSuccess('提交成功');
        // }
        // this.$store.dispatch('tagsView/delView', this.$route);
        // this.reload();
      });
    },
    // 未读变已读
    weideu(){
      weit(this.wfor).then(response => {
        console.log(response)
        if(response.code == 200){
          this.msgSuccess('已读成功');
          // this.shouwe =  true
        }else{

          // this.shouwe =  false
        }
        })
    },
    // 时间转换
    dateFormat() {
          var date = new Date();
              var month = date.getMonth() + 1;
              var strDate = date.getDate();
              var hours = date.getHours()
              var minus = date.getMinutes()
              var secong = date.getSeconds()
              if (month >= 1 && month <= 9) {
                  month = "0" + month;
              }
              if (strDate >= 0 && strDate <= 9) {
                  strDate = "0" + strDate;
              }
              if (hours >= 0 && hours <= 9) {
                  hours = "0" + hours;
              }
              if (minus >= 0 && minus <= 9) {
                  minus = "0" + minus;
              }
              if (secong >= 0 && secong <= 9) {
                  secong = "0" + secong;
              }
              var currentDate = date.getFullYear() + "-" + month + "-" + strDate
                      + " " + hours + ":" + minus + ":" + secong;
              return currentDate;
        },


  }
}
</script>

<style>
  .pdf{
    padding: 30px;
  }
</style>
