<!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>修正指定之project</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/project">{{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">修正{{project.a05name}}之資料</h5>
          <h6 class="card-subtitle mb-2 text-muted">{{card_subtitle}}</h6>
          <form action="/deep1/project/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="project._id">
            
            <label for="formGroupExampleInput2">{{items.item0}}</label>
            <select name="a05client_id" 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.item1}}</label>
            <select name="a10staff_id" 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.item2}}</label>
            <input type="text" name="a15name" class="form-control" id="formGroupExampleInput2" :value="project.a15name">
          
            <label for="formGroupExampleInput2">{{items.item3}}</label>
            <select name="a20type" class="form-select">
              <optgroup v-for="(type,index) of types" :key="type._id">
              <option :value="type.a25code" :selected="typeindex[index]" >{{type.a30mean}}</option>
              </optgroup>
              </select>
            <br>

            <label for="formGroupExampleInput2">{{items.item4}}</label>
            <input type="text" name="a25describe" class="form-control" id="formGroupExampleInput4" :value="project.a25describe">
         
            <label for="formGroupExampleInput2">{{items.item5}}</label>
            <input type="text" name="a30requestdate" class="form-control" id="formGroupExampleInput5" :value="project.a30requestdate">
          
            <label for="formGroupExampleInput2">{{items.item6}}</label>
            <input type="text" name="a35proposaldate" class="form-control" id="formGroupExampleInput6" :value="project.a35proposaldate">
          
            <label for="formGroupExampleInput2">{{items.item7}}</label>
            <input type="text" name="a40contractdate" class="form-control" id="formGroupExampleInput7" :value="project.a40contractdate">
          
            <label for="formGroupExampleInput2">{{items.item8}}</label>
         <select name="a45process" class="form-select">
                  <optgroup v-for="(stage,index) of stages" :key="stage._id">
                  <option :value="stage.a25code" :selected="stageindex[index]">{{stage.a30mean}}</option>
                  </optgroup>
                  </select>
                <br> 
            <label for="formGroupExampleInput2">{{items.item9}}</label>
            <input type="text" name="a50fullfitdate" class="form-control" id="formGroupExampleInput9" :value="project.a50fullfitdate">
          
            <label for="formGroupExampleInput2">{{items.item10}}</label>
            <input type="text" name="a55realrevenue" class="form-control" id="formGroupExampleInput10" :value="project.a55realrevenue">
          
            <label for="formGroupExampleInput2">{{items.item11}}</label>
            <input type="text" name="a60paydate" class="form-control" id="formGroupExampleInput11" :value="project.a60paydate">
          
            <label for="formGroupExampleInput2">{{items.item12}}</label>
            <input type="text" name="a65status" class="form-control" id="formGroupExampleInput12" :value="project.a65status">  
              <input type="hidden" name="statusreport" class="form-control" id="msg1" value="由修正project後進入本頁">
              <input type="hidden" name="status" class="form-control" id="msg2" value="0">
              <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:"進度紀錄:",
            item9:"驗收合格日期:",
            item10:"實際履行金額:",
            item11:"尾款收取日期:",
            item12:"結案註記:",  
            item99:"特別註記"     
      },
      project:JSON.parse(decodeURIComponent('<%=project%>')),
      termlist:JSON.parse(decodeURIComponent('<%=termlist%>')),
        staffinfolist:JSON.parse(decodeURIComponent('<%=staffinfolist%>')),
        guestinfolist:JSON.parse(decodeURIComponent('<%=guestinfolist%>')),
        types:[],
        stages:[],
        staffindex:[],
        guestindex:[],
        typeindex:[],
        stageindex:[],
      inputerUIkey:0
      } 
    },
    mounted:function(){
        for(term of this.termlist){
            if(term.a20field=="a20type"){
                this.types.push(term)
            }
        }
        for(term of this.termlist){
            if(term.a20field=="a45stage"){
                this.stages.push(term)
            }
        }
        for(staff of this.staffinfolist){
            if(staff._id==this.project.a10staff_id){
                this.staffindex.push(true)
            }else{
                this.staffindex.push(false)
            }
        } 
        for(guest of this.guestlist){
            if(guest.a25code==this.project.a05client_id){
                this.guestindex.push(true)
            }else{
                this.guestindex.push(false)
            }
        }
        for(stage of this.stages){
            if(stage.a25code==this.project.a45stage){
                this.stageindex.push(true)
            }else{
                this.stageindex.push(false)
            }
        }
        for(type of this.types){
            if(type.a25code==this.project.a20type){
                this.typeindex.push(true)
            }else{
                this.typeindex.push(false)
            }
        }                     
    },    
    methods:{
        rerender:function() {
      this.inputerUIkey += 1;
      console.log("inputerUIkey:"+this.inputerUIkey) 
    }
    }, 
    /*
    mounted:{
        this:{
            values:{
                value0:project.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>