<template>
        <v-layout column pb-2>
            <v-dialog
    v-model="dialog_bahandatang"
    persistent 
    max-width="50%"
    >
        <v-card>
            <v-card-title
                class="headline pt-2 pb-2"
                primary-title
        
            >
            <h4>Tanggal sampling</h4>
            </v-card-title>
            <v-card-text class="pt-2 pb-2">
                <v-layout row>
                    <v-flex xs12 d-flex>
                        <v-text-field
                        label="Tanggal sampling"
                        v-model="sampling_date"
                       hint="format : dd-mm-yyyy"
                    ></v-text-field>
                    </v-flex>
                </v-layout> 
            </v-card-text>
            <v-divider></v-divider>
            <v-card-actions>
                <v-spacer></v-spacer>
                <v-btn
                    color="primary"
                    
                    
                    @click="patientComing()"
                >
                Simpan
                </v-btn>
                <v-btn
                    color="grey"
                    flat
                    @click="dialog_bahandatang = false"
                >
                Batal
                </v-btn>
            </v-card-actions>
        </v-card>
    </v-dialog>
            <v-card v-if="messagetype === 'FO.VERIFICATION.REJECT'" class="mb-2">
                <v-layout v-if="selstatus.value !== 'adhoc'" row pa-2  align-center wrap >
                    <table>
                        <tr>
                            <th width="20%" class="text-md-left pt-2 pb-2">AKSI</th>
                            <th width="80%" class="text-md-left pt-2 pb-2">CATATAN KOREKSI</th>
                        </tr>
                        <tr class="mini-input" v-if="notes && notes.length > 0" v-for="(note,index) in notes">
                            <td width="20%" ><span v-bind:class="{'teal--text': colorBtn('VERIFY',note.button), 'primary--text': colorBtn('PASIEN',note.button),'error--text': colorBtn('ORDER',note.button),'purple--text': colorBtn('PEMERIKSAAN',note.button),'success--text': colorBtn('PENGIRIMAN HASIL',note.button)}" style="font-size:smaller;"> {{note.button}} </span></td>
                            <td width="80%" >
                                <div class="flex">
                                    <strong>{{note.label}}</strong>
                                    <div class="caption text-muted">{{note.reason}}</div>
                                </div>
                            </td>
                        </tr>
                        <tr class="mini-input" v-if="notes && notes.length ===  0">
                            <td colspan="5" class="text-md-center pr-2">
                                Tidak ada data
                            </td>
                        </tr>
                    </table>
                </v-layout>
            </v-card>
            
            <v-card >
    
                <v-layout v-if="status_data_patient !== 1" row pt-1 align-center wrap >
                    <v-flex xs4   class="text-md-center pl-2">
                        <div>
                            <v-btn dark @click="dialog_bahandatang = true" block color="teal">Bahan Datang</v-btn>
                        </div>
                    </v-flex>
                    <v-flex xs4 class="text-md-center pl-2">
                        <div>
                           <!-- <v-btn  block @click="openorder" color="error">Order</v-btn>-->
                        </div>
                    </v-flex>
                    <v-flex xs4 class="text-md-center pl-2 pr-2">
                        <div>
                           <!-- <v-btn  block @click="opentest" dark color="purple ">Pemeriksaan</v-btn>-->
                        </div>
                    </v-flex>
                </v-layout>
                
            </v-card>
            <one-fo-supervisor-dialog-alias></one-fo-supervisor-dialog-alias>
            <one-fo-supervisor-dialog-read></one-fo-supervisor-dialog-read>
            <one-fo-supervisor-dialog-void></one-fo-supervisor-dialog-void>
            <one-fo-supervisor-dialog-supplies></one-fo-supervisor-dialog-supplies>
            <one-fo-supervisor-dialog-barcode></one-fo-supervisor-dialog-barcode>
            <one-fo-supervisor-dialog-delivery></one-fo-supervisor-dialog-delivery>
            <one-fo-supervisor-dialog-verify></one-fo-supervisor-dialog-verify>
            <one-fo-supervisor-dialog-order></one-fo-supervisor-dialog-order>
            <one-fo-supervisor-dialog-test></one-fo-supervisor-dialog-test>
            <one-fo-supervisor-dialog-promise></one-fo-supervisor-dialog-promise>
            <one-dialog-print :title="printtitle" :width="printwidth" :height="500" :status="openprintcontrol" :urlprint="urlprintnote" @close-dialog-print="openprintcontrol = false"></one-dialog-print>
        </v-layout>
        
</template>

<style scoped>
    .label-tagihan{
        text-align:left;
        font-size: 25px;
        font-family: open sans, tahoma, sans-serif;
        font-weight:700;
    }

    .sub-header{
        text-align:left;
        font-size: 18px;
        font-family: open sans, tahoma, sans-serif;
        font-weight:700;
    }

    .sub-title{
        text-align:left;
        font-size: 14px;
        font-family: open sans, tahoma, sans-serif;
        font-weight:700;
    }

    .text-tagihan{
        text-align:left;
        font-size: 42px;
        font-family: open sans, tahoma, sans-serif;
    }

    .disabled-background{
        background:#b7b7b7;
    }

    .input-cash{
        width: 100%;
        padding: 8px 14px;
        box-sizing: border-box;
        border: 2px solid grey;
        border-radius: 4px;
        font-size: 22px;
        font-weight:700;
        text-align:right;
    }
    .input-plain{
        width: 100%;
        padding: 4px 8px;
        box-sizing: border-box;
        border: 2px solid grey;
        border-radius: 4px;
        font-size: 14px;
    }
    .v-input, .v-input__slot, .v-messages{
        margin:0px;
        padding:0px;
        min-height: 0px; 
    }
    .v-input--selection-controls:not(.v-input--hide-details) .v-input__slot {
        margin-bottom: 0px;
    }
    table {
    font-family: arial, sans-serif;
    border-collapse: collapse;
    width: 100%;
    background:white;
    border: 1px solid #ddd;
    }

    th, td {
    border-top: 1px solid #ddd;
    border-collapse: collapse;
    padding: .75rem 1.25rem;
    }
    table>tr>td {
    padding: .75rem 1.25rem;
    }
    table>tr>td:first {
    padding-left:15px!important;
    }
    .mini-input .v-input{
        margin-top: 0px; 
    }

    .mini-input .v-input, .mini-input .v-input--selection-controls,.mini-input .v-input__slot{
        margin-top: 0px; 
        margin-bottom:0px;
        margin-left:3px;
    }
    .mini-input .v-messages{
        min-height:0px;
    }

    .border-bottom-dashed{
        border-bottom : 1px dashed rgba(0,0,0,.12);
    }
</style>
<script>
module.exports = {
    components : {
        'one-field-verification' : httpVueLoader('../../common/oneFieldVerificationSupply.vue'),
        'one-dialog-print':httpVueLoader('../../common/oneDialogPrintX.vue'),
        'one-fo-supervisor-dialog-read' : httpVueLoader('./oneFoSupervisorDialogRead.vue'),
        'one-fo-supervisor-dialog-alias' : httpVueLoader('./oneFoSupervisorDialogAlias.vue'),
        'one-fo-supervisor-dialog-void' : httpVueLoader('./oneFoSupervisorDialogVoid.vue'),
        'one-fo-supervisor-dialog-supplies' : httpVueLoader('./oneFoSupervisorDialogSupplies.vue'),
        'one-fo-supervisor-dialog-barcode' : httpVueLoader('./oneFoSupervisorDialogBarcode.vue'),
        'one-fo-supervisor-dialog-delivery' : httpVueLoader('./oneFoSupervisorDialogDelivery.vue'),
        'one-fo-supervisor-dialog-verify' : httpVueLoader('./oneFoSupervisorDialogVerify.vue'),
        'one-fo-supervisor-dialog-order' : httpVueLoader('./oneFoSupervisorDialogOrder.vue'),
        'one-fo-supervisor-dialog-test' : httpVueLoader('./oneFoSupervisorDialogTest.vue'),
        'one-fo-supervisor-dialog-promise' : httpVueLoader('./oneFoSupervisorDialogPromise.vue'),
        'one-dialog-print':httpVueLoader('../../common/oneDialogPrintX.vue')
    },
    data () {
      return {
        checkbox: true,
        radioGroup: 1,
        switchCash: true,
        switchDebit: false,
        switchKredit: false,
        dialog:false,
        urlprintnote:'',
        printtitle:'',
        printwidth:600,
        openprintcontrol:false,
        dialog_bahandatang:false,
        sampling_date:''
      }
    },
    computed: {
        selected_patient() {
         return this.$store.state.patient.selected_patient
        },
        status_data_patient(){
            return this.$store.state.supervisor.status_data_patient
        },
        notes(){
            return this.$store.state.patient.notes
        },
        messagetype(){
            return this.$store.state.patient.message_type
        },
        statusact(){
            return this.$store.state.patient.status_act
        },
        selstatus(){
            return this.$store.state.patient.selected_status
        },
        xselstatus(){
            return this.$store.state.patient.selected_patient.status
        },
        selpat(){
            return this.$store.state.patient.selected_patient
        },
        snackbar: {
         get() {
            return this.$store.state.patient.snackbar
         },
         set(val) {
            this.$store.commit("patient/update_snackbar",val)
         }
      },
    },
    methods : {
        patientComing(){
            
            var xDate = moment(this.sampling_date, 'DD-MM-YYYY', true)
            var isValidDate = xDate.isValid()
            
            if(isValidDate){
                var sampling_date = this.deFormatedDate(this.sampling_date)
                this.dialog_bahandatang = false
                this.sampling_date = ''
                var selpat = this.selected_patient
                selpat.sampling_date = sampling_date
                this.$store.dispatch("patient/patientComing",selpat)
            }else{
                alert('format tanggal salah')
            }
            
        },
        colorBtn(asli,dinamis){
            if(asli === dinamis)
            return true
            else
            return false
        },
        changeAct(note,idx){
            let valnow = note.chex === 'N'?'Y':'N'
            note.chex = valnow
            var notes = this.$store.state.patient.notes
            notes[idx] = note
        },
        alias(){
            if(!_.isEmpty(this.selpat, true)){
                this.$store.commit("order/update_alias_doctor",this.selpat.alias)
                this.$store.commit("supervisor/update_save_status",0)
                this.$store.commit("supervisor/update_dialog_alias",true)
            }
            
        },
        read(){
            if(!_.isEmpty(this.selpat, true)){
                this.$store.commit("supervisor/update_read_message","")
                this.$store.commit("supervisor/update_save_status",0)
                this.$store.commit("supervisor/update_read_dialog_message","Akankah akan dibaca ?")
                this.$store.commit("supervisor/update_read_dialog",true)
            }
            
        },
        xvoid(){
            console.log(this.selpat)
            if(!_.isEmpty(this.selpat, true)){
                this.$store.commit("supervisor/update_void_message","")
                this.$store.commit("supervisor/update_save_status",0)
                this.$store.commit("supervisor/update_void_dialog_message","Yakin akan membatalkan order "+this.$store.state.patient.selected_patient.labnumber+" ?")
                this.$store.commit("supervisor/update_void_dialog",true)
            }
        },
        verify(){
            if(!_.isEmpty(this.selpat, true)){
                this.$store.commit("supervisor/update_verify_message","")
                this.$store.commit("supervisor/update_save_status",0)
                this.$store.commit("supervisor/update_verify_dialog_message","Yakin, akan verify ?")
                this.$store.commit("supervisor/update_verify_dialog",true)
            }
        },
        opensupplies(){
            if(!_.isEmpty(this.selpat, true)){
                this.$store.dispatch("supplies/lookup",{orderid:this.$store.state.patient.selected_patient.orderid})
                this.$store.commit("supplies/update_supplies_message","")
                this.$store.commit("supplies/update_save_status",0)
                this.$store.commit("supplies/update_supplies_dialog",true)
            }
        },
        openflagmcu(){
            if(!_.isEmpty(this.selpat, true)){
                this.$store.dispatch("supervisor/flagmcu",{orderid:this.$store.state.patient.selected_patient.orderid,value:'Y'})
            }
        },
        releaseflagmcu(){
            if(!_.isEmpty(this.selpat, true)){
                this.$store.dispatch("supervisor/flagmcu",{orderid:this.$store.state.patient.selected_patient.orderid,value:'N'})
            }
        },
        openbarcode(){
            if(!_.isEmpty(this.selpat, true)){
                this.$store.dispatch("barcode/lookup",{orderid:this.$store.state.patient.selected_patient.orderid})
                this.$store.commit("barcode/update_barcode_message","")
                this.$store.commit("barcode/update_save_status",0)
                this.$store.commit("barcode/update_barcode_dialog",true)
            }
        },
        opendelivery(){
            if(!_.isEmpty(this.selpat, true)){
                this.$store.dispatch("delivery/lookup",{orderid:this.$store.state.patient.selected_patient.orderid})
                this.$store.commit("delivery/update_delivery_message","")
                this.$store.commit("delivery/update_save_status",0)
                this.$store.commit("delivery/update_status_done",this.$store.state.patient.selected_patient.donedelivery)
                this.$store.commit("delivery/update_delivery_dialog",true)
            }
        },
        openorder(){
            if(!_.isEmpty(this.selpat, true)){
                this.$store.commit("order/update_order_message","")
                this.$store.commit("order/update_save_status",0)
                this.$store.commit("order/update_order_dialog",true)
                this.$store.dispatch("order/lookup",{orderid:this.$store.state.patient.selected_patient.orderid})
                
            }
        },
        opentest(){
            if(!_.isEmpty(this.selpat, true)){
                this.$store.commit("test/update_test_all",[])
                this.$store.dispatch("test/lookup",{orderid:this.$store.state.patient.selected_patient.orderid})
                this.$store.dispatch("test/lookup_promises",{orderid:this.$store.state.patient.selected_patient.orderid})
                this.$store.commit("test/update_test_message","")
                this.$store.commit("test/update_save_status",0)
                this.$store.commit("test/update_save_status_verification",0)
                this.$store.commit("test/update_show_cito_dropdown","N")
                this.$store.commit("test/update_selected_cito",{})
                this.$store.commit("test/update_test_dialog",true)
            }
        },
        openpromise(){
            if(!_.isEmpty(this.selpat, true)){
                this.$store.dispatch("promise/lookup",{orderid:this.$store.state.patient.selected_patient.orderid})
                this.$store.commit("promise/update_promise_message","")
                this.$store.commit("promise/update_save_status",0)
                this.$store.commit("promise/update_promise_dialog",true)
            }
        },
        deFormatedDate (date) {
          if (!date) return null

      const [ day,month, year] = date.split('-')
      return `${year}-${month.padStart(2, '0')}-${day.padStart(2, '0')}`
      },
        printControlCard(){
            if(!_.isEmpty(this.selpat, true)){
                var orderid = this.$store.state.patient.selected_patient.orderid
                this.printwidth = 950
                this.printtitle = ""
                let user = one_user()
                var rpt = 'rpt_fo_001'
                var xdatetime = Date.now()
                this.urlprintnote = "/birt/run?__report=report/one/lab/"+rpt+".rptdesign&__format=pdf&username="+user.M_UserUsername+"&PID="+orderid+"&tm="+xdatetime
                this.openprintcontrol = true
            }
        }
   }
}
</script>
