<!--
 * @Author: zqm
 * @Date: 2021-06-28 16:16:25
 * @LastEditTime: 2022-01-28 17:47:24
 * @LastEditors: Please set LastEditors
 * @Description: 关闭按钮
 * @FilePath: \taxFormToolFramework\src\components\closeButton.vue
-->
<template>
  <div>
    <el-button ref="closeButton" type="primary" size="small" :plain="closeProp.isPlain" @click="closeFun">关闭</el-button>
  </div>
</template>
<script>
export default {
  name: "closeButton",
  props: {
    closeProp: { type: Object, default: () => ({}) },
    selected: { type: String, default: "" }
  },
  methods: {
    closeFun() {
      var flag1 = this.valuesEqual();//flag1为false 不一样 弹出 flag1为true 一样 不弹出 
      var flag2 = true;//flag2为true 不弹出 flag2为false 弹出
      if (this.selected == "saveButton") {//页面保存过并且无数据更改，可直接关闭
        if (this.$store.state.data.saveStatus) {
          flag2 = true;
        } else {
          flag2 = false;
        }
      } else {
        flag2 = false;
      }
      if (flag1) {
        this.returnHomePageType();
      } else {
        if (!flag2) {
          var _self = this
          this.$confirm("关闭当前页面前，是否需要保存当前报表数据？", '提示', {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            type: 'warning'
          }).then(() => {
            var obj = _self.recursionChild(_self.$parent.$children, "saveButton");
            obj.saveFun( "close");
            _self.returnHomePageType();
          }).catch(() => {
            this.returnHomePageType();
          });
        } else {
          this.returnHomePageType();
        }
      }
    },
    //关闭当前页面的处理方式
    returnHomePageType() {
      var _self = this;
      var platform = this.$store.state.data.platform;
      if (platform == "2") {//云代账、天保
        Vue.prototype.closeWin = true;
        window.history.back(-1);
        return
      } else if (platform == "1") { //在线、涉税
        if (navigator.userAgent.indexOf("MSIE") > 0) {
          if (navigator.userAgent.indexOf("MSIE 6.0") > 0) {
            window.opener = null;
            window.close();
          } else {
            window.open('', '_top');
            window.top.close();
          }
        } else if (navigator.userAgent.indexOf("Firefox") > 0 || navigator.userAgent.indexOf("Chrome") > 0) {
          window.location.href = "about:blank";
          window.close();
        } else {
          window.opener = null;
          window.open('', '_self');
          window.close();
        }
        return;
      }
    }
  }
}
</script>
<style scoped>
</style>
