<!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>修正指定之post</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/post">{{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">修正{{post.a05name}}之資料</h5>
          <h6 class="card-subtitle mb-2 text-muted">{{card_subtitle}}</h6>
          <form action="/deep1/post/update" method="post">
            <div class="form-group" :key="inputerUIkey">
                <label for="formGroupExampleInput2">{{items.item1}}</label>
                <select name="a10posttype" class="form-select">
                    <optgroup v-for="(posttype,index) of posttypes" :key="posttype._id">
                    <option :value="posttype.a25code" :selected="typeindex[index]">{{posttype.a30mean}}</option>
                    </optgroup>
                    </select>
                  <br>

                <label for="formGroupExampleInput2">{{items.item2}}</label>
                <select name="a15poster" class="form-select">
                    <optgroup v-for="(staffinfo,index) of staffinfolist" :key="staffinfo._id" >            
                    <option :value="staffinfo._id" :selected="staffindex[index]">{{staffinfo.a28department}}{{staffinfo.a05lastname}}{{staffinfo.a10firstname}}</option>
                    </optgroup>  
                    </select>             
                    <br>    
              
                <label for="formGroupExampleInput2">{{items.item3}}</label>
                <input type="text" name="a20postdate" class="form-control" id="formGroupExampleInput3" :value="post.a20postdate">
              
                <label for="formGroupExampleInput2">{{items.item4}}</label>
                <input type="text" name="a25posttitle" class="form-control" id="formGroupExampleInput4" :value="post.a25posttitle">
             
                <label for="formGroupExampleInput2">{{items.item5}}</label>
                <input type="text" name="a30postcontent" class="form-control" id="formGroupExampleInput5" :value="post.a30postcontent">
              
                <label for="formGroupExampleInput2">{{items.item6}}</label>
                <input type="text" name="a35reader" class="form-control" id="formGroupExampleInput6" :value="post.a35reader">
              
                <label for="formGroupExampleInput2">{{items.item7}}</label>
                <select name="a40showtype" class="form-select">
                    <optgroup v-for="(showtype,index) of showtypes" :key="showtype._id">
                    <option :value="showtype.a25code" :selected="showindex[index]">{{showtype.a30mean}}</option>
                    </optgroup>
                    </select>
                  <br>
                <label for="formGroupExampleInput2">{{items.item8}}</label>
                <input type="text" name="a45datetodown" class="form-control" id="formGroupExampleInput8" :value="post.a45datetodown">
           
              <input type="hidden" name="statusreport" class="form-control" id="msg1" value="由修正post後進入本頁">
            
              <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:"內容類別：",
            item2:"公告者：",
            item3:"公告日期時間：",
            item4:"公告標題：",
            item5:"公告內容：",
            item6:"公告對象：",
            item7:"呈現方式：",
            item8:"預定下架時間：",   
            item99:"管理註記"     
      },
      post:JSON.parse(decodeURIComponent('<%=post%>')),
      termlist:JSON.parse(decodeURIComponent('<%=termlist%>')),
        staffinfolist:JSON.parse(decodeURIComponent('<%=staffinfolist%>')),
        posttypes:[],
        showtypes:[],
        staffindex:[],
        typeindex:[],
        showindex:[],
      inputerUIkey:0
        
      } 
    },
    mounted:function(){
        for(term of this.termlist){
            if(term.a20field=="a10posttype"){
                this.posttypes.push(term)
            }
        }
        for(term of this.termlist){
            if(term.a20field=="a40showtype"){
                this.showtypes.push(term)
            }
        }
        for(staff of this.staffinfolist){
            if(staff._id==this.post.a15poster){
                this.staffindex.push(true)
            }else{
                this.staffindex.push(false)
            }
        } 
        for(type of this.posttypes){
            if(type.a25code==this.post.a10posttype){
                this.typeindex.push(true)
            }else{
                this.typeindex.push(false)
            }
        }
        for(show of this.showtypes){
            if(show.a25code==this.post.a40showtype){
                this.showindex.push(true)
            }else{
                this.showindex.push(false)
            }
        }                          
    },   
    methods:{
        rerender:function() {
      this.inputerUIkey += 1;
      console.log("inputerUIkey:"+this.inputerUIkey) 
    }
    }, 
    /*
    mounted:{
        this:{
            values:{
                value0:post.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>