<template>
  <a-config-provider :locale="locale">
    <div id="app">
      <a-layout>
        <a-layout-header>
          <fe-header></fe-header>
        </a-layout-header>
        <a-layout-content class="dfmea-page-content">
          <router-view v-if="isRouterAlive"
                       :versionLibraryDiffCloseFlag="versionLibraryDiffCloseFlag"
                       @versionLibraryDiffCloseFlagChange="quoteLibraryToFmeaCloseFlagChange"
          />
        </a-layout-content>
        <a-layout-footer>
          <div class="footer">
            <div class="copyright">
              Copyright
              <a-icon type="copyright" />
              <span>国可工软科技有限公司</span>
            </div>
          </div>
        </a-layout-footer>
      </a-layout>
      <!-- 知识库-》fmea的差异对比 -->
      <LibraryToFmeaDiff ref="libraryToFmeaDiff" @closeModal="quoteLibraryToFmeaDiffClose" @refresh="getLibraryToFmeaStatistics"/>
      <AiButton ref="aiButton" class="ai" v-show="aiButtomVisible && isAiSwtich" onclick="openOrCloseAiChat()"></AiButton >
      <el-dialog title="" :visible.sync="aiDialogVisible" :close-on-click-modal=false
                 @close="aiDialogClose()" v-dialogDrag width="40%" right="0" top="40vh" :modal="false">
        <i class="iconfont iconquanpingc quanping"/>
        <iframe src="http://ai.nationrel.cn/ui/chat/iframe?userId=1" id="mobsf"
                scrolling="no" frameborder="0" class="iframe-ai"></iframe>
      </el-dialog>
    </div>
  </a-config-provider>
</template>
<script>

import feHeader from "@/layout/header";
import WaterMark from "@/components/watermark/watermark";
import MasterFmeaDiff from "@/components/MasterFmeaDiff";
import LibraryToFmeaDiff from "@/components/LibraryToFmeaDiff";

import AiButton from "@/components/AiButton/aiButton.vue";

export default {
  components: {
    feHeader,
    MasterFmeaDiff,
    LibraryToFmeaDiff,
    AiButton
  },
  provide() {
    return {
      reload: this.reload
    };
  },
  data() {
    return {
      isRouterAlive: true,
      versionDiffCloseFlag: false,
      versionLibraryDiffCloseFlag: false,
      aiButtomVisible: true,
      aiDialogVisible: false,
      isAiSwtich: false,
    };
  },
  methods: {
    reload() {
      this.isRouterAlive = false;
      this.$nextTick(function(){
        this.isRouterAlive = true;
      });
    },
    // 获取路径参数
    getUrlParam(paraName) {
      var url = document.location.toString();
      var arrObj = url.split("?");
      if (arrObj.length > 1) {
        var arrPara = arrObj[1].split("&");
        var arr;
        for (var i = 0; i < arrPara.length; i++) {
          arr = arrPara[i].split("=");
          if (arr != null && arr[0] == paraName) {
            return arr[1];
          }
        }
        return "";
      } else {
        return "";
      }
    },

    /**
     * 差异处理弹框-关闭
     */
    quoteLibraryToFmeaDiffClose() {
      this.quoteLibraryToFmeaCloseFlagChange();
      this.$refs.libraryToFmeaDiff.visible = false;
    },
    /**
     * 差异处理弹框关闭标志处理
     */
    quoteLibraryToFmeaCloseFlagChange() {
      this.versionLibraryDiffCloseFlag = !this.versionLibraryDiffCloseFlag;
    },
    /**
     * 获取知识库-->FMEA差异数量统计
     */
    getLibraryToFmeaStatistics() {
      let rfmeaId = this.getUrlParam("rfmeaId");
      this.$api.getQuoteLibraryToFmeaStatistics(rfmeaId).then(res => {
        if (res.flag) {
          this.$refs.libraryToFmeaDiff.functionDiffNum = res.data.functionDiffNum;
          this.$refs.libraryToFmeaDiff.productFeatureDiffNum = res.data.productFeatureDiffNum;
          this.$refs.libraryToFmeaDiff.faultDiffNum = res.data.faultDiffNum;
          this.$refs.libraryToFmeaDiff.preventDiffNum = res.data.preventDiffNum;
          this.$refs.libraryToFmeaDiff.detectDiffNum = res.data.detectDiffNum;
          this.$refs.libraryToFmeaDiff.interfaceDiffNum = res.data.interfaceDiffNum;
        } else {
          this.$message.error(res.message);
        }
      })
    },
    openOrCloseAiChat() {
      if (!this.$refs.aiButton.isClickEvent) return;
      this.aiDialogVisible = true;
      this.aiButtomVisible = false;
    },
    aiDialogClose() {
      this.aiDialogVisible = false;
      this.aiButtomVisible = true;
    },
    initAiConfig() {
      this.$api.initAiConfig().then(res => {
        if (res.flag) {
          window.apiObj.isAiSwtich = res.data.aiDisable === '0';
          this.isAiSwtich = res.data.aiDisable === '0';
        } else {
          this.$message.error(res.message, 1);
        }
      });
    }
  },
  computed: {
    locale() {
      return this.$i18n.getLocaleMessage(this.$store.getters.lang).antLocale;
    }
  },
  mounted() {
    let userInfo = localStorage.getItem('userInfo');
    if (userInfo) {
      let user = JSON.parse(userInfo);
      let name = user.username;
      let mark = localStorage.getItem('waterMark');
      let waterMark = {};
      if (mark) {
        waterMark = JSON.parse(mark);
        if (!user.hasOwnProperty('waterMark') && waterMark.state == '0') {
          WaterMark.set(name + " 正在非法访问");
          return;
        }
        if (waterMark.state == '0') {
          let main = document.getElementById('app');
          WaterMark.set(user.waterMark, main);
        }
      }
    }
    this.getLibraryToFmeaStatistics();
    window.openOrCloseAiChat = this.openOrCloseAiChat;
    window.aiDialogClose = this.aiDialogClose;
    this.initAiConfig();
    //加水印
    //VUE_APP_Wmshost 水印系统地址
    //水印
    // let config = {
    //   clientuser: u.name,
    //   strlevelname: process.env.VUE_APP_Water_Name,
    //   host: process.env.VUE_APP_Wmshost,
    //   protical: 'http'
    // };
    // window.HLeagMark(config);
    /*if (window.HVueLeagMark) {
      window.HVueLeagMark(
        u.name,
        "dfmea-qa-网页水印",
        process.env.VUE_APP_Wmshost,
        true
      );
    }*/
  },
  beforeDestroy() {
    let userinfo = localStorage.getItem("userInfo");
    let u = JSON.parse(userinfo);
    //去水印
    // window.h_560_XRWO_IO20X_77();
    /*if(window.clearHVueLeagMarkData){
      window.clearHVueLeagMarkData(
      u.name,
      "dfmea-qa-网页水印",
      process.env.VUE_APP_Wmshost,
      true
    );
    }*/
    window.location.reload();
  },
  // methods: {}
};
</script>
<style>
  .footer {
    text-align: center;
  }

  .copyright {
    color: rgba(0, 0, 0, 0.45);
    font-size: 14px;
  }

.clear {
  clear: both;
}

.fl {
  float: left;
}

.fr {
  float: right;
}

.zin99 {
  z-index: 99;
}

.mt5 {
  margin-top: 5px;
}

.mt10 {
  margin-top: 10px;
}

.mt15 {
  margin-top: 15px;
}

.mt20 {
  margin-top: 20px;
}

.mt30 {
  margin-top: 30px;
}

.mt40 {
  margin-top: 40px;
}

.mt50 {
  margin-top: 50px;
}

.ml5 {
  margin-left: 5px;
}

.ml10 {
  margin-left: 10px;
}

.ml15 {
  margin-left: 15px;
}

.ml20 {
  margin-left: 20px;
}

.ml30 {
  margin-left: 30px;
}

.ml40 {
  margin-left: 40px;
}

.ml50 {
  margin-left: 50px;
}

.mr5 {
  margin-right: 5px;
}

.mr10 {
  margin-right: 10px;
}

.mr15 {
  margin-right: 15px;
}

.mr20 {
  margin-right: 20px;
}

.mr30 {
  margin-right: 30px;
}

.mr40 {
  margin-right: 40px;
}

.mr50 {
  margin-right: 50px;
}

.mb5 {
  margin-bottom: 5px;
}

.mb10 {
  margin-bottom: 10px;
}

.mb15 {
  margin-bottom: 15px;
}

.mb20 {
  margin-bottom: 20px;
}

.mb30 {
  margin-bottom: 30px;
}

.mb40 {
  margin-bottom: 40px;
}

.mb50 {
  margin-bottom: 50px;
}

.pt5 {
  padding-top: 5px;
}

.pt10 {
  padding-top: 10px;
}

.pt15 {
  padding-top: 15px;
}

.pt20 {
  padding-top: 20px;
}

.pt30 {
  padding-top: 30px;
}

.pt40 {
  padding-top: 40px;
}

.pt50 {
  padding-top: 50px;
}

.pl5 {
  padding-left: 5px;
}

.pl10 {
  padding-left: 10px;
}

.pl15 {
  padding-left: 15px;
}

.pl20 {
  padding-left: 20px;
}

.pl30 {
  padding-left: 30px;
}

.pl40 {
  padding-left: 40px;
}

.pl50 {
  padding-left: 50px;
}

.pr5 {
  padding-right: 5px;
}

.pr10 {
  padding-right: 10px;
}

.pr15 {
  padding-right: 15px;
}

.pr20 {
  padding-right: 20px;
}

.pr30 {
  padding-right: 30px;
}

.pr40 {
  padding-right: 40px;
}

.pr50 {
  padding-right: 50px;
}

.pb5 {
  padding-bottom: 5px;
}

.pb10 {
  padding-bottom: 10px;
}

.pb15 {
  padding-bottom: 15px;
}

.pb20 {
  padding-bottom: 20px;
}

.pb30 {
  padding-bottom: 30px;
}

.pb40 {
  padding-bottom: 40px;
}

.pb50 {
  padding-bottom: 50px;
}

.m0 {
  margin: 0;
}

.m5 {
  margin: 5px;
}

.m10 {
  margin: 10px;
}

.m15 {
  margin: 15px;
}

.m20 {
  margin: 20px;
}

.p0 {
  padding: 0;
}

.p5 {
  padding: 5px;
}

.p10 {
  padding: 10px;
}

.p15 {
  padding: 15px;
}

.p20 {
  padding: 20px;
}

.clickRowStyl {
  background-color: rgb(230, 247, 255);
}

.ant-table-thead > tr > th .ant-table-header-column {
  color: #040B29;
}

.ant-table-tbody > tr > td {
  color: #040B29;
}

.ant-btn .ant-btn-primary {
  border-radius: 4px;
}

.ai {
  width: 45px !important;
  height: 45px !important;
  bottom: 20px;
  right: 20px;
  position: fixed;
  z-index: 10000;
}
.iframe-ai {
  width: 100%;
  height: 100%;
  padding: 0 20px;
  background-color: #f5f6f7;
  margin-top: -51px;
  overflow: auto hidden;
}

.quanping {
  font-size: 20px !important;
  color: #6F7385;
  top: 13px;
  right: 45px;
  font-weight: 700;
  position: absolute;
  pointer-events: none;
}
</style>
