require("./../css/common.less");
require("./../css/qaPage.less");
const { post, api,ifHideLogo } = require('./api.js');
const $ = require("jquery");

(function(){
    ifHideLogo();
  $("#analy").click(function(){
    getAnswer();
  });
  $("#infoTxt").bind("input propertychange",function(event){
    const val = $("#infoTxt").val().trim();
    if(!val){
      $('#analy').addClass('disabled')
      $('#resultBoxInfo').html('');
      $('.empty').css("display","block");
    }else{
      $('#analy').removeClass('disabled')
    }
  });

  function getAnswer(){
    const qa = $("#infoTxt").val().trim();
    if(!qa)return;
    $('#resultBoxInfo').html(`<p class="loading">正在检索中…</p>`);
    $('.empty').css("display","none");
    post(api.getAnswer, {question:qa}).then(res =>{
      const data=res.data;
      if(data.code==="0"){
        const ans = data.data.answer;
        $('#resultBoxInfo').html(ans);
        $('.empty').css("display","none");
      }else{
        $('#resultBoxInfo').html('');
        $('.empty').css("display","block");
        $('.analying').css("display","none");
      }
    });
  }
})();