<template xmlns="http://www.w3.org/1999/html">
  <b-page @bPageLoaded="voiceCallback"></b-page>
  <count-down times=300 bottomOffset="0" rightOffset="10" fontSize="16" ref="child"></count-down>

  <template v-if="schedule == 0">
    <div class="workGuide">
      <div style="padding-top: 18%;">
        <div style="margin-top: 45px;">
          <font size="6" color="#FFFFFF">{{startPrintRemind}}，<br><br>如果您已经备齐该资料请点击下一步，如果您不具备该资料请点击打印</font>
        </div>
        <div style="position: absolute;margin-left: 248px;margin-top: 280px;">
          <img style="width: 90%;" src="../assets/images/btn/btnPrint.png" @click="printClick" id="confirm">
        </div>
        <div style="position: absolute;margin-left: 600px;margin-top: 280px;">
          <img style="width: 90%;" src="../assets/images/btn/btnNext.png" @click="nextClick" id="cancel">
        </div>
      </div>
    </div>
  </template>

  <template v-if="schedule == 1">
    <div class="workGuide">
      <div style="padding-top: 18%;">
        <div style="margin-top: 45px;">
          <font size="6" color="#FFFFFF">正在为您打印{{promptInformation}},请您耐心等候</font>
        </div>
        <div style="position: absolute;margin-left: 520px;margin-top: 100px;">
          <img style="width: 90%;" src="../assets/images/wait.gif">
        </div>
      </div>
    </div>
  </template>

  <template v-if="schedule == 2">
    <div class="workGuide">
      <div style="padding-top: 18%;">
        <div style="margin-top: 45px;">
          <font size="6" color="#FFFFFF">{{printEndRemind}}</font>
        </div>
      </div>
    </div>
  </template>

</template>
<style scoped>
.workGuide{
  background-image: url('../assets/images/background.png');
  background-repeat: no-repeat;
  background-size: cover;
  overflow:auto;
  margin-bottom: 20px;
  padding: 0 70px;
  height:100%;
}
</style>
<script>
import { layer } from "@layui/layer-vue";
import websocket from "@/assets/js/websocket";
import commonUtil from "@/assets/js/commonUtil";
import BPage from "@/components/registerVoice";
export default{
  components: {
    BPage,
  },

  data() {
    return {
      isWorkPrint:'',//办事指南处是否打印word 1：是 0：否
      printStep:'',//打印完成后续步骤 1：继续 0：退出
      startPrintRemind:'',//打印前提示信息
      promptInformation:'',//打印资料名称：
      printEndRemind:'',//打印后提示信息
      inquiryUnemployment:'',//是否询问失业原因

      projectId: '',//事项ID
      serviceId: '',//机器人ID
      projectName:'',//事项名称
      schedule: "",//界面显示控制

    }
  },
  created() {
    this.projectId = this.$route.query.projectId;
    this.serviceId = this.$route.query.serviceId;
    this.projectName = this.$route.query.projectName;
    this.schedule="0";
    window.printReport = (res) => this.printReport(res);//打印回调
    window.PlayAudio_printReportCallback = (res) => this.PlayAudio_printReportCallback(res);//打印事项资料后语音回调
    this.findParam();
  },
  methods:{
    timing(){//调试页面使用
      let timer = setInterval(() => {
        //需要定时执行的代码
        this.schedule++;
        console.log(this.schedule);
        if (this.schedule>0){
          this.schedule=0;
          //清除多次执行定时器
          clearInterval(timer);
          // this.$router.push({ path: '/scanMaterial' , query: {projectId: this.projectId}});
        }
      },3000)
    },

    findParam(){
      if(robotType){
        $.post(window.config.api + '/lilo/aiCase/getCaseMethodByProjectId', {
          projectId:this.projectId
        }).then(item => {
          if (item.success) {//接口调用成功
            this.startPrintRemind = item.obj.startPrintRemind;//打印前提示信息
            this.promptInformation = item.obj.promptInformation;//打印资料名称
            this.printEndRemind = item.obj.printEndRemind;//打印后提示信息
            this.inquiryUnemployment = item.obj.inquiryUnemployment;//是否进入询问失业原因页面
            //是否办事指南处是否打印word赋值  1：是 0：否
            if (item.obj.isWorkPrint!=null){
              this.isWorkPrint = item.obj.isWorkPrint;
            } else {
              this.isWorkPrint="0";
            }
            //打印完成后续步骤赋值  1：继续 0：退出
            if (item.obj.printStep!=null){
              this.printStep = item.obj.printStep;
            } else {
              this.printStep="0";
            }
            //是否办事指南处打印word流程  1:是,0:否
            if ("1"==this.isWorkPrint){//需要打印界面
              this.schedule="0";
              robotsdk.playAudio({
                cmd: "cmd",
                animation: 0,
                videocontent: (this.startPrintRemind) + "，如果您已经备齐该资料请点击下一步，如果您不具备该资料请点击打印",
                callback: ""
              })
            }else {//不需要打印
              debugger;
              if ("1" == this.inquiryUnemployment){
                this.$router.push({ path: '/inquiryUnemployment',query: {projectId: this.projectId ,serviceId:this.serviceId, projectName:this.projectName}});//转跳贵阳询问是否进入失业金申领页面
              }else {
                this.$router.push({ path: '/userSelect',query: {projectId: this.projectId ,serviceId:this.serviceId, projectName:this.projectName}});//转跳身份选择页面
              }
            }
          }else {//接口调用失败
            this.$router.push({ path: '/errorPage'});//转跳错误提示页面
          }
        })
      }else {//页面调试用
        this.timing();
      }
    },

    //点击打印按钮
    printClick(){
      this.schedule=1;
      $.post(window.config.rocrUrl + '/lilo/aiCase/workGuide', {
        projectId:this.projectId
      }).then(item => {
        if (item.success) {//接口调用成功
          robotsdk.playAudio({
            cmd: "cmd",
            animation: 0,
            videocontent: "请稍等，正在为您打印！",
            callback: ""
          })
          robotsdk.printFile({
            filetype: 'doc',
            base64: item.obj.base64Byte,//打印base64数据
            remoteprintname: "",
            replyvoice: '',
            callback: "printReport"
          });
        }else {//接口调用失败
          this.$router.push({ path: '/errorPage'});//转跳错误提示页面
        }
      })
    },

    //打印事项材料回调
    printReport(bool){
      if (bool){//打印成功返回true
        this.schedule=2;
        robotsdk.playAudio({
          cmd: "cmd",
          animation: 0,
          videocontent: this.printEndRemind,
          callback: "PlayAudio_printReportCallback"
        })
      }else {
        this.$router.push({ path: '/errorPage',query: {msg: '事项材料打印失败，请联系管理员'}});//转跳错误提示页面
      }
    },

    //"事项材料打印成功_语音回调"
    PlayAudio_printReportCallback(res){
      if (res=="cmdOK") {//语音播报完5秒后执行代码
        let timer = setInterval(() => {
          if ("1"==this.printStep){//打印完成后续步骤 1：继续 0：退出
            this.$router.push({ path: '/userSelect',query: {projectId: this.projectId ,serviceId:this.serviceId, projectName:this.projectName}});//转跳身份选择页面
          }else {
            robotsdk.closeExternalApp({
              mode:0
            });
          }
        },3000)

      }
    },

    //点击下一步
    nextClick(){
      if(robotType){
        this.$router.push({ path: '/userSelect',query: {projectId: this.projectId ,serviceId:this.serviceId, projectName:this.projectName}});//转跳身份选择页面
      }
    },

    //语音回调（只处理下一步和退出）
    voiceCallback(res){
      if (res=="nextStep"){
        this.nextClick();
      }

      if (res=="quit"){
        if(robotType){
          robotsdk.closeExternalApp({
            mode:0
          });
        }
      }
    }

  }
}
</script>