// 과거불량이력조회 팝업

class Tb_DefHst_class {
  constructor(vueform, com ) {
    this.ajaxUrl = "./reg_prod_result.ajax.php";
    
    this.vueform = vueform;
    this.formData = this.vueform.formData;
    this.compactData = this.vueform.compactData[com];
    this.getMode = this.vueform.compactData[com].getMode;
    this.putMode = this.vueform.compactData[com].putMode;
    
    this.fields = this.vueform.tableField[com]
    
    this.container = document.querySelector(`#${com}`);
    this.table = this.container.querySelector(".hy-table");

  }

  getMainList(){

    const ITEM_CD = document.querySelector("#ITEM_CD")?.value;
    const OP_CD = document.querySelector("#OP_CD")?.value;

    let talert = window.setTimeout(()=> { this.tbList.alert("Loading ...") }, 1000);
    ajax_json({
        url: this.ajaxUrl,
        data: { mode: this.getMode, ITEM_CD: ITEM_CD, OP_CD: OP_CD },
        success: (data) => {
            this.tbList.setData(data.data);
        },
        error: (req, status, err) => {
            kuls_alert(err.message);
        },
        complete: () => {
            window.clearTimeout(talert);
        },
    });


  }

  init(){
    document.querySelector("#ITEM_CD_FLT").value = this.compactData['data']['ITEM_CD'];
    document.querySelector("#OP_CD_FLT").value = this.compactData['data']['OP_CD'];

    const commonFieldData = {
      headerSort: true,
      vertAlign: "middle",
      hozAlign: "center",
      resizable: "header", //Resize 는 헤더에서만 가능
      headerHozAlign: "center", //헤더 정렬
      headerSortTristate: true, //데이터 정렬 => 정/역/초기화
    };
    this.tbList = new Tabulator(this.table, {
      layout: "fitColumns",
      data: [], //기본 데이터
      columns: this.fields, //컬럼 설정
      columnDefaults: commonFieldData,
      headerSortElement: "<i class='bi'></i>", //정렬 아이콘
    });

    /*
      * @Overview 테이블 만들어지면 데이터 불러오기
      * @Parameter 없음
      */
    this.tbList.on("tableBuilt", () => {
      this.getMainList();
    });

  }
}