<template>
 
		<div class="contents">
			<div class="contents_wrap">
				<div class="top_wrap">
					<h3 class="title">발신번호 차단</h3>
					<p class="breadcrumb">리스크관리 &gt; 발신번호 차단</p>
				</div>
				<form autocomplete="off" class="search_form">
					<div class="search_wrap">
						<div class="group">
							<div class="input_box">
								<label for="regId" class="label">등록자</label>
								<input class="search-box" type="text" id="search" placeholder="검색어 입력" v-model="grid.params.regId" v-on:keydown.enter.prevent="search"/>
							</div>
							<div class="select_box">
								<label for="blckRsnCd" class="label">차단사유</label>
								<select name="" id="blckRsnCd" v-model="grid.params.blckRsnCd" @keyup="search">
									<option value="" selected>전체</option>
									<option value="">일반</option>
									<option value="">대출</option>
									<option value="">의약품</option>
									<option value="">도박</option>
									<option value="">스미싱</option>
									<option value="">기타</option>
								</select>
							</div>
						</div>
						<div class="group">
							<div class="select_box">
								<label for="right" class="label">차단여부</label>
								<select name="" id="" v-model="grid.params.blckYn">
									<option value="" selected>전체</option>
									<option value="">차단</option>
									<option value="">해제</option>
								</select>
							</div>
							<div class="select_box">
								<label for="right" class="label">발송타입</label>
								<select name="" id="" v-model="grid.params.sndblckTpCd">
									<option value="" selected>전체</option>
									<option value="">공용</option>
									<option value="">문자</option>
									<option value="">RCS</option>
								</select>
							</div>
							<div class="input_box">
								<label for="right" class="label">발신번호</label>
                            	<input class="search-box" type="text" id="search" placeholder="검색어 입력" v-model="grid.params.blcksndrno">
						    </div>
							<button type="button" class="button grey" @click="search">조회</button>
						</div>
					</div>
				</form>
				<div class="info">
					<div class="count">총 <span>{{ totalItems }}</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 class="button_group">
						<button type="button" class="button blue add" @click="ModalOpen()">신규등록</button>
					</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>
            <insert-intrcp-pop ref="insertIntrcpPop"> </insert-intrcp-pop>
            <intrcp-detail-popup ref="intrcpDetailPopup"></intrcp-detail-popup>
			</div>
		</div>
</template>

<script>
import customGrid from '@/components/CustomGrid';
import api from '@/service/api.js';
import intrcpDetailPopup from '../components/IntrcpDetailPopup';
import insertIntrcpPop from '../components/InsertIntrcpPop';
//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);
        });
    }
}

export default {
  name: 'intrcpList',
  data() {
    return {
      totalItems: 0,
      perPageCnt: 50,
      options: [
        { text: '20', value: 20},
        { text: '50', value: 50},
        { text: '100', value: 100}
      ],
      grid: {
        url: '/api/v1/bo/riskMgt/sendNum/intrcpList',
        perPage: 20,
        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: 50 },
          { name: 'blcksndrno', header: '발신번호', align: 'center', width: 160, 
          renderer: { type: CustomATagRenderer, options: { callback: this.inDetailPop} } },
          { name: 'blckYn', header: '차단여부', align: 'center', width: 100},
          { name: 'sndblckTpCd', header: '발송타입', align: 'center', width: 100},
          { name: 'lastChgDt', header: '최근수정일', align: 'center', width: 100},      
          { name: 'blckRsnCd', header: '차단사유', width: 100, cls: 'td_line' },
          { name: 'regId', header: '등록자', width: 150 }
        ],
        noDataStr: '검색 결과가 없습니다.',        
        params: {
          regId: '',
          blckRsnCd: '',
          blckYn: '',
          sndblckTpCd: '',
          blcksndrno: ''
        },
        excelHeader: []
      }    
    };
  },  
  components: {
    customGrid: customGrid,
    intrcpDetailPopup,
    insertIntrcpPop
  },
  destroyed() {
     
  },
   created(){
    this.$store.commit("login/isLogin", true);
    this.$store.commit("login/isAuthChk", true);
    this.setCodeData();
    // this.formReset();
  },
  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) {
      console.log(this.grid.params);
      this.$refs.table.search(this.grid.params, isKeep);
      this.sendStoreData();
    },
    sendStoreData: function() {
      const getP = this.$refs.table.getPagination();
      console.log("==========getP : " + getP._currentPage);
      this.$store.commit('searchcondition/updateSearchCondition', {
        page: getP._currentPage,        
        perPage: this.perPageCnt,        
        params: this.grid.params
      });

      const getCondition = this.$store.getters['searchcondition/getSearchCondition'];
      console.log("getCondition : "+ getCondition.perPage);
    },
    setCodeData() {
      // 상태 옵션 셋팅.
      api.commCode({'grpCd' : 'SVCUSER_STTUS_CD'}).then(response => {
        this.statType = response.data.data.list;
      });
      // 
      api.commCode({'grpCd' : 'SVCUSER_TP_CD'}).then(response => {
        this.userType = response.data.data.list;
      });
    },
    ModalOpen: function(){      
      this.$refs.insertIntrcpPop.ModalOpen();
    },
    inDetailPop(props) {
      this.$refs.intrcpDetailPopup.IntrcpDetailModalOpen(props);
    },
    // formReset(){
		// 	var type= this.insertType;
		// 	Object.assign(this.$data, this.$options.data());
		// 	this.insertType = type;
		// },
    
  },
  beforeRouteLeave(to, from, next) {
	
	const getP = this.$refs.table.getPagination();
	console.log("==========getP : " + getP._currentPage);
	this.$store.commit('searchcondition/updateSearchCondition', {
	  page: getP._currentPage,        
	  perPage: this.perPageCnt,        
	  params: this.grid.params
	});  
	// 라우트 하기전 실행 
	next();
  }
};
</script>
