<style scoped>
.clearfix:after{content:".";display:block;height:0;clear:both;visibility:hidden}
.clearfix{overflow:hidden;_zoom:1;}
input{background:none;outline:none;border:0px;}
.text-gray{color:#717171;}
.text-orange{color:#eb7741;}
.text-danger{color:#c03546;}
.messageDetail{position: relative;background-color: #f3f6ff;}
.messageTitle{font-weight:600;margin:0;word-wrap:break-word;padding:0.6rem 3%;padding-bottom: 0;}
.messageDate{font-size: 0.7rem;padding:0 3%;padding-bottom: 0.4rem;color:#616161;}
.messageContent{word-wrap:break-word;padding:0 3%;padding-bottom: 0.4rem;}
.messageContent img{max-width: 100%;height:auto;}
</style>
<template>     
  <div class="jfBaseSize messageDetail" v-cloak v-bind:style="isShow.vh?'height:100vh':'height: 100%;'"> 
    <p class="messageTitle" v-html="messageData.CategoryName"></p>
    <p class="messageDate" v-html="messageData.row_create_date"></p>
    <div class="messageContent" v-html="messageData.LetterContent">
    </div>
     <ReturnHome ref="returnhome"></ReturnHome>
  </div>
</template>
<script>
import Vue from 'vue';
import { Toast,DatetimePicker,Indicator,Picker,MessageBox } from 'mint-ui';
import channelHelper from "@/assets/js/channelHelper.js";
import { base64 } from "@/assets/js/cryptoHelper";
import { debug } from 'util';
import '@/assets/js/libs/js.cookie';
import utils from "@/assets/js/utils.js";
import QRCode from 'qrcodejs2';
import ReturnHome from "@/components/channel/temp001/ReturnHome";
import Clipboard from 'clipboard';
export default {
  props: ["comp", "cfg", "selectedPage"],
  components: {
    ReturnHome
  },
  provide(){       
     return{           
        goPage:this.goPage       
     }   
  },
  data() {
    return {
      isShow:{
        vh:true,
      },
      messageObj:{
        LetterId:'',
        OperUserId:'',
        EnterpriseNo:this.sup8.context.enterpriseno,
        UserToken:channelHelper.GetUserToken(),
        LanguageType:"zh-cn",
      },
      messageData:{},
    }
  },
  methods: {
    goPage(pagetype){
        this.$parent.changeSelectedPage(pagetype);
    },
    
    //配置获取
    GetMessageSetting(){
      var that=this;
      var url = "/channel/GetMessageSetting";
      var dataParams = that.searchRequest;
      Indicator.open();
      var cbSuccess = function(res){
        if (res.flag) {
          var data=res.data;
          that.$set(that,'setResponse',data);
        }else
        { 
            Toast(res.msg);
        }
        Indicator.close();
      };
      var cbError = function(jqXHR, textStatus, errorThrown){
        Toast(jqXHR.responseText);
      };
      //请求后端
      channelHelper.CommonCallService(url,dataParams,cbSuccess,cbError,null,null);
    },
    //详情获取
    LookDetailById(){
      var that=this; 
      var url = "/channel/LookDetailById";
      var dataParams = that.messageObj;
      Indicator.open();
      var cbSuccess = function(res){
        if (res.flag) {
          var data=res.data;
          if(data.LetterContent){
              data.LetterContent=data.LetterContent.replace(/%/g, '%25');
              data.LetterContent=decodeURIComponent(data.LetterContent);
              const regex = new RegExp('<img', 'gi');
              data.LetterContent = data.LetterContent.replace(regex, `<img style="max-width: 100%; height: auto"`);
          }
          that.$set(that,'messageData',data);
          that.UpdateLetterStatusByIds();
        }else
        { 
          Toast(res.msg);
        }
        Indicator.close();
      };
      var cbError = function(jqXHR, textStatus, errorThrown){
        Toast(jqXHR.responseText);
      };
      //请求后端
      channelHelper.CommonCallService(url,dataParams,cbSuccess,cbError,null,null);
    },
    //已读
    UpdateLetterStatusByIds(){
      var that=this; 
      var url = "/channel/UpdateLetterStatusByIds";
      var dataParams = that.messageObj;
      dataParams.Ids=dataParams.LetterId;
      var cbSuccess = function(res){
        Indicator.close();
      };
      var cbError = function(jqXHR, textStatus, errorThrown){
        Toast(jqXHR.responseText);
      };
      //请求后端
      channelHelper.CommonCallService(url,dataParams,cbSuccess,cbError,null,null);
    },
    judgeLogin:function(){
      var eno = this.sup8.context.enterpriseno;
      if (!channelHelper.CheckLogin(this.$parent,eno,this.sup8.context.entranceid)) {
        this.$parent.changeSelectedPage('Key_Login');
        return false;
      }
    },
    //消息配置获取
    GetSup8UserID(){
      var that=this;
      var url = "/channel/GetSup8UserID";
      var dataParams = that.messageObj;
      Indicator.open();
      var cbSuccess = function(res){
        if (res.flag) {
          var data=res.data;
          that.$set(that.messageObj,'OperUserId',data);
          that.LookDetailById();
        }else
        { 
          Toast(res.msg);
          Indicator.close();
        }
      };
      var cbError = function(jqXHR, textStatus, errorThrown){
        Toast(jqXHR.responseText);
      };
      //请求后端
      channelHelper.CommonCallService(url,dataParams,cbSuccess,cbError,null,null);
    },
  },
  watch: {},
  created: function() {
    var that = this;
    var isDesign = location.pathname.indexOf('design');
    if(isDesign!=-1)
    {
        return;
    }
    //判断是否登录
    that.judgeLogin();
    that.GetSup8UserID();
    var ID=sessionStorage.getItem('Key_MessageList_DetailID');
    if(ID){
      that.$set(that.messageObj,'LetterId',ID);
      sessionStorage.removeItem('Key_MessageList_DetailID');
    }
  },
  mounted: function() {
    var that =this;
    var isDesign = location.pathname.indexOf('design');
    if (!(isDesign>-1)) {
        that.$set(that.isShow,'vh',true);
    }else{
        that.$set(that.isShow,'vh',false);
    }
  }
};
</script>

