<template>

   <v-dialog
      v-model="dialog"
      width="400"
      >

         <v-card>
            <v-card-title
               class="headline grey lighten-2 pt-2 pb-2"
               primary-title
               >
               Tambah Janji Hasil
            </v-card-title>
               <v-card-text class="pt-2 pb-2">
                  
                   <v-layout row>
                       <v-flex xs12 pr-3>
                           <v-layout row wrap>
                                <v-flex xs12>
                                    <v-text-field
                                        v-model="selected_px.T_TestName"
                                        label="Pemeriksaan"
                                    ></v-text-field>
                                </v-flex>
                               <v-flex xs8 pr-2>
                                   <v-text-field
                                        v-model="promise_date"
                                        label="Tanggal"
                                        return-masked-value
                                        mask="##-##-####"
                                        v-if="dialog"
                                    ></v-text-field>
                               </v-flex>

                               <v-flex xs4>
                                   <v-text-field
                                        v-model="promise_time"
                                        label="Jam"
                                        return-masked-value
                                        mask="##:##"
                                        v-if="dialog"
                                    ></v-text-field>
                               </v-flex>
                           </v-layout>

                           
                       </v-flex>

                       
                   </v-layout>

               </v-card-text>
               <v-card-actions>
                  <v-spacer></v-spacer>
                  <v-btn
                     color="primary"
                     flat
                     @click="dialog = false"
                     >
                     Tutup
                  </v-btn>

                  <v-btn
                     color="primary"
                     @click="add_new()"
                     >
                     Simpan
                  </v-btn>
               </v-card-actions>
         </v-card>
   </v-dialog>

</template>

<style scoped>
.v-dialog__container {
   display: block !important;
}

.one-btn-icon { font-size: 1.5em; height: 42px; float: right }
</style>

<script>
module.exports = {
    components : {
        
    },

    data () {
        return {
            promise_date: '',
            promise_time: ''
        }
    },

   computed: {

      dialog: {
         get() {
            return this.$store.state.px.dialog_promise
         },
         set(val) {
            this.$store.commit('px/update_dialog_promise', val)
         }
      },

        selected_px () {
            return this.$store.state.px.selected_selected_test
        }
   },

   methods : {
       

       add_new () {
           let x = this.$store.state.px.selected_test
           for (let i in x) {
               if (x[i].T_TestID == this.selected_px.T_TestID) {
                   x[i].promise = this.promise_date.split('-').reverse().join('-') + ' ' + this.promise_time
                   x[i].promise_new = "Y"
               }
           }

            this.$store.commit('px/update_selected_test', x)
            this.dialog = false
        //    this.$store.dispatch('px/add_promise', {promise_date:this.promise_date, promise_time:this.promise_time})
       }
   },

   watch : {
      
       
       dialog (val, old) {
            if (val && !old) {
                this.promise_date = ''
                this.promise_time = ''
            }
       }
   },

   mounted () {
    
   }
}
</script>
