<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_wrap">
          <div class="select_box">
            <label for="stat" class="label">상태</label>
            <select name="" id="stat" v-model="searchType1" @keyup.enter="search">
              <option value="">전체</option>
              <option value="Y">사용</option>
              <option value="N">폐기</option>
            </select>
          </div>
          <div class="select_box">
            <label for="searchType" class="label">고객사명</label>
            <select name="" id="searchType" v-model="searchType2" @keyup.enter="search">
              <option value="custNm">고객사명</option>
              <option value="bizNo">사업자번호</option>
              <option value="authCd">인증코드</option>
            </select>
          </div>
          <div class="input_box">
            <label for="search" class="label">검색어</label>
            <input type="text" id="id1" placeholder="검색어 입력" v-model.trim="grid.params.searchText1"
                   @keyup.enter="search" maxlength="100"/>
          </div>
          <button type="button" class="button grey" @click="search">조회</button>
        </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.initialRequest"
            :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 api from '../service/api';
import commonModal from "@/components/modal/commonModal";

export default {
  name: 'rejectRecvList',
  data() {
    return {
      row: {},
      authType: [],
      statType: [],
      cate2Code: "",
      totalItems: 0,
      searchType1: '',
      searchType2: 'custNm',
      // 테이블 리스트 데이터
      perPageCnt: 50,
      options: [
        {text: '20', value: 20},
        {text: '50', value: 50},
        {text: '100', value: 100}
      ],
      grid: {
        url: '/api/v1/bo/servMgt/rejectRecvList',
        pagePerRows: 20,
        pagination: true,
        isCheckbox: false,
        initialRequest: false,
        addCls: 'box_OFvis',
        header: [
          [
            {header: 'NO', childNames: []},
            {header: '고객사명(이름)', childNames: []},
            {header: '사업자번호(생년월일)', childNames: []},
            {header: '관리자ID', 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%'},
          {name: 'bregNo', header: '사업자번호', align: 'center', width: '10%'},
          {name: 'userId', header: '관리자ID', align: 'center', width: '15%'},
          {name: 'authcd080', header: '인증코드', align: 'center', width: '10%'},
          {name: 'useYN', header: '사용여부', align: 'center', width: '10%', cls: 'td_line'},
          {name: 'regDt', header: '등록일', align: 'center', width: '15%'},
          {name: 'chgDt', header: '마지막 수정일', align: 'center', width: '15%', cls: 'td_line'}
        ],
        noDataStr: '검색 결과가 없습니다.',
        params: {
          searchType1: '',
          searchType2: 'custNm',
          searchText1: ''
        },
        excelHeader: []
      }
    };
  },
  components: {
    customGrid: customGrid,
    commonModal
  },
  created() {
    const getCondition = this.$store.getters['searchcondition/getSearchCondition'];
  },
  destroyed() {
    this.$store.commit('searchcondition/updateSearchCondition', {
      page: 1,
      perPage: 50,
      params: {
        searchType1: '',
        searchType2: '',
        searchText1: ''
      }
    });
  },
  mounted() {

    let page = 1;
    // 페이지 정보 및 검색 조건
    const getCondition = this.$store.getters['searchcondition/getSearchCondition'];

    // store에 저장된 페이지 정보 및 검색 조건을 불러오기
    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.grid.params.searchType1 = this.searchType1
      this.grid.params.searchType2 = this.searchType2
      this.$refs.table.search(this.grid.params, isKeep);
      this.sendStoreData();
    },
    sendStoreData: function () {
      const getP = this.$refs.table.getPagination();
      this.$store.commit('searchcondition/updateSearchCondition', {
        page: getP._currentPage,
        perPage: this.perPageCnt,
        params: {
          searchType1: '',
          searchType2: '',
          searchText1: ''
        }
      });

    },
    changePerPage: function () { 	// 페이지당 조회할 개수
      this.grid.pagePerRows = this.perPageCnt;
      this.search(true);
    },
  },

  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>