<!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>修正指定之request</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/innerweb">{{daily}}</a>
                </li>
            </div>   
            <li class="nav-item">
              <a class="nav-link" href="/deep1/innerweb/workzone/bellcall">{{lastpage}}</a>
            </li>
            <li class="nav-item active">
              <a class="nav-link" href="#">{{edit1}} <span class="sr-only">(current)</span></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">修正{{request.a05name}}之資料</h5>
          <h6 class="card-subtitle mb-2 text-muted">{{card_subtitle}}</h6>
          <form action="/deep1/request/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="request._id">
            
            <label for="formGroupExampleInput2">{{items.item0}}</label>
            <input type="text" name="a05ipofclient" class="form-control" id="formGroupExampleInput0" :value="request.a05ipofclient">

            <label for="formGroupExampleInput2">{{items.item1}}</label>
            <input type="text" name="a10client" class="form-control" id="formGroupExampleInput1" :value="request.a10client">
         
            <label for="formGroupExampleInput2">{{items.item2}}</label>
            <input type="text" name="a15requestdate" class="form-control" id="formGroupExampleInput2" :value="request.a15requestdate">
          
            <label for="formGroupExampleInput2">{{items.item3}}</label>
            <input type="text" name="a20phoneno" class="form-control" id="formGroupExampleInput3" :value="request.a20phoneno">
          
            <label for="formGroupExampleInput2">{{items.item4}}</label>
            <input type="text" name="a23tel" class="form-control" id="formGroupExampleInput4" :value="request.a23tel">
            
            <label for="formGroupExampleInput2">{{items.item5}}</label>
            <input type="text" name="a25email" class="form-control" id="formGroupExampleInput5" :value="request.a25email">
         
            <label for="formGroupExampleInput2">{{items.item6}}</label>
            <input type="text" name="a30address" class="form-control" id="formGroupExampleInput6" :value="request.a30address">
          
            <label for="formGroupExampleInput2">{{items.item7}}</label>
            <input type="text" name="a35request" class="form-control" id="formGroupExampleInput7" :value="request.a35request">
          
            <label for="formGroupExampleInput2">{{items.item8}}</label>
            <input type="text" name="a40deadline" class="form-control" id="formGroupExampleInput8" :value="request.a40deadline">
          
            <label for="formGroupExampleInput2">{{items.item9}}</label>              
            <select name="a45status" 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.item10}}</label>
            <select name="a50contactor" 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.item11}}</label>
            <select name="a55howtodo" class="form-select">
              <optgroup v-for="(howtodo,index) of howtodos" :key="howtodo._id">
              <option :value="howtodo.a25code" :selected="howtodoindex[index]">{{howtodo.a30mean}}</option>
              </optgroup>
              </select>
            <br>

            <label for="formGroupExampleInput2">{{items.item12}}</label>
            <input type="text" name="a60initial" class="form-control" id="formGroupExampleInput12" :value="request.a60initial">
          
            <label for="formGroupExampleInput2">{{items.item13}}</label>
        <select name="a65followup" class="form-select">
              <optgroup v-for="(followup,index) of followups" :key="followup._id">
              <option :value="followup.a25code" :selected="followupindex[index]">{{followup.a30mean}}</option>
              </optgroup>
              </select>
            <br>
             
            <label for="formGroupExampleInput2">{{items.item14}}</label>
            <input type="text" name="a70extra" class="form-control" id="formGroupExampleInput14" :value="request.a70extra">  
           
              <input type="hidden" name="statusreport" class="form-control" id="msg1" value="由修正request後進入本頁">
              <input type="hidden" name="status" class="form-control" id="msg2" value="1">
              <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內部功能",
        daily:"本員工首頁",
        lastpage:"回前頁(處理需求工作區)",
        edit1:"修正1筆",
        statusreport:'<%- statusreport %>'
      }
    },
    methods:{

    },
    template:"#banderUI"
  });
  Vue.component("inputer",{
    props:{},
    data(){
      return {
        card_title:"",
        card_subtitle:"請修正以下各項資料:",
        items:{
            item:"ID",
            item0:"來客IP:",
            item1:"稱呼或已註冊帳號:",
            item2:"提出日期:",
            item3:"手機:",
            item4:"電話:",
            item5:"Email:",
            item6:"地址:",
            item7:"服務需求:",
            item8:"期望完成期限:",
            item9:"處理狀態:",
            item10:"服務窗口人員:",
            item11:"專業屬性:",
            item12:"初步解決構想:",
            item13:"處理後追踪:",
            item14:"其他:",  
            item99:"特別註記"     
      },
      request:JSON.parse(decodeURIComponent('<%=request%>')),
      termlist:JSON.parse(decodeURIComponent('<%=termlist%>')),
        staffinfolist:JSON.parse(decodeURIComponent('<%=staffinfolist%>')),
        statuss:[],
        howtodos:[],
        followups:[],
        staffindex:[],
        statusindex:[],
        howtodoindex:[],
        followupindex:[],
      inputerUIkey:0
        
      } 
    },
    mounted:function(){
        for(term of this.termlist){
            if(term.a20field=="a45status"){
                this.statuss.push(term)
            }
        }
        for(term of this.termlist){
            if(term.a20field=="a55howtodo"){
                this.howtodos.push(term)
            }
        } 
        for(term of this.termlist){
            if(term.a20field=="a65followup"){
                this.followups.push(term)
            }
        }
        for(staff of this.staffinfolist){
            if(staff._id==this.request.a50contactor){
                this.staffindex.push(true)
            }else{
                this.staffindex.push(false)
            }
            console.log("staffindex: "+this.staffindex)            
        } 
        for(howtodo of this.howtodos){
            if(howtodo.a25code==this.request.a55howtodo){
                this.howtodoindex.push(true)
            }else{
                this.howtodoindex.push(false)
            }
        }
        for(status of this.statuss){
            if(status.a25code==this.request.a45status){
                this.statusindex.push(true)
            }else{
                this.statusindex.push(false)
            }
        }
        for(followup of this.followups){
            if(followup.a25code==this.request.a65followup){
                this.followupindex.push(true)
            }else{
                this.followupindex.push(false)
            }
        }

    },     
    methods:{
        rerender:function() {
      this.inputerUIkey += 1;
      console.log("inputerUIkey:"+this.inputerUIkey) 
    }
    }, 
      
    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>