<template>
  <b-page @bPageLoaded="voiceCallback"></b-page>
  <div class="back" style="height:100%">
      <iframe ref="iframe" :src="fileUrl" style="height:85%;padding-top:20px;width:95%;"/>
      <div style="padding-right: 1%;padding-top: 20px">
        <!-- 删除按钮 -->
        <img class="imgButton" @click="del" src="../assets/images/btn/btnDel.png">&nbsp;&nbsp;
        <!-- 旋转按钮 -->
        <img class="imgButton" @click="rotateImg"  src="../assets/images/btn/btnRotate.png">&nbsp;&nbsp;
        <!-- 取消按钮 -->
        <img class="imgButton" @click="back" src="../assets/images/btn/btnCancel.png">
      </div>
  </div>

</template>

<script>
import BPage from "@/components/registerVoice";

export default{
  components: {
    BPage,
  },
  data() {
    return {
      projectId: '',//事项ID
      projectName: '',//事项名称
      serviceId: '',//机器人ID
      fileUrl:'',//图片路径
      imgIndex:'',//图片坐标
      fileId:'',//图片fileId
      isMore:0,//是否多份
    }
  },
  created() {

      this.projectId = this.$route.query.projectId;
      this.serviceId = this.$route.query.serviceId;
      this.projectName = this.$route.query.projectName;
      this.fileUrl = "/#/scanMaterialLoad?fileUrl="+this.$route.query.fileUrl;
      this.imgIndex = this.$route.query.index;
      this.fileId=this.$route.query.fileId;
      this.isMore=this.$route.query.isMore;

      //将方法绑定到window下面，提供给外部调用
      window.ConfirmCallback = (res)=> this.ConfirmCallback(res);//提示确认，取消对话框
  },
  methods:{
    rotateImg(){
      this.$refs.iframe.contentWindow.rotateImg();
    },

    back(){
      this.$router.push({ path: '/scanMaterial'});
    },

    del(){
      if (this.isMore>0){//大于1为多份,与其它材料一起删除
        this.showConfirmMessage("当前材料还包含其它材料是否确认一起删除?");
      }else{
        this.$router.push({ path: '/scanMaterial' , query: {imgIndex:this.imgIndex,fileId:this.fileId}});
      }
    },

    showConfirmMessage(content){
      if (robotType) {
        robotsdk.showConfirmMessage({
          isOpen: true,
          content: content,
          isAutoClose: false,
          callback: "ConfirmCallback"
        });
      }
    },

    ConfirmCallback(bool) {
      if (bool) {//确认
        this.$router.push({ path: '/scanMaterial' , query: {imgIndex:this.imgIndex,fileId:this.fileId}});
      }
    },

    //语音回调（只处理退出）
    voiceCallback(res){
      if(robotType){
        robotsdk.closeExternalApp({//退出跳转咨询页面
          mode:0
        });
      }
    }

  }
}

</script>

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