<template>
		<div class="contents">
			<div class="contents_wrap">
				<div class="top_wrap">
					<h3 class="title">청약고객관리</h3>
					<p class="breadcrumb">고객관리 &gt; 청약고객관리</p>
				</div>
				<div class="info">
					<div class="title">기본정보</div>
				</div>
				<div class="table table_form">
					<form autocomplete="off">
						<table>
						 <colgroup>
							<col style="width:140px">
							<col style="width:auto"> 
							<col style="width:auto">  
							<col style="width:140px"> 
							<col style="width:auto"> 
							<col style="width:auto"> 
						  </colgroup>
							<tbody>
								<tr class="tr_input w75">
									<th>고객사명</th>
									<td colspan="2"><input type="text" disabled v-model="custNm"></td>
								</tr>
								<tr class="tr_input w75">
									<th>대표자명</th>
									<td colspan="2"><input type="text" disabled v-model="reprNm"></td>
									<th class="center">사용자 구분</th>
									<td colspan="2"><input type="text" disabled v-model="custType"></td>
								</tr>
								<tr class="tr_input">
									<th>사업장 주소</th>
									   <td colspan="5">
										 <div class="input-address">
										  <input type="text" disabled v-model="adr1">
										  <input type="text" disabled v-model="adr2">
										  <input type="text" disabled v-model="adr3">
									     </div>
									  </td>
								</tr>
								<tr class="tr_input">
									<th>사업자등록번호</th>
									<td colspan="2">
										<div class="input-bnumber">
										 <input type="text" disabled v-model="bregNo1">
										 <input type="text" disabled v-model="bregNo2">
										 <input type="text" disabled v-model="bregNo3">
										</div>
									</td>
									<th class="center">법인등록번호</th>
									<td colspan="2">
										<div class="input-double">
										 <input type="text" disabled v-model="cprRegNo1">
										 <input type="text" disabled v-model="cprRegNo2">
										</div>
									</td>
								</tr>
							</tbody>
						</table>
					</form>
				</div>
				<div class="info">
					<div class="title">사용정보</div>
				</div>
				<div class="table table_form">
					<form autocomplete="off">
						<table>
						 <colgroup>
							<col style="width:140px">
							<col style="width:auto"> 
							<col style="width:auto">  
							<col style="width:140px"> 
							<col style="width:auto"> 
							<col style="width:auto"> 
						  </colgroup>
							<tbody>
								<tr class="tr_input w75">
									<th>가입일</th>
									<td colspan="2"><input type="text" disabled v-model="subsDt"></td>
									<th class="center">상태</th>
									<td class="center" colspan="2">
										<input type="text" disabled v-model="stat">
									</td>
								</tr>
								<tr class="tr_input w75">
									<th>요금제</th>
									<td colspan="2"><input type="text" disabled v-model="plan"></td>
									<th class="center">가입번호</th>
									<td colspan="2"><input type="text" disabled v-model="subsNo"></td>
								</tr>
								<tr class="tr_input w75">
									<th>관리자명</th>
									<td colspan="2">
										<div class="input-double">
										 <input type="text" v-model="adminId">
										 <input type="text" v-model="adminNm">
										 <button type="button" class="button grey btn-a" @click="searchIDPopOpen">변경</button>
										</div>
									</td>
									<th class="center">유치자명</th>
									<td colspan="2">
										<div class="input-double">
										 <input type="text" disabled v-model="channelId">
										 <input type="text" disabled v-model="channelNm">
										</div>
									</td>
								</tr>
							
							</tbody>
						</table>
					</form>
				</div>
				<div class="info">
					<div class="title">사용자 데이터</div>
				</div>
				<div class="table table_form">
					<form autocomplete="off">
						<table>
						 <colgroup>
							<col style="width:140px">
							<col style="width:auto"> 
							<col style="width:auto">  
							<col style="width:140px"> 
							<col style="width:auto"> 
							<col style="width:auto"> 
						  </colgroup>
							<tbody>
								<tr class="tr_input w75">
									<th>서비스 ID</th>
									<td colspan="2"><input type="text" disabled v-model="serviceId"></td>
									<th class="center">이용권한</th>
									<td colspan="2"><input type="text" disabled v-model="useAuth"></td>
								</tr>
								<tr class="tr_input w75">
									<th>사용자명</th>
									<td colspan="2"><input type="text" disabled v-model="userNm"></td>
									<th class="center">휴대폰 번호</th>
									<td colspan="2"><input type="text" disabled v-model="mdn"></td>
								</tr>
								<tr class="tr_input w75">
									<th>이월누적금액</th>
									<td colspan="2">
										<div class="input-double button-double">
										 <input type="text" disabled v-model="carryOver">
										 <button type="button" class="button grey" @click="carryOverListPopOpen();">이월금액보기</button>
										</div>
									</td>
									<th class="center">사용자ID 개수</th>
									<td colspan="2">
										<div class="input-double button-double">
										 <input type="text" disabled v-model="userCnt">
										 <button type="button" class="button grey">사용자ID 확인</button>
										</div>
									</td>
								</tr>
							</tbody>
						</table>
					</form>
				</div>
				<div class="pop-btn2">
					<button class="btn-default" type="button" @click="toComplete();">취소</button>
					<button class="btn-pcolor" type="button" @click="confirmPopOpen();">저장</button>
				</div>

				<!--이월금액 모달.-->
				<carry-Over-List-Pop ref="carryOverListPop"></carry-Over-List-Pop>
				<!--수정 확인 모달-->
				<validation-confirm-pop ref="validationConfirmPop"></validation-confirm-pop>
				<!--관리자명 조회 모달-->
				<admin-nm-pop ref="adminNmPop"></admin-nm-pop>				
			</div>

		</div>
	
</template>

<script>
import api from '@/service/api';
import custMgtApi from "../service/custMgtApi.js";
import CarryOverListPop from '../components/CarryOverListPop';
//import ConfirmPop from '@/components/modal/confirm';
import ValidationConfirmPop from '../components/ValidationConfirmPop';
//import SearchIDPop from '@/components/modal/searchID';
import AdminNmPop from '../components/AdminNmPop';

export default {
	name: "subsDetail",
	data(){
        return{
			row: {},
			custNm: '',	
			reprNm: '',
			custType: '',	
			adr1: '',
			adr2: '',	
			adr3: '',
			bregNo: '',
			bregNo1: '',
			bregNo3: '',
			bregNo2: '',	
			cprRegNo: '',
			cprRegNo1: '',
			cprRegNo2: '',	
			birth: '',
			subsDt: '',	
			stat: '',
			plan: '',	
			subsNo: '',	
			adminId: '',
			adminNm: '',
			bindDis: '',
			channelId: '',	
			channelNm: '',
			useAuth: '',
			userNm: '',
			mdn: '',
			carryOver: '',		
			userCnt: '',
			saveConfirm:false,
			props: {},
        }
    },
	props: {
		serviceId: {
			type: String,
			default: "",
		},
	},
	components: {
		CarryOverListPop,
		//ConfirmPop,
		//SearchIDPop,
		ValidationConfirmPop,
		AdminNmPop,
	},
	created(){
		this.$store.commit("login/isLogin", true);
    	this.$store.commit("login/isAuthChk", true);
		console.log(this.$route.params.serviceId);
		this.subsDetail(this.$route.params.serviceId);
		// checkVaildBizNum
    }, 
	methods :{
		doValidate(){
			// if(this.isNull(this.userId)){
			// 	alert("아이디를 입력해 주세요.");
			// 	this.$refs._userId.focus();
			// 	return false;
			// }
			return true;
		},
		// 저장 후 부모창 호출.
		toComplete(){
			this.row.searchType1 = '';
			this.row.searchType2= '';
			this.row.searchType3= '';
			this.row.searchText1= '';          
			this.row.startDt= '';
			this.row.endDt= '';
			this.row.page = 1;

			this.$router.push({ name: 'subsList', params: this.row });
        },
		async doInsert(props){
			
				console.log(props);
                // try {
				// 	const response = await custMgtApi.insertTestId(this.row);
				// 	const result = response.data;
				// 	if (result != null && result.retCode == "0000") {
				// 		alert('저장 하였습니다.');
				// 		this.toComplete();
				// 	}
                // } catch(err) {
                // 	alert("실패 하였습니다.");
                // }
            // }
        },
		async subsDetail(serviceId){
			this.row.serviceId = serviceId;
			try {
				const response = await custMgtApi.subsDetail(this.row);
				const result = response.data;
				console.log(result);
				if (result != null && result.retCode == "0000") {
					this.custNm = result.data.custNm;
					this.reprNm = result.data.reprNm;
					this.custType = result.data.custType;
					this.adr1 = result.data.adr1;
					this.adr2 = result.data.adr2;
					this.adr3 = result.data.adr3;
					this.bregNo = result.data.bregNo;
					this.cprRegNo = result.data.cprRegNo;
					this.birth = result.data.birth;
					this.subsDt = result.data.subsDt;
					this.stat = result.data.stat;
					this.plan = result.data.plan;
					this.subsNo = result.data.subsNo;
					this.adminId = result.data.adminId;
					this.adminNm = result.data.adminNm;
					this.bindDis = result.data.bindDis;
					this.channelId = result.data.channelId;
					this.channelNm = result.data.channelNm;
					this.serviceId = result.data.serviceId;
					this.useAuth = result.data.useAuth;
					this.userNm = result.data.userNm;
					this.mdn = result.data.mdn;
					this.carryOver = result.data.carryOver;
					this.userCnt = result.data.userCnt;
					if(this.bregNo != '' && this.bregNo != null){
						this.bregNo1 = this.bregNo.substr(0, 3);
						this.bregNo2 = this.bregNo.substr(3, 2);
						this.bregNo3 = this.bregNo.substr(5);
					}
					if(this.cprRegNo != '' && this.cprRegNo != null){
						this.cprRegNo1 = this.cprRegNo.substr(0, 6);
						this.cprRegNo2 = this.cprRegNo.substr(6);
					}
				}
			} catch (error) {
				alert("실패 하였습니다.");
			}

		},
		// updateAdminInfo 청약고객-사용정보-관리자ID,관리자명 수정
		async updateAdminInfo() {
			this.row.serviceId = this.$route.params.serviceId;
			this.row.adminId = this.adminId;
			this.row.adminNm = this.adminNm;

			try {
				const response = await custMgtApi.updateAdminInfo(this.row);
				const result = response.data;
				console.log(result);
				if (result != null && result.retCode == "0000") {
					alert('저장 하였습니다.');
					this.toComplete();
				} else {
					alert("실패 하였습니다.");
				}
			} catch (error) {
				alert("실패 하였습니다.");
			}

		},
		carryOverListPopOpen: function(){
			this.$refs.carryOverListPop.carryOverListPopOpen(this.serviceId);
		},
		confirmPopOpen: function(){
			if(this.doValidate()){
				// this.row.title = '사용자 수정 확인';
				// this.row.msg = '변경된 내용을 저장하시겠습니까?';
				// console.log(this.row);
				// this.$refs.confirmPop.confirmModalOpen(this.row);
				this.$refs.validationConfirmPop.confirmUpdateOpen();
			}
			
		},
		confirmCalbackFnc: function(props){
			console.log(props);
			if(props.result){
				this.doInsert(props.result);
			}
		},
		searchIDPopOpen: function(){
			this.$refs.adminNmPop.ModalOpen();			
		},
		searchIDCalbackFnc: function(props){
			console.log(props);
			if(props.result){
				this.doInsert(props.result);
			}
		},
	}
}



</script>