<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<script src="/javascripts/jquery-3.4.1.js"></script>
<style type="text/css">
body {
  background-color: #d6d6d3;
  height: 100vh;
  width: 100vw;
  display: flex;
     flex-direction:column;
	 justify-content: flex-start;
     align-items:center;
  	margin: 0;
}
.navbar{background:#e5f8cd;}
.nav-link, .navbar-brand{color: #f4f4f4;cursor:pointer;}
.nav-link{margin-right:1em !important;}
.nav-link:hover{background: #f4f4f4;color:#f97300;}
.navbar-collapse{justify-content:flex-end;}
.navbar-toggler{background:#fff !important;}
</style>

  <title>修正指定之user</title>
  </head>
  <body>
    <div id="show_div">
      <bander></bander>
        <inputer></inputer>
        <!-- <outputer></outputer> -->
    </div>
 
    <template id="banderUI">
      <nav class="navbar navbar-expand-lg navbar-light">
        <a class="navbar-brand" href="#">{{brand}}</a>
        <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarText" aria-controls="navbarText" aria-expanded="false" aria-label="Toggle navigation">
          <span class="navbar-toggler-icon"></span>
        </button>
        <div class="collapse navbar-collapse" id="navbarText">
          <ul class="navbar-nav mr-auto">
            <li class="nav-item">
              <a class="nav-link" href="/deep1/user">{{lastpage}}</a>
            </li>
            <li class="nav-item active">
              <a class="nav-link" href="#">{{edit1}} <span class="sr-only">(current)</span></a>
            </li>
            <li class="nav-item">
              <a class="nav-link" href="#">{{editbatch}}</a>
            </li>
          </ul>
          <span class="navbar-text">
            {{statusreport}}
          </span>
        </div>
      </nav>
    </template>
    
    <template id="inputerUI" >
      <div class="card" style="width: 18rem;">
        <div class="card-body">
          <h5 class="card-title">修正{{user.a05name}}之資料</h5>
          <h6 class="card-subtitle mb-2 text-muted">{{card_subtitle}}</h6>
          <form action="/deep1/user/update" method="post">
            <div class="form-group" :key="inputerUIkey">
            <label for="formGroupExampleInput2">{{items.item}}</label>
            <input type="text" name="_id" class="form-control" id="formGroupExampleInput" :value="user._id">
            
            <label for="formGroupExampleInput2">{{items.item0}}</label>
            <select name="a03status" class="form-select">
               <optgroup v-for="(status,index) of statuss" :key="status._id">
               <option :value="status.a25code" :selected="statusindex[index]">{{status.a30mean}}</option>
               </optgroup>
               </select>
             <br>

             <label for="formGroupExampleInput2">{{items.item1}}</label>
             <select name="a08infoID" class="form-select">
               <optgroup v-for="(guestinfo,index) of guestinfolist" :key="guestinfo._id" >            
               <option :value="guestinfo._id" :selected="guestindex[index]">{{guestinfo.a10visitor}}{{guestinfo.a30phoneno}}</option>
               </optgroup>  
               </select>             
               <br>  
             
             <label for="formGroupExampleInput2">{{items.item2}}</label>
             <input type="text" name="a10account" class="form-control" id="formGroupExampleInput2" :value="user.a10account">
          
             <label for="formGroupExampleInput2">{{items.item3}}</label>
             <input type="text" name="a15password" class="form-control" id="formGroupExampleInput3" :value="user.a15password">
           
             <label for="formGroupExampleInput2">{{items.item4}}</label>
             <select name="a45group" class="form-select">
               <optgroup v-for="(group,index) of groups" :key="group._id">
               <option :value="group.a25code" :selected="groupindex[index]">{{group.a30mean}}</option>
               </optgroup>
               </select>
             <br>   
           
              <input type="hidden" name="statusreport" class="form-control" id="msg1" value="由修正user後進入本頁">
            
              <input type="submit" id="button1" value="確定送出" class="btn btn-info">
            </div>
          </form>
          <input type="submit" id="button2" value="重新輸入" class="btn btn-info" @click="rerender()">
          <!-- <a href="#" class="card-link">Card link</a>
          <a href="#" class="card-link">Another link</a> -->
        </div>
      </div> 
    </template>

 
<!-- Vue CDN-->
<script src="https://unpkg.com/vue@2.6.14/dist/vue.js"></script>
<script>
Vue.component("bander",{
    props:{},
    data(){
      return {
        brand:"Deep內部功能",
        lastpage:"回前頁",
        edit1:"修正1筆",
        editbatch:"修正多筆",
        statusreport:'<%- statusreport %>'
      }
    },
    methods:{

    },
    template:"#banderUI"
  });
  Vue.component("inputer",{
    props:{},
    data(){
      return {
        card_title:"",
        card_subtitle:"請修正以下各項資料:",
        items:{
            item:"ID",
            item0:"資格狀態:",
            item1:"對應個資(員工或客戶)ID:",
            item2:"使用者使用帳號:",
            item3:"使用者登入密碼:",
            item4:"使用者群組別:",   
            item99:"使用者特別註記"     
      },
      user:JSON.parse(decodeURIComponent('<%=user%>')),
      termlist:JSON.parse(decodeURIComponent('<%=termlist%>')),
        staffinfolist:JSON.parse(decodeURIComponent('<%=staffinfolist%>')),
        guestinfolist:JSON.parse(decodeURIComponent('<%=guestinfolist%>')),
        statuss:[],
        groups:[],
        guestindex:[],
        statusindex:[],
        groupindex:[],           
      inputerUIkey:0
        
      } 
    },
    mounted:function(){
        for(term of this.termlist){
            if(term.a20field=="a03status"){
                this.statuss.push(term)
            }
        }
        for(term of this.termlist){
            if(term.a20field=="a45group"){
                this.groups.push(term)
            }
        }
        for(guest of this.guestinfolist){
            if(guest._id==this.user.a08infoID){
                this.guestindex.push(true)
            }else{
                this.guestindex.push(false)
            }
        } 
        for(group of this.groups){
            if(group.a25code==this.user.a45group){
                this.groupindex.push(true)
            }else{
                this.groupindex.push(false)
            }
        }
        for(status of this.statuss){
            if(status.a25code==this.user.a30status){
                this.statusindex.push(true)
            }else{
                this.statusindex.push(false)
            }
        }                         
    },    
    methods:{
        rerender:function() {
      this.inputerUIkey += 1;
      console.log("inputerUIkey:"+this.inputerUIkey) 
    }
    }, 
    /*
    mounted:{
        this:{
            values:{
                value0:user.a05name 
            }}
        }, */   
    template:"#inputerUI"
  });
    new Vue({
        el:'#show_div',
        data:{
          testdata:'有執行到此。。。。'
        },
        /* computed:{

        },
        watch:{

        },
        filters:{

        },
        mixins:[

        ],
        template:" ",
        components:{

        },*/
        beforeCreate:function(){
          console.log("before create...")
        },created:function(){
          console.log("created...")
        },
        beforeMount:function(){
          console.log("before mount...")
        },
        mounted:function(){
          console.log("mounted...")
        },
        beforeUpdate:function(){
          console.log("before update...")
        },
        updated:function(){
          console.log("updated...")
        },
        beforeDestroy:function(){

        } 
    })
</script>


  </body>
</html>