<template>

  <div class="contents">

    <div class="contents_wrap">
      <div class="top_wrap">
        <h3 class="title">080 수신번호 차단</h3>
        <p class="breadcrumb">리스크관리 &gt; 080 수신번호 차단</p>
      </div>
<!--      <div class="search_form">-->
        <div class="search_wrap">
          <div class="input_box">
            <label for="search" class="label">고객사</label>
            <input class="search-box" type="text" id="search" placeholder="검색어 입력" v-model.trim="grid.params.custNm"
                   @keypress="onlyText" @input="onlyText" maxlength="20"/>
          </div>
          <div class="input_box">
            <label for="search" class="label">인증코드</label>
            <input class="search-box" type="text" id="search" placeholder="검색어 입력" v-model.trim="grid.params.authcd080"
                   @keypress="onlyNum" @input="onlyNum" maxlength="6"/>
          </div>
          <div class="input_box">
            <label for="search" class="label">수신번호</label>
            <input class="search-box" type="text" id="search" placeholder="검색어 입력" v-model.trim="grid.params.rcvblckno"
                   @keypress="onlyNum"
                   @input="onlyNum" maxlength="11"/>
          </div>
          <button type="button" class="button grey" @click="search">조회</button>
        </div>
<!--      </div>-->
      <div class="info">
        <div class="count">총 <span> {{ totalItems.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ',') }} </span>건
          <div class="select_box NumberSe">
            <select name="" id="" v-model="perPageCnt" @change="changePerPage()">
              <option v-for="option in options" v-bind:value="option.value" v-bind:key="option.value">{{
                  option.text
                }}
              </option>
            </select>
          </div>
        </div>
      </div>
      <div class="table">
        <custom-grid
            ref="table"
            :totalItems="'totalItems'"
            :url="grid.url"
            :pagePerRows="grid.pagePerRows"
            :initialRequest="grid.pagination"
            :pagination="grid.pagination"
            :isCheckbox="grid.isCheckbox"
            :columns="grid.columns"
            :noDataStr="grid.noDataStr"
            :addCls="grid.addCls"
            :header="grid.headder">
        </custom-grid>
      </div>
      <common-modal ref="commmonModal"></common-modal>
    </div>

  </div>
</template>

<script>
import customGrid from '@/components/CustomGrid';
import commonModal from "@/components/modal/commonModal";
import {utils_mixin, chkPattern2} from '../service/mixins';

//import api from '../service/api';
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);
    });
  }
}

class customBRegNo {
  constructor(props) {
    //this.props = props;
    const el = document.createElement('td');
    var bregNo = String(props.colValue);
    el.innerText = bregNo;
    if (bregNo.length == 10) {
      el.innerText = bregNo.substring(0, 3) + '-' + bregNo.substring(3, 5) + '-' + bregNo.substring(5, 10)
    }
    this.el = el;
  }

  getElement() {
    return this.el;
  }

  addEvent(selEl) {
  }
}

export default {
  name: 'intrcpList',
  mixins: [utils_mixin, chkPattern2],
  data() {
    return {
      totalItems: 0,
      userType: [],
      row: {},
      perPageCnt: 50,
      pagePerRows: 20,
      options: [
        {text: '20', value: 20},
        {text: '50', value: 50},
        {text: '100', value: 100}
      ],
      grid: {
        url: '/api/v1/bo/riskMgt/zezNum/intrcpList',
        pagination: true,
        isCheckbox: false,
        initialRequest: false,
        addCls: 'box_OFvis',
        header: [
          [
            {header: 'NO', childNames: []},
            {header: '고객사', childNames: []},
            {header: '사업자번호', childNames: []},
            {header: '인증코드', childNames: []},
            {header: '수신번호', childNames: []},
            {header: '등록일', childNames: []},
            {header: '등록구분', childNames: []}
          ]
        ],

        columns: [
          {name: 'no', header: 'NO', align: 'center', width: '5%'},
          {
            name: 'custNm', header: '고객사', align: 'center', width: '15%', renderer: {
              type: CustomATagRenderer
              , options: {
                callback: this.memberDetail,
              }
            }
          },
          {name: 'bizrno', header: '사업자번호', align: 'center', width: '15%'},
          {name: 'authcd080', header: '인증코드', align: 'center', width: '15%'},
          {name: 'rcvblckno', header: '수신번호', align: 'center', width: '15%'},
          {name: 'regDt', header: '등록일', align: 'center', width: '20%'},
          {name: 'regTpCd', header: '등록구분', width: '15%', cls: 'td_line'}
        ],
        noDataStr: '검색 결과가 없습니다.',
        params: {
          regTpCd: '',
          authcd080: '',
          rcvblckno: ''
        },
        excelHeader: []
      }
    };
  },
  components: {
    customGrid: customGrid,
    commonModal,
  },
  destroyed() {

  },
  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.pagePerRows = getCondition.perPage;
      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();
    },
    changePerPage: function () { 	// 페이지당 조회할 개수
      this.grid.pagePerRows = this.perPageCnt;
    },
    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'];
    },
    //회원 상세페이지로 이동
    memberDetail(props) {
      this.row.serviceId = props.userId;
      this.$router.push({name: 'subsDetail', params: this.row});
    }
  },
  beforeRouteLeave(to, from, next) {

    const getP = this.$refs.table.getPagination();
    this.$store.commit('searchcondition/updateSearchCondition', {
      page: getP._currentPage,
      perPage: this.perPageCnt,
      params: this.grid.params
    });
    // 라우트 하기전 실행
    next();
  }
};
</script>