<template>
	<div class="self-container">
    <div>
      <div class="print-content">
        <img :src="imgSrc" style="border-radius: 35px;">
      </div>
      <div class="printing-word">{{ wordTips }}</div>
    </div>
	</div>
</template>
<script>
import { layer } from "@layui/layer-vue";
import printGit from '../assets/images/print.gif';
export default {
	data() {
		return {
      wordUrl: '',
      wordTips: '',
      base64: '',
      imgSrc: printGit
		}
	},
	created() {
    var caseData = this.$LocalStorage.SessionGet("caseData");
    this.wordUrl = encodeURIComponent(caseData.wordUrl);
    this.wordTips = caseData.wordTips;
    this.getBase64();
	},
  mounted () {
    //将Vue方法传到全局对象window中
    window.printReport = this.printReport;
    window.printPdfSuccess = this.printPdfSuccess;
    window.printPdfError = this.printPdfError;
    if(this.base64 != '') {
      robotsdk.printFile({
        filetype: 'doc',
        base64: this.base64,
        remoteprintname: '',
        replyvoice: this.wordTips,
        callback: "printReport"
      });
    }
  },
	methods: {
    getBase64() {
      var _this = this;
      $.ajax({
        type: "get",
        url: window.config.rocrUrl + 'lilo/aiCase/base64TransToFile',
        async: false, //改为同步请求
        data: {fileUrl: this.wordUrl, flag: true},
        success:function(data){
          if(data.success){
            _this.base64 = data.obj;
          } else {
            layer.msg("系统繁忙，请到窗口办理！", { time: 1500, icon: 3 });
            console.log(data.msg);
          }
        },error: function(error){
          layer.msg("系统繁忙，请到窗口办理！", { time: 1500, icon: 3 });
          console.log(error);
        }
      })
    },
    printReport(obj){
      if (obj) {
        robotsdk.playAudio({
          cmd: 'playAudio',
          animation: 0,
          videocontent: '打印已完成，即将继续后续流程',
          callback: "printPdfSuccess"
        });
      } else {
        robotsdk.playAudio({
          cmd: 'playAudio',
          animation: 0,
          videocontent: '打印机故障，暂时不能为您打印',
          callback: "printPdfError"
        });
      }
    },
    //打印成功
    printPdfSuccess(){
      this.$router.push({ path: '/report'});
    },
    //打印失败
    printPdfError(){
      this.$router.push({ path: '/errorPage' , query: {msg: '暂时不能为您打印，即将回到咨询页面！'}});
    }
	}
}
</script>

<style scoped>
	
	.self-container {
		background-image: url('../assets/images/background.png');
		background-repeat: no-repeat;
		background-size: cover;
		overflow: auto;
		height: 100%;
		padding: 0;
		margin: 0;
	}

	.print-content {
    width: 374px;
    height: 294px;
    position: absolute;
    top: 35%;
    left: 50%;
    transform: translate(-50%, -50%);
	}

  .printing-word{
    width: 100%;
    height: 100%;
    font-size: 26px;
    color: #ffffff;
    position: absolute;
    top: 65%
  }

</style>
