<template>
	<div class="self-container">
    <div v-if="step=='1'">
      <div class="print-content"></div>
      <div class="printing-word">正在打印预审报告...</div>
    </div>
    <div v-if="step=='2'">
      <div class="print-success-content"></div>
      <div class="print-success-word">预审报告打印完成</div>
    </div>
    <div v-if="step=='3'">
      <div class="print-error-content"></div>
      <div class="print-error-word">暂时不能为您打印预审报告，您可以通过扫描二维码获取预审报告！</div>
    </div>
	</div>
</template>
<script>
import { layer } from "@layui/layer-vue";
export default {
	data() {
		return {
      projectId: '',
      fileUrl: '',
      step: '1',
      base64: '',
      success: false
		}
	},
	created() {
    var caseData = this.$LocalStorage.SessionGet("caseData");
    this.projectId = caseData.projectId;
    this.fileUrl = caseData.fileUrl;
    this.success = caseData.success;
    this.getBase64();
	},
  mounted () {
    //将Vue方法传到全局对象window中
    window.printReport = this.printReport;
    window.printPdfSuccess = this.printPdfSuccess;
    window.printPdfError = this.printPdfError;
    if(robotType){
      if(this.base64 != ''){
        robotsdk.printFile({
          filetype: 'pdf',
          base64: this.base64,
          remoteprintname: '',
          replyvoice: '正在打印预审报告...',
          callback: "printReport"
        });
      }
    }
  },
	methods: {
    getBase64() {
      var _this = this;
      $.ajax({
        type: "get",
        url: window.config.rocrUrl + 'lilo/aiCase/base64TransToFile',
        async: false, //改为同步请求
        data: {fileUrl: this.fileUrl, flag: false},
        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) {
       this.step='2';
        if(robotType){
          robotsdk.playAudio({
            cmd: 'playAudio',
            animation: 0,
            videocontent: '预审报告已打印完成！',
            callback: "printPdfSuccess"
          });
        }
      } else {
        this.step='3';
        if(robotType){
          robotsdk.playAudio({
            cmd: 'playAudio',
            animation: 0,
            videocontent: '暂时不能为您打印预审报告，您可以通过扫描二维码获取预审报告！',
            callback: "printPdfError"
          });
        }
      }
    },
    //打印预审报告pdf成功
    printPdfSuccess(){
      var caseData = this.$LocalStorage.SessionGet("caseData");
      caseData.printSuccess = true;
      this.$LocalStorage.SessionPut("caseData", caseData);
      if(this.success){
        //预审成功进入装袋页面
        this.$router.push({ path: '/information'});
      } else {
        //预审失败进入评价页面
        this.$router.push({ path: '/evaluation'});
      }
    },
    //打印预审报告pdf失败
    printPdfError(){
      var caseData = this.$LocalStorage.SessionGet("caseData");
      caseData.printSuccess = false;
      this.$LocalStorage.SessionPut("caseData", caseData);
      this.$router.push({ path: '/report'});
    }
	}
}
</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 {
    background-image: url('../assets/images/print.png');
    background-repeat: no-repeat;
    overflow: auto;
    width: 450px;
    height: 367px;
    position: absolute;
    top: 45%;
    left: 50%;
    transform: translate(-50%, -50%);
	}

  .printing-word{
    font-size: 26px;
    color: #ffffff;
    position: absolute;
    bottom: 15%;
    left: 50%;
    transform: translate(-50%, -50%);
  }

  .print-success-content {
    background-image: url('../assets/images/ico/ico_ok.png');
    background-repeat: no-repeat;
    overflow: auto;
    width: 190px;
    height: 190px;
    position: absolute;
    top: 45%;
    left: 50%;
    transform: translate(-50%, -50%);
  }

  .print-success-word{
    font-size: 26px;
    color: #ffffff;
    position: absolute;
    bottom: 28%;
    left: 50%;
    transform: translate(-50%, -50%);
  }

  .print-error-content {
    background-image: url('../assets/images/ico/ico_warn.png');
    background-repeat: no-repeat;
    overflow: auto;
    width: 204px;
    height: 184px;
    position: absolute;
    top: 45%;
    left: 50%;
    transform: translate(-50%, -50%);
  }

  .print-error-word{
    width: 100%;
    font-size: 26px;
    color: #ffffff;
    position: absolute;
    bottom: 28%;
    left: 50%;
    transform: translate(-50%, -50%);
  }

</style>
