/* 페이징 관련 변수 */
let membershipTotalCount = 0;
let membershipTotalPages = 0;

/*aggird*/
let membershipAgGridData = [];
var userData = [];
let membershipSelectedId   = "";

/****************************************************************************
 * 멤버십 고객 상세 리스트 조회
 ****************************************************************************/
function fn_selectListHistoryJson(){
    let formData = new FormData();
    formData.append("menuClass", menuClass);
    formData.append("membershipSort", membershipSort);
    formData.append("membershipDir", membershipDir);
    formData.append("membershipStart", membershipStart);
    formData.append("membershipLimit", membershipLimit);
    formData.append("muTreatmentId", muTreatmentId);
    formData.append("treatmentName", treatmentName);
    formData.append("usedType", usedType);
    formData.append("membershipSearchStartDate", membershipSearchStartDate);
    formData.append("membershipSearchEndDate", membershipSearchEndDate);
    formData.append("membershipSearchDateType", membershipSearchDateType);
    formData.append("muUserId", muUserId);

    $.ajax({
        url: encodeURI('/webmembership/selectListMembershipHistory.do'),
        data: formData,
        dataType: "json",
        processData: false,
        contentType: false,
        type: 'POST',
        async: true,
        success: function(data){
            if('0'==data.msgCode){
                membershipTotalCount = data.totalCount;
                userData = data.totalMembershipHistoryInfo[0];
                document.getElementById('userName').textContent = userData.userName;
                document.getElementById('birth').textContent = userData.birth;
                document.getElementById('age').textContent = `${userData.age??'-'}세`;
                document.getElementById('gender').textContent = userData.gender;
                document.getElementById('nationality').textContent = userData.nationality;
                document.getElementById('membershipBalance').textContent = userData.membershipBalance + ' 원';

                let sumChargeBalance = (userData.sumChargeBalance !== '0' ? '+' : '') + userData.sumChargeBalance + ' 원'
                let sumUsageBalance = (userData.sumUsageBalance !== '0' ? '-' : '') + userData.sumUsageBalance + ' 원'

                document.getElementById('sumChargeBalance').textContent = sumChargeBalance;
                document.getElementById('sumUsageBalance').textContent = sumUsageBalance;
                // 페이징 처리
                membershipTotalPages = Math.ceil(membershipTotalCount / membershipLimit);

                // 리스트 조회
                membershipAgGridData = data.rows.map((item, index) => ({
                    ...item,
                    rowNum: index + 1
                }));
                membershipGridOptions.api.setRowData(membershipAgGridData);

                if (0 < data.rows.length) {
                    //페이징 처리
                    window.pagObj = $('#membershipPagination').twbsPagination({
                        startPage: ((membershipStart / membershipLimit) + 1),
                        totalPages: (membershipTotalPages == 0) ? 1 : membershipTotalPages,
                        visiblePages: 10,
                        initiateStartPageClick: false,
                        prev: '<img src="/image/web/page_navigation_arrow.svg" alt="prev"/>',
                        next: '<img src="/image/web/page_navigation_arrow.svg" alt="next"/>',
                        first: '',
                        last: '',
                        onPageClick: function (event, page) {
                            fn_membershipPagination(page);
                        }
                    }).on('page', function (event, page) {
                        //console.info(page + ' (from event listening)');
                    });
                } else {

                }
            }
            else{
                modalEvent.danger("조회 오류", data.msgDesc);
            }
        },
        error : function(xhr, status, error) {
            modalEvent.danger("조회 오류", "조회 중 오류가 발생하였습니다. 잠시후 다시시도하십시오.");
        },
        beforeSend:function(){
            // 로딩열기
            membershipGridOptions.api.showLoadingOverlay();
        },
        complete:function(){

        }
    });
}

/****************************************************************************
 * 검색하기
 ****************************************************************************/
function fn_membershipSearch(param){
    if("A"!=param && "Y"!=selectUseYn){
        modalEvent.warning("", "조회 권한이 없습니다.");
        return false;
    }

    fn_membershipPaginReset();

    membershipSearchDateType  = $("#membershipSearchDateType").val();
    membershipSearchStartDate = $("#membershipSearchStartDate").val();
    membershipSearchEndDate   = $("#membershipSearchEndDate").val();

    usedType                = $("#usedType").val();
    muTreatmentId           = $("#muTreatmentId").val();
    treatmentName           = $("#muTreatmentId").siblings('button').text();


    fn_selectListHistoryJson();
}


/****************************************************************************
 * 초기화하기
 ****************************************************************************/
function fn_membershipReset(){

    fn_membershipSearch();
}

/****************************************************************************
 * 페이징 처리
 ****************************************************************************/
function fn_membershipPagination(param){
    membershipStart = (parseInt(param)-1)*membershipLimit;

    fn_selectListHistoryJson();
}

/****************************************************************************
 * 페이징 리셋
 ****************************************************************************/
function fn_membershipPaginReset(){

    membershipStart        = 0;
    membershipLimit        = 100;
    membershipTotalCount   = 0;
    membershipTotalPages   = 0;

    //페이징 초기화
    if($("#membershipPagination").data("twbs-pagination")){
        $("#membershipPagination").twbsPagination("destroy");
    }
}

/****************************************************************************
 * 검색 엔터 이벤트
 ****************************************************************************/
function fn_membershipEnter(e){
    if(e.which){
        // 파이어폭스
        if(13 == e.which) {
            //로그인 액션 스크립트
            fn_membershipSearch();
        }
    }
    else{
        // 윈도우, 사파리, 크롬
        if(13 == event.keyCode) {
            //로그인 액션 스크립트
            fn_membershipSearch();
        }
    }
}
/****************************************************************************
 * 진료구분 검색필터 세팅
 ****************************************************************************/
function setTreatmentOption(data){
    const ulElement = document.getElementById('treatmentList');

    data.forEach(treatment => {
        const liElement = document.createElement('li');
        liElement.className = 'option_list_item';
        liElement.textContent = treatment.treatmentName;
        liElement.id = treatment.muTreatmentId;

        ulElement.appendChild(liElement);
    });
}
/****************************************************************************
 * 완료
 ****************************************************************************/
function fn_membershipOk(){
    fn_membershipReset();
}

/****************************************************************************
 * 수정 화면으로 이동.
 ****************************************************************************/
function fn_updateMembershipIntro(param){
    if("Y"==updateUseYn){
        // 수정가능
        let pagingParam = "?menuClass="+menuClass;
        pagingParam    += "&membershipSearchKeywordParam="+membershipSearchKeywordParam;
        pagingParam    += "&membershipSort="+membershipSort;
        pagingParam    += "&membershipDir="+membershipDir;
        pagingParam    += "&membershipStart="+membershipStart;
        pagingParam    += "&membershipLimit="+membershipLimit;
        pagingParam    += "&muMemberId="+param;

        fn_leftFormAction("/webmembership/updateMembershipIntro.do"+pagingParam);
    }
    else{
        modalEvent.warning("", "조회 및 수정 권한이 없습니다.");
        return false;
    }
}

/****************************************************************************
 * 엑셀 다운 다운로드
 ****************************************************************************/
function fn_downloadMembershipExcel(){
    if("Y"==downloadUseYn){
        // 수정가능
        let pagingParam = "?menuClass="+menuClass;
        pagingParam    += "&membershipSort="+membershipSort;
        pagingParam    += "&membershipDir="+membershipDir;
        pagingParam    += "&membershipStart="+membershipStart;
        pagingParam    += "&membershipLimit="+membershipLimit;
        pagingParam    += "&membershipSearchStartDate="+membershipSearchStartDate;
        pagingParam    += "&membershipSearchEndDate="+membershipSearchEndDate;
        pagingParam    += "&membershipSearchDateType="+membershipSearchDateType;
        pagingParam    += "&muTreatmentId="+muTreatmentId;
        pagingParam    += "&usedType="+usedType;
        pagingParam    += "&muUserId="+muUserId;
        let url = encodeURI("/webmembership/downloadMembershipHistoryExcel.do"+pagingParam);
        $("#excelForm").prop("action",url);
        $("#excelForm").submit();
    }
    else{
        modalEvent.warning("", "내려받기 권한이 없습니다.");
        return false;
    }
}

function fn_treatmentName(params){
    if(!params.value){
        return '-'
    }
    return params.value;
}
function fn_procedureName(params){
    if(!params.value){
        return params.data.procedureName
    }
    return params.value;
}
function formatUsedAmount(params) {
    if (params.value) {
        return '-'+params.value.toLocaleString();
    }
    return '';
}

function formatRechargeAmount(params) {
    if (params.value) {
        return '+' + params.value.toLocaleString();
    }
    return '';
}

let membershipColumnDefs = [
    {field: "rowNum", headerName:"번호", minWidth:60,sortable: false, cellStyle:{textAlign: 'center'}},
    {field: "writeDate", headerName:"날짜", minWidth: 100, maxWidth: 100},
    {field: "treatmentName", headerName:"진료유형", minWidth:100, maxWidth:100, valueFormatter:fn_treatmentName },
    {field: "procedureName", headerName:"시술(상품)명", minWidth:300, valueFormatter:fn_procedureName},
    {field: "reserveMemberNm", headerName:"담당의사", minWidth:120, maxWidth:120},
    {field: "muMemberNm", headerName:"담당자", minWidth:120, maxWidth:120},
    {field: "usedAmount", headerName:"멤버십 사용금액", minWidth:135, maxWidth:135, valueFormatter: formatUsedAmount,cellStyle:{textAlign: 'right'}},
    {field: "rechargeAmount", headerName:"멤버십 충전금액", minWidth:135, maxWidth:135, valueFormatter: formatRechargeAmount,cellStyle:{textAlign: 'right'}},
    {field: "memo", headerName:"결제메모", minWidth:409},
    {
        field: "usageType",
        headerName:"사용구분",
        minWidth:100,
        maxWidth:100,
        cellStyle: params => {
            if (params.value === '양도' || params.value === '양수') {
                return { cursor: 'pointer', color: '#3985EA' };
            }
            return null;
        }
    }
];

// let the grid know which columns and what data to use
let membershipGridOptions = {
    suppressRowTransform: true,
    columnDefs: membershipColumnDefs,
    defaultColDef: {                  // 리스트 기본 설정
        flex: 1,
        sortable: true,               //정렬 여부
        resizable: true,              //리사이즈
        editable: true,               // 그리드에서 데이터 수정
        cellStyle:{textAlign:'left',fontSize:'14px',padding:'0'},
        //suppressSizeToFit:true,     //자동 맞춤
        //enableRowGroup: true,       // 그룹 묶음
        enablePivot: true,
        enableValue : true
    },
    //suppressMultiSort:true,         //단일솔트 true가 단일, false가 다중 shift + sort 시
    headerHeight : 41,                // header 높이
    rowHeight : 41,                   // row 높이
    rowData : membershipAgGridData,
    suppressRowClickSelection : true, // 로우 클릭시 체크박스 선택 true no, false yes
    localeText : {
        noRowsToShow : '조회 결과가 없습니다.'
    }, //데이터 없을 시 나오는 문구
    rowSelection : 'multiple',        // row 다중 선택
    debug : false,
    onCellClicked: function(event){   //셀 클릭 이벤트
        /* alert(event.column.colId); */
        if('usageType'==event.column.colId){
            fn_selectMembershipTransferPop(event.data.muMembershipHistoryId);
        }
    },
    onSelectionChanged: function(event){ //체크박스 선택
        let selectRows = [];
        selectRows = event.api.getSelectedRows();

        membershipSelectedId = '';
        for(let i=0; i<selectRows.length; i++){
            membershipSelectedId += selectRows[i].muMemberId + ",";
        }
        membershipSelectedId = membershipSelectedId.substring(0, membershipSelectedId.lastIndexOf(','));
    },
    onSortChanged: function(event){
        //정렬
        membershipSort = ''; //기존 정렬 초기화
        let columnArr = event.columnApi.getColumnState();
        if(0<columnArr.length){
            //sort index 순으로 재정렬
            columnArr.sort(function(a,b){
                return a.sortIndex - b.sortIndex;
            });

            let nullCnt = 0;
            for(let i=0; i<columnArr.length; i++){
                let gridSortModel = columnArr[i].colId;
                let gridSort = columnArr[i].sort;

                if(gridSort != null){
                    membershipStart = 0;
                    membershipSort += gridSortModel+' '+ gridSort + ',';
                }
                else{
                    nullCnt++;

                    if(nullCnt == columnArr.length){
                        membershipSort  = '';
                        membershipDir   = '';
                        membershipStart = 0;
                    }
                }
            }
        }
        membershipSort = membershipSort.substring(0,membershipSort.lastIndexOf( ",")); //맨끝 콤마 지우기

        fn_membershipSearch();
    }
};

// lookup the container we want the Grid to use
let membershipHistoryGridDiv = document.querySelector('#membershipHistoryGrid');

// create the grid passing in the div to use together with the columns & data we want to use
new agGrid.Grid(membershipHistoryGridDiv, membershipGridOptions);

/****************************************************************************
 * 옵션선택
 ****************************************************************************/
function fn_OptionSelection(target,e) {
    // 옵션 선택 이벤트 핸들러
    $(target).closest('.select_box').find('.label').text( $(target).text());
    $(target).closest('.select_box').find('input').val($(target).attr('id')??$(target).text());
    // $(target).closest('.select_box').find('.option_list_item').removeClass('selected');
    // $(target).addClass('selected');
    // $(target).closest('.select_option_list').hide();
    // e.stopPropagation();

}
/****************************************************************************
 * select box 선택 이벤트
 ****************************************************************************/
function fn_clickSelectBox(target) {
    $(target).find('.select_option_list').toggle();
}

function fn_clickEvent() {
    // $('.select_box').off('click');
    //$(document).off('click');

    // $('.select_box').on('click', function () {
    //     fn_clickSelectBox($(this));
    //     $('.select_box').not(this).find('.select_option_list').hide();
    // });
    // 옵션 선택 이벤트
    $('.select_box').on('click', 'li', function (e) {
        fn_OptionSelection($(this), e);
    });

// 다른 곳을 클릭했을 때 옵션 숨기기
//     $(document).on('click', function (event) {
//         if (!$(event.target).closest('.select_box').length) {
//             $('.select_option_list').hide();
//         }
//     });
}
/****************************************************************************
 * 검색 날짜 설정
 //(A:오늘, B:3일, C:7일, D:최근30일, E:최근90일, F:이번달, G:올해, H:지난주, I:지난달)
 ****************************************************************************/
function fn_membershipSetDate(param){
    if("A"==param){
        // 오늘
        let toDate = new Date();
        let year  = toDate.getFullYear();
        let month = toDate.getMonth() + 1;
        let day   = toDate.getDate();

        if(month < 10) month = "0" + month;
        if(day < 10) day = "0" + day;

        membershipSearchStartDate = year+'-'+month+'-'+day;
        membershipSearchEndDate   = year+'-'+month+'-'+day;
    }
    else if("B"==param){
        // 3일
        // 검색 종료일자
        let toDate = new Date();
        let year  = toDate.getFullYear();
        let month = toDate.getMonth() + 1;
        let day   = toDate.getDate();

        if(month < 10) month = "0" + month;
        if(day < 10) day = "0" + day;

        membershipSearchEndDate   = year+'-'+month+'-'+day;

        // 검색 시작일자
        toDate.setDate(toDate.getDate() - 3);
        year  = toDate.getFullYear();
        month = toDate.getMonth() + 1;
        day   = toDate.getDate();

        if(month < 10) month = "0" + month;
        if(day < 10) day = "0" + day;

        membershipSearchStartDate = year+'-'+month+'-'+day;
    }
    else if("C"==param){
        // 이번주
        // 검색 종료일자
        let toDate = new Date();
        let year  = toDate.getFullYear();
        let month = toDate.getMonth() + 1;
        let day   = toDate.getDate();

        if(month < 10) month = "0" + month;
        if(day < 10) day = "0" + day;

        membershipSearchEndDate   = year+'-'+month+'-'+day;

        // 검색 시작일자
        toDate.setDate(toDate.getDate() - 7);
        year  = toDate.getFullYear();
        month = toDate.getMonth() + 1;
        day   = toDate.getDate();

        if(month < 10) month = "0" + month;
        if(day < 10) day = "0" + day;

        membershipSearchStartDate = year+'-'+month+'-'+day;
    }
    else if("D"==param){
        // 최근30일
        let toDate = new Date();
        let year  = toDate.getFullYear();
        let month = toDate.getMonth() + 1;
        let day   = toDate.getDate();

        if(month < 10) month = "0" + month;
        if(day < 10) day = "0" + day;

        //최근30일
        toDate.setDate(toDate.getDate() - 30);
        startYear  = toDate.getFullYear();
        startMonth = toDate.getMonth() + 1;
        startDay   = toDate.getDate();

        if(startMonth < 10) startMonth = "0" + startMonth;
        if(startDay < 10) startDay = "0" + startDay;

        membershipSearchStartDate = startYear+'-'+startMonth+'-'+startDay;
        membershipSearchEndDate   = year+'-'+month+'-'+day;

    }
    else if("E"==param){
        // 최근90일
        // 검색 종료일자
        let toDate = new Date();
        let year  = toDate.getFullYear();
        let month = toDate.getMonth() + 1;
        let day   = toDate.getDate();

        if(month < 10) month = "0" + month;
        if(day < 10) day = "0" + day;

        membershipSearchEndDate   = year+'-'+month+'-'+day;

        // 검색 시작일자
        toDate.setDate(toDate.getDate() - 90);
        year  = toDate.getFullYear();
        month = toDate.getMonth() + 1;
        day   = toDate.getDate();

        if(month < 10) month = "0" + month;
        if(day < 10) day = "0" + day;

        membershipSearchStartDate = year+'-'+month+'-'+day;
    }
    else if("F"==param){
        //F:이번달
        // 검색 종료일자
        let toDate = new Date();
        let year  = toDate.getFullYear();
        let month = toDate.getMonth() + 1;
        let day   = toDate.getDate();

        if(month < 10) month = "0" + month;
        if(day < 10) day = "0" + day;

        membershipSearchEndDate   = year+'-'+month+'-'+day;

        // 검색 시작일자
        membershipSearchStartDate = year+'-'+month+'-01';
    }
    else if("G"==param){
        // G:올해
        // 검색 종료일자
        let toDate = new Date();
        let year  = toDate.getFullYear();
        let month = toDate.getMonth() + 1;
        let day   = toDate.getDate();

        if(month < 10) month = "0" + month;
        if(day < 10) day = "0" + day;

        membershipSearchEndDate   = year+'-'+month+'-'+day;
        // 검색 시작일자
        membershipSearchStartDate = year+'-01-01';
    }
    else if("H"==param){
        // H:지난주, I:지난달
        // 검색 종료일자
        let toDate = new Date();
        let startDate = new Date(toDate.getFullYear(), toDate.getMonth(), toDate.getDate() - toDate.getDay() - 6); // 지난주 월요일
        let endDate = new Date(toDate.getFullYear(), toDate.getMonth(), toDate.getDate() - toDate.getDay()); // 지난주 일요일

        // 종료일자 설정
        let year = endDate.getFullYear();
        let month = endDate.getMonth() + 1; // JS의 getMonth()는 0부터 시작하므로 +1
        let day = endDate.getDate();

        month = month < 10 ? '0' + month : month;
        day = day < 10 ? '0' + day : day;

        membershipSearchEndDate = year + '-' + month + '-' + day;

        // 시작일자 설정
        year = startDate.getFullYear();
        month = startDate.getMonth() + 1;
        day = startDate.getDate();

        month = month < 10 ? '0' + month : month;
        day = day < 10 ? '0' + day : day;

        membershipSearchStartDate = year + '-' + month + '-' + day;
    }
    else if("I"==param){
        // I:지난달
        // I: 지난달
        let currentDate = new Date();
        let currentYear = currentDate.getFullYear();
        let currentMonth = currentDate.getMonth();

        // 지난달의 첫째 날
        let firstDayOfLastMonth = new Date(currentYear, currentMonth - 1, 1);
        let year = firstDayOfLastMonth.getFullYear();
        let month = firstDayOfLastMonth.getMonth() + 1; // JS는 월을 0부터 시작하므로 +1
        let day = firstDayOfLastMonth.getDate();

        month = month < 10 ? '0' + month : month;
        day = day < 10 ? '0' + day : day;

        membershipSearchStartDate = year + '-' + month + '-' + day;

        // 지난달의 마지막 날
        let lastDayOfLastMonth = new Date(currentYear, currentMonth, 0);
        year = lastDayOfLastMonth.getFullYear();
        month = lastDayOfLastMonth.getMonth() + 1;
        day = lastDayOfLastMonth.getDate();

        month = month < 10 ? '0' + month : month;
        day = day < 10 ? '0' + day : day;

        membershipSearchEndDate = year + '-' + month + '-' + day;
    }

    $("#membershipSearchStartDate").val(membershipSearchStartDate).trigger("change");
    $("#membershipSearchEndDate").val(membershipSearchEndDate).trigger("change");
}
/****************************************************************************
 * 멤버십양도 팝업
 ****************************************************************************/
function fn_insertMembershipTransferPop() {
    if ("Y" != insertUseYn) {
        modalEvent.warning("", "등록 권한이 없습니다.");
        return false;
    }

    let reqParam = {"userData":userData};
    membershipTransferInsertModal.popup(function (obj, reqParam) {
        fn_membershipOk();
    }, reqParam);
}
/****************************************************************************
 * 멤버십양도 조회
 ****************************************************************************/
function fn_selectMembershipTransferPop(muMembershipHistoryId) {
    if ("Y" != selectUseYn) {
        modalEvent.warning("", "조회 권한이 없습니다.");
        return false;
    }

    let reqParam = {"muMembershipHistoryId":muMembershipHistoryId};
    membershipTransferSelectModal.popup(function (obj, reqParam) {
        fn_membershipOk();
    }, reqParam);
}
/****************************************************************************
 * 멤버십포인트 적립 팝업
 ****************************************************************************/
function fn_membershipPointPop() {
    if ("Y" != insertUseYn) {
        modalEvent.warning("", "등록 권한이 없습니다.");
        return false;
    }

    let reqParam = {"userData":userData};
    membershipPointModal.popup(function (obj, reqParam) {
        fn_membershipOk();
    }, reqParam);
}
/****************************************************************************
 * 멤버십충전 팝업
 ****************************************************************************/
function fn_membershipChargePop() {
    if ("Y" != insertUseYn) {
        modalEvent.warning("", "등록 권한이 없습니다.");
        return false;
    }

    let reqParam = {"userData":userData};
    membershipChargeInsertModal.popup(function (obj, reqParam) {
        fn_membershipOk();
    }, reqParam);
}
/****************************************************************************
 * 정렬 이벤트
 ****************************************************************************/
function fn_alignEvent(param, param2){
    let align = "";

    if("A"==param){
        align = "오늘";

        fn_membershipSetDate('A');
    }
    else if("B"==param){
        align = "최근30일";

        fn_membershipSetDate('D');
    }
    else if("C"==param){
        align = "최근90일";

        fn_membershipSetDate('E');
    }
    else if("D"==param){
        align = "이번주";

        fn_membershipSetDate('C');
    }
    else if("E"==param){
        align = "이번달";

        fn_membershipSetDate('F');
    }
    else if("F"==param){
        align = "올해";

        fn_membershipSetDate('G');
    }
    else if("G"==param){
        align = "지난주";

        fn_membershipSetDate('H');
    }
    else if("H"==param){
        align = "지난달";

        fn_membershipSetDate('I');
    }
    else{
        align = "";
    }
    $("#membershipSearchDateType").val(param);
    $("#membershipSearchDateType").siblings("button").text(align);
}
/****************************************************************************
 * 페이지 init
 ****************************************************************************/
function fn_pageInit(){

    // 날짜 datepicker
    fn_searchDatePicker("#divMembershipSearchStartDate", "#divMembershipSearchEndDate");

    if(!membershipSearchDateType){
        $("#li_F").click();
    }else{
        fn_alignEvent(membershipSearchDateType);
    }

    fn_membershipSearch("A");

    if('080102'===menuClass)
        $('.left_box .back').show();
    else
        $('.left_box .back').hide();
}

/****************************************************************************
 * 페이지 event
 ****************************************************************************/
function fn_pageEvent(){
    let treatmentOption = fn_selectListTreatmentOption2();
    setTreatmentOption(treatmentOption);
    fn_clickEvent();
    // 검색 조회 버튼
    $("#btnSearchMembership").click(function () {
        fn_membershipSearch();
    });

    // 엑셀다운
    $("#btnDownloadMembershipExcel").click(function () {
        fn_downloadMembershipExcel();
    });
    $("#btnTransfer").click(function () {
        fn_insertMembershipTransferPop();
    });
    $("#btnPoint").click(function () {
        fn_membershipPointPop();
    });
    $("#btnCharge").click(function () {
        fn_membershipChargePop();
    });

    // 기간 선택 콤보 이벤트
    const target = $("#membershipSearchDateType").siblings("ul.select_option_list");
    target.find("li.option_list_item").click(function (){
        let selectIdArr = $(this).prop("id").split('_');
        let selectId    = selectIdArr[1];
        let selectName  = $(this).text();

        $(this).parent().siblings("button").text(selectName);
        $(this).parent().siblings("input").val(selectId);

        fn_alignEvent(selectId);
    });
}

$(function(){
    // 페이지 init
    fn_pageInit();

    // 페이지 event
    fn_pageEvent();
});