menu.ejs 21.5 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437
<%- include('./header.ejs') %>

            <!-- Header-->
            <header class="py-5">
                <div class="container px-5">
                    <div class="row justify-content-center">
                        <div class="col-lg-8 col-xxl-6">
                            <div class="text-center my-5">
                                <h1 class="fw-bolder mb-3">휴게소 메뉴 정보</h1>
                                <p class="lead fw-normal text-muted mb-4">Just search the name of the rest stop,<br>You'll find out what kind of food there is at the rest area.</p>
                                
                                <div class="dropdown">
                                
                                    <button class ="btn btn-primary dropdown-toggle " id="highway" data-bs-toggle="dropdown">
                                        고속도로 선택
                                    </button>
                                    <div class ="dropdown-menu">
                                        <a class="dropdown-item" onclick="addReststop('0010')">경부선</a>
                                        <a class="dropdown-item" onclick="addReststop('0550')">중앙선</a>
                                        <a class="dropdown-item" onclick="addReststop('0500')">영동선</a>
                                    </div>
                                    <button class ="btn btn-primary dropdown-toggle " id = "rest_stop" data-bs-toggle="dropdown">
                                        휴게소 선택
                                    </button>
                                    <div class ="dropdown-menu" id = "select_restStop">
                                    </div>
                                </div>
                                <!--<input type="text" placeholder="내용을 입력하세요" id="menuname"><input type="button"  onclick="Showmenu()" value="확인">-->
                                </a>
                            </div>
                        </div>
                    </div>
                </div>
            </header>

            <!--추천메뉴-->
            <section class="py-5 bg-light">
                <div class="container px-2 my-2">
                    <div class="text-center">
                        <h2 class="fw-bolder">추천메뉴</h2>
                        <p class="lead fw-normal text-muted mb-5">Recommend the menu you can eat at the rest stop</p>
                    </div>
                    <div class="row gx-5 row-cols-1 row-cols-sm-2 row-cols-xl-4 justify-content-center">
                        <div class="col mb-5 mb-5 mb-xl-0">
                            <div class="text-center">
                                <img class="img-fluid rounded-circle mb-4 px-4" src="https://dummyimage.com/150x150/ced4da/6c757d" alt="..." />
                                <h5 class="fw-bolder"><recommend1></recommend1></h5>
                                <div class="fst-italic text-muted"><rec1></rec1></div>
                            </div>
                        </div>
                        <div class="col mb-5 mb-5 mb-xl-0">
                            <div class="text-center">
                                <img class="img-fluid rounded-circle mb-4 px-4" src="https://dummyimage.com/150x150/ced4da/6c757d" alt="..." />
                                <h5 class="fw-bolder"><recommend2></recommend2></h5>
                                <div class="fst-italic text-muted"><rec2></rec2></div>
                            </div>
                        </div>
                        <div class="col mb-5 mb-5 mb-sm-0">
                            <div class="text-center">
                                <img class="img-fluid rounded-circle mb-4 px-4" src="https://dummyimage.com/150x150/ced4da/6c757d" alt="..." />
                                <h5 class="fw-bolder"><recommend3></recommend3></h5>
                                <div class="fst-italic text-muted"><rec3></rec3></div>
                            </div>
                        </div>
                            </div>
                        </div>
                    </div>
                </div>
            </section>


            <!--menu1-->  
            <section class="py-3">
                <div class="container px-0.1 my-0.1">
                    <div class="text-center">
                        <h4 class="fw-bolder"> <menu1></menu1></h4>
                </div>
            </section>  
            
            <section class="py-5 bg-light" id="scroll-target">
                <div class="container px-2 my-2">
                    <div class="text-center">
                        <h2 class="fw-bolder"><foodname1></foodname1></h2>
                        <p class="lead fw-normal text-muted mb-0"><foodcost1></foodcost1></p>
                    </div>
                </div>
            </section>


            <!--menu2-->
            <section class="py-3">
                <div class="container px-0.1 my-0.1">
                    <div class="text-center">
                        <h4 class="fw-bolder"> <menu2></menu2></h4>
                </div>
            </section>  

            <section class="py-5 bg-light" id="scroll-target">
                <div class="container px-2 my-2">
                    <div class="text-center">
                        <h2 class="fw-bolder"><foodname2></foodname2></h2>
                        <p class="lead fw-normal text-muted mb-0"><foodcost2></foodcost2></p>
                    </div>
                </div>
            </section>


            <!--menu3-->
            <section class="py-3">
                <div class="container px-0.1 my-0.1">
                    <div class="text-center">
                        <h4 class="fw-bolder"> <menu3></menu3> </h4>
                </div>
            </section>  

            <section class="py-5 bg-light" id="scroll-target">
                <div class="container px-2 my-2">
                    <div class="text-center">
                        <h2 class="fw-bolder"><foodname3></foodname3></h2>
                        <p class="lead fw-normal text-muted mb-0"><foodcost3></foodcost3></p>
                    </div>
                </div>
            </section>


            <!--menu4-->
            <section class="py-3">
                <div class="container px-0.1 my-0.1">
                    <div class="text-center">
                        <h4 class="fw-bolder"> <menu4></menu4></h4>
                </div>
            </section>  

            <section class="py-5 bg-light" id="scroll-target">
                <div class="container px-2 my-2">
                    <div class="text-center">
                            <h2 class="fw-bolder"><foodname4></foodname4></h2>
                            <p class="lead fw-normal text-muted mb-0"><foodcost4></foodcost4></p>
                    </div>
                </div>
            </section>


            <!--menu5-->
            <section class="py-3">
                <div class="container px-0.1 my-0.1">
                    <div class="text-center">
                        <h4 class="fw-bolder"> <menu5></menu5> </h4>
                </div>
            </section>  

            <section class="py-5 bg-light" id="scroll-target">
                <div class="container px-2 my-2">
                    <div class="text-center">
                        <h2 class="fw-bolder"><foodname5></foodname5></h2>
                        <p class="lead fw-normal text-muted mb-0"><foodcost5></foodcost5></p>
                    </div>
                </div>
            </section>
            

            <!--menu6-->
            <section class="py-3">
                <div class="container px-0.1 my-0.1">
                    <div class="text-center">
                        <h4 class="fw-bolder"> <menu6></menu6> </h4>
                </div>
            </section>  

            <section class="py-5 bg-light" id="scroll-target">
                <div class="container px-2 my-2">
                    <div class="text-center">
                        <h2 class="fw-bolder"><foodname6></foodname6></h2>
                        <p class="lead fw-normal text-muted mb-0"><foodcost6></foodcost6></p>
                    </div>
                </div>
            </section>    

            <!--menu7-->
            <section class="py-3">
                <div class="container px-0.1 my-0.1">
                    <div class="text-center">
                        <h4 class="fw-bolder"> <menu7></menu7> </h4>
                </div>
            </section>  

            <section class="py-5 bg-light" id="scroll-target">
                <div class="container px-2 my-2">
                    <div class="text-center">
                        <h2 class="fw-bolder"><foodname7></foodname7></h2>
                        <p class="lead fw-normal text-muted mb-0"><foodcost7></foodcost6></p>
                    </div>
                </div>
            </section>  

            <!--menu8-->
            <section class="py-3">
                <div class="container px-0.1 my-0.1">
                    <div class="text-center">
                        <h4 class="fw-bolder"> <menu8></menu8> </h4>
                </div>
            </section>  

            <section class="py-5 bg-light" id="scroll-target">
                <div class="container px-2 my-2">
                    <div class="text-center">
                        <h2 class="fw-bolder"><foodname8></foodname8></h2>
                        <p class="lead fw-normal text-muted mb-0"><foodcost8></foodcost8></p>
                    </div>
                </div>
            </section>        

        </main>
        <!-- Footer-->
        <footer class="bg-dark py-4 mt-auto">
            <div class="container px-5">
                <div class="row align-items-center justify-content-between flex-column flex-sm-row">
                    <div class="col-auto"><div class="small m-0 text-white">Copyright &copy; Your Website 2022</div></div>
                    <div class="col-auto">
                        <a class="link-light small" href="#!">Privacy</a>
                        <span class="text-white mx-1">&middot;</span>
                        <a class="link-light small" href="#!">Terms</a>
                        <span class="text-white mx-1">&middot;</span>
                        <a class="link-light small" href="#!">Contact</a>
                    </div>
                </div>
            </div>
        </footer>
        
        <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script>
        <!--fetch로 오픈 api 데이터 끌어오기-->
        <script>
        
            // 모든 자식요소들을 삭제하는 함수
            function removeAllchild(div) {
                while (div.hasChildNodes()) {
                    div.removeChild(div.firstChild);
                }
            }


            var serviceAreaCode= "";


            // 각 고속도로에 존재하는 휴게소 리스트를 작성하여 드랍다운 메뉴에 추가합니다.
            function addReststop(lineNumber){

                // 아래 조건문은 각 고속도로 선택시 해당 고속도로 이름이 버튼(html)에 기록되도록 하기 위함입니다.
                let highway_Area = document.getElementById('highway');
                if(lineNumber==='0010'){
                    highway_Area.innerHTML = '경부선';
                }
                else if(lineNumber==='0550'){
                    highway_Area.innerHTML = '중앙선';
                }
                else if(lineNumber==='0500'){
                    highway_Area.innerHTML = '영동선';
                }
                let tagArea = document.getElementById('select_restStop'); // 드랍다운 메뉴 추가할 태그 아이디 저장
                removeAllchild(tagArea);    // 고속도로 선택시마다 새로운 휴게소를 불러와야 하므로 현재 드랍다운 메뉴에 존재하는 자식요소 싹다 삭제합니다.
                
                


                // 아래의 ajax 문을 통해서 휴게소표준 api를 불러옵니다. 각 고속도로에 대한 모든 휴게소이름과 휴게소 코드를 가져오기 위함입니다.
                // 여기서 가져오게되는 휴게소 코드(serviceAreaCode)는 추후에 휴게소별 날씨정보 api에 있는 unitCode와 상응하는 데이터입니다.
                var routeCodes = [];
                var svarAddrs = [];
                var rest_names = [];
                var serviceAreaCodes = [];
                // 페이지 1
                $.ajax({
                    url: "http://data.ex.co.kr/openapi/business/conveniServiceArea?key=1817997939&type=json&numOfRows=99&pageNo=1",
                    async:false,
                    success: function(data){
                        //변수 설정
                        userData = data;
                    },
                }).done(function() {
                    var routeCode = ""; 
                    var svarAddr = "";
                    var rest_name = "";
                    var data_count = userData["list"].length    // 데이터 개수 얻기
                    
                    for (var i =0; i<data_count; i++){
                        routeCode = JSON.stringify(userData["list"][i]["routeCode"]);   // 고속도로 번호를 가져옵니다.
                        rest_name = JSON.stringify(userData["list"][i]["serviceAreaName"]); // 휴게소 이름을 가져옵니다.
                        serviceCode = JSON.stringify(userData["list"][i]["serviceAreaCode"]); // 휴게소코드를 가져옵니다.
                        
                        if(routeCode.substring(1,5) === lineNumber){    //  고속도로 코드가 같다면
                            rest_names.push(rest_name); //휴게소 이름을 저장해둡니다...
                            serviceAreaCodes.push(serviceCode); //  휴게소 코드를 저장해둡니다.
                        }
                    }
                    // 아래 forEach문은 저장한 모든 휴게소에 대해, 드랍다운 버튼을 생성하기 위함입니다.
                    rest_names.forEach(function(addr,index){
                        let new_A_Button = document.createElement('a');   // a 속성 생성
                        new_A_Button.setAttribute('class','dropdown-item');
                        new_A_Button.setAttribute('onclick',"Showmenu("+rest_names[index]+")");
                        new_A_Button.innerHTML = rest_names[index].substring(1,rest_names[index].length-1);
                        tagArea.appendChild(new_A_Button);
                    })
                })
                /*
                // 페이지 2, 페이지 1과 모든 과정이 동일하며, 오픈 api 데이터 가져오는 특성상 페이지를 나누었습니다.
                $.ajax({
                    url: "http://data.ex.co.kr/openapi/business/conveniServiceArea?key=1817997939&type=json&numOfRows=99&pageNo=2",
                    async:false,
                    success: function(data){
                        //변수 설정
                        userData = data;
                    },
                }).done(function() {
                    var routeCode = ""; 
                    var svarAddr = "";
                    var rest_name = "";
                    var data_count = userData["list"].length    // 데이터 개수 얻기
                    
                    for (var i =0; i<data_count; i++){
                        routeCode = JSON.stringify(userData["list"][i]["routeCode"]);
                        rest_name = JSON.stringify(userData["list"][i]["serviceAreaName"]); // 휴게소 이름...
                        serviceCode = JSON.stringify(userData["list"][i]["serviceAreaCode"]);
                        
                        if(routeCode.substring(1,5) === lineNumber){    //  고속도로 코드가 같다면
                            rest_names.push(rest_name); //휴게소 이름...
                            serviceAreaCodes.push(serviceCode);
                        }
                    }
                    rest_names.forEach(function(addr,index){
                        let new_A_Button = document.createElement('a');   // a 속성 생성
                        new_A_Button.setAttribute('class','dropdown-item');
                        new_A_Button.setAttribute('onclick',"Showweather("+serviceAreaCodes[index]+","+rest_names[index]+")");
                        new_A_Button.innerHTML = rest_names[index].substring(1,rest_names[index].length-1);
                        tagArea.appendChild(new_A_Button);
                    })
                })
                // 페이지 3
                $.ajax({
                    url: "http://data.ex.co.kr/openapi/business/conveniServiceArea?key=1817997939&type=json&numOfRows=99&pageNo=3",
                    async:false,
                    success: function(data){
                        //변수 설정
                        userData = data;
                    },
                }).done(function() {
                    var routeCode = ""; 
                    var svarAddr = "";
                    var rest_name = "";
                    var data_count = userData["list"].length    // 데이터 개수 얻기
                    
                    for (var i =0; i<data_count; i++){
                        routeCode = JSON.stringify(userData["list"][i]["routeCode"]);
                        rest_name = JSON.stringify(userData["list"][i]["serviceAreaName"]); // 휴게소 이름...
                        serviceCode = JSON.stringify(userData["list"][i]["serviceAreaCode"]);
                        
                        if(routeCode.substring(1,5) === lineNumber){    //  고속도로 코드가 같다면
                            rest_names.push(rest_name); //휴게소 이름...
                            serviceAreaCodes.push(serviceCode);
                        }
                    }
                    rest_names.forEach(function(addr,index){
                        let new_A_Button = document.createElement('a');   // a 속성 생성
                        new_A_Button.setAttribute('class','dropdown-item');
                        new_A_Button.setAttribute('onclick',"Showweather("+serviceAreaCodes[index]+","+rest_names[index]+")");
                        new_A_Button.innerHTML = rest_names[index].substring(1,rest_names[index].length-1);
                        tagArea.appendChild(new_A_Button);
                    })
                })*/

            }

            function Showmenu(rest_name) {
            
            console.log(rest_name);
            fetch('http://data.ex.co.kr/openapi/restinfo/restBestfoodList?key=6806352377&type=json&numOfRows=1000' + '&stdRestNm='+rest_name).then(function(response){
                  method: 'GET';
                  body: JSON.stringify(this.obj)
                  response.text().then(function(text){
                  
                  //데이터 정렬 및 text data-> array data 변환
                  index1=text.indexOf('[')
                  index2=text.indexOf(']')
                  ndata=text.substr(index1+1, index2-index1+1)
                  nndata=ndata.split('},');
                  
                  for(let i=0; i<8; i++){
                    index3=nndata[i].indexOf('"foodNm":"')
                    index4=nndata[i].indexOf('"foodCost":"')
                    index5=nndata[i].indexOf('"etc"')
                    foodname=nndata[i].substr(index3+10, index4-index3-12)
                    foodcost=nndata[i].substr(index4+12, index5-index4-14)
                    console.log(foodname,foodcost)
        
                    //foodname 
                    document.querySelector('foodname'+String(i+1)).innerHTML = foodname;
                    //foodcost
                    document.querySelector('foodcost'+String(i+1)).innerHTML = foodcost+"원";
                  
                  }

                    //recommend menu
                    index3=nndata[1].indexOf('"foodNm":"')
                    index4=nndata[1].indexOf('"foodCost":"')
                    index5=nndata[1].indexOf('"etc"')
                    foodname1=nndata[1].substr(index3+10, index4-index3-12)
                    foodcost1=nndata[1].substr(index4+12, index5-index4-14)
                    document.querySelector('recommend1').innerHTML = foodname1;
                    document.querySelector('rec1').innerHTML = foodcost1+"원";

                    index3=nndata[4].indexOf('"foodNm":"')
                    index4=nndata[4].indexOf('"foodCost":"')
                    index5=nndata[4].indexOf('"etc"')
                    foodname1=nndata[4].substr(index3+10, index4-index3-12)
                    foodcost1=nndata[4].substr(index4+12, index5-index4-14)
                    document.querySelector('recommend2').innerHTML = foodname1;
                    document.querySelector('rec2').innerHTML = foodcost1+"원";

                    index3=nndata[5].indexOf('"foodNm":"')
                    index4=nndata[5].indexOf('"foodCost":"')
                    index5=nndata[5].indexOf('"etc"')
                    foodname1=nndata[5].substr(index3+10, index4-index3-12)
                    foodcost1=nndata[5].substr(index4+12, index5-index4-14)
                    document.querySelector('recommend3').innerHTML = foodname1;
                    document.querySelector('rec3').innerHTML = foodcost1+"원";

                    for(let i=1; i<9; i++)
                    document.querySelector('menu'+String(i)).innerHTML = "< "+"menu"+String(i)+" >";
                
            }
        

                )
              })
            }
              </script>
              
              <%- include('./footer.ejs') %>