<template>

  <div class="contents">
    <div class="contents_wrap">
      <div class="top_wrap">
        <h3 class="title">배치 모니터링</h3>
        <p class="breadcrumb">모니터링 &gt; 배치 모니터링</p>
      </div>
      <div class= "table">
        <custom-grid
          ref="table"
          :url="grid.url"
          :columns="grid.columns"

        ></custom-grid>
      </div>
    </div>
  </div>
</template>

<script>
import customGrid from '@/components/CustomGrid';

class CustomATagRenderer {
  constructor(props) {
    this.props = props;
    const el = document.createElement('a');
    el.href = 'javascript:void(0);';
    el.className = 'btn_text';
    el.innerText = String(props.colValue)
    this.el = el;
  }

  getElement() {
    return this.el;
  }

  addEvent(selEl) {
    selEl.addEventListener("click", () => {
      const {callback} = this.props["cgrido" + this.props.colName].options;
      callback(this.props);
    });
  }
}

export default {
  name: 'batchList',
  data() {
    return {
      row: {},
      perPageCnt: 50,
      grid: {
        url: '/api/v1/bo/sysMgt/batchList',
        header: [
          [
            {header: '배치ID', childNames: {}},
            {header: '배치명', childNames: {}},
          ]
        ],
        columns: [
          {name: 'batchType', header: '배치유형', align: 'center', width: '7%'},
          {
            name: 'batchNm', header:'배치명',align:'left', width:'15%', renderer: {
            type: CustomATagRenderer
            , options: {
              callback: this.batchDetail,
            }
          }},
          {name: 'batchId', header:'배치ID', align:'center', width:'8%'},
          {name: 'batchCycle', header:'실행일자',align:'center', width:'8%'},
          {name: 'batchTime', header:'실행시간',align:'center', width:'7%'},
          {name: 'regDt', header:'배치 수행시간',align:'center', width:'20%'},
          {name: 'sttusCd', header:'상태',align:'center', width:'5%'},
          {name: 'errMsg', header:'메시지',align:'left', width:'30%'}
        ]
      }
    };
  },  
  components: {
    customGrid: customGrid,
  },
  created(){
    const getCondition = this.$store.getters['searchcondition/getSearchCondition'];

  },
  mounted(){
    let page = 1;
    const getCondition = this.$store.getters['searchcondition/getSearchCondition'];
    let isKeep = false;
    if(getCondition){
      this.grid.params = getCondition.params;
      page = getCondition.page;
      isKeep = true;
    }
    this.search(isKeep);

  },

  methods: {
    search: function (isKeep) {
      this.$refs.table.search(this.grid.params, isKeep);
      this.sendStoreData();
    },
    batchDetail(props){
      this.row.batchId = props.batchId;
      this.$router.push({name: 'batchDetail', params: this.row});
    },
    sendStoreData: function () {
      const getP = this.$refs.table.getPagination();
      this.$store.commit('searchcondition/updateSearchCondition', {
        page: getP._currentPage,
        perPage: this.perPageCnt,
        params: this.grid.params
      });

      const getCondition = this.$store.getters['searchcondition/getSearchCondition'];
    },


  },
  
};
</script>