<template>
    <div>

    <v-card   class="mb-1 pa-1">
        <v-layout row>
             
            <v-flex xs10>
                <v-layout row>
                    <v-flex xs2>
                    
                        <one-date-picker
                            label="Tanggal"
                            :date="sdate"
                            
                            data="0"
                            @change="changeDate"
                        ></one-date-picker>
                    </v-flex>
                    <v-flex xs3>
                            <v-text-field class="flex ma-1"
                                label="Cari ..."
                                placeholder="No Reg / Nama"
                                outline
                                hide-details
                                v-model="search"
                                v-on:keyup.enter="searchs"
                            ></v-text-field>
                    </v-flex>
                    <v-flex xs3>
                            <v-autocomplete
                                v-model="company"
                                :items="companies"
                                outline
                                :loading="loading_company"
                                :search-input.sync="search_company"
                                class=" ma-1 ml-1 mini-select mr-1"
                                hide-no-data
                                filled
                                item-text="M_CompanyName"
                                item-value="M_CompanyID"
                                label="Filter Kel. Pelanggan"
                                placeholder="Cari Kelompok Pelanggan"
                                return-object
                            ></v-autocomplete>  
                    </v-flex>
                    <!--<v-flex xs3>
                            <v-select class="ma-1 mini-select "  :items="deliveries" 
                                item-text="name"
                                return-object
                                v-model="selected_delivery"
                                label="Filter Pengambilan Hasil" outline hide-details></v-select>
                        
                    </v-flex>-->
                    <!--<v-flex xs1>
                        <v-layout>
                            <v-btn class="btn-search one-btn-icon ma-1" color="success" >
                                <span class="icon-search"><span>
                            </v-btn>
                        </v-layout>
                    </v-flex>-->

                </v-layout>
                
            </v-flex>
            <v-flex xs2 align-center pr-2 class="text-xs-right" >
                <v-layout row>
                    <v-btn  @click="releaseResult()" block dark color="red">SERAHKAN</v-btn>
                </v-layout>
            </v-flex>
        </v-layout>
        
        <one-dialog-info :status="opendialoginfo" :msg="msginfo" @close-dialog-info="opendialoginfo = false"></one-dialog-info>
    </v-card>
    </div>
</template>

<style scoped>
.btn-legend {
    height: 25px;
    width: 25px;
    border-radius: 0%;
}

button {
    height: 48px;
}

.btn-search {
    font-size: 1.5em
}
.v-input input {
    max-height: 25px;
}
</style>

<script>
module.exports = {
    components : {
        'one-date-picker' : httpVueLoader('./oneDatePicker.vue'),
        'one-dialog-info':httpVueLoader('../../common/oneDialogInfo.vue')
    },
    data() {
       return {
         search_company: '',
         opendialoginfo:false,
         msginfo:''
       }
    },
    watch : {
	search_company(n,o) {
		this.$store.dispatch('company/search',n)
	}
    },
    computed : {
        company: {
            get() { return this.$store.state.company.company },
            set(v) { 
                this.$store.commit('company/update_company',v) 
                this.searchs()
            }
        },
        companies() {
            return this.$store.state.company.companies
        },
        deliveries() {
            return this.$store.state.re_patient.deliveries
        },
        selected_delivery: {
            get() { return this.$store.state.re_patient.selected_delivery },
            set(v) { 
                this.$store.commit('re_patient/update_selected_delivery',v)
                this.searchs()
                //this.$store.dispatch('re_patient/search')  
            }
        },
        search_status() { 
            return this.$store.state.re_patient.search_status
        },
        loading_company() { 
            return this.$store.state.company.loading
        },
        nolab : {
            get () { return this.$store.state.re_patient.nolab },
            set (v) { this.$store.commit('re_patient/update_nolab', v) }
        },

        search : {
            get () { return this.$store.state.re_patient.search },
            set (v) { this.$store.commit('re_patient/update_search', v) }
        },

        groups () {
            return this.$store.state.re_px.groups
        },

        selected_group : {
            get () { return this.$store.state.re_px.selected_group },
            set (v) { this.$store.commit('re_px/update_selected_group', v) }
        },

        order_id () {
            return this.$store.state.re_px.order_id
        },

        contain_val () {
            return this.$store.state.re_px.contain_val
        },

        lang () {
            return {code:this.$store.state.re_patient.selected_patient.M_LangCode, is_si:this.$store.state.re_patient.selected_patient.is_si}
        },

        img_lang () {
            if (this.lang.code == "ID")
                return "flag-ina_48.png"
            else if (this.lang.code == "EN")
                return "flag-us_48.png"
        },

        sdate : {
            get () { return this.$store.state.re_patient.s_date },
            set (v) { this.$store.commit('re_patient/update_sdate', v) }
        },

        selected_patient () {
            return this.$store.state.re_patient.selected_patient
        },

        btn_history_show () {
            if (!this.selected_patient) return false
            if (!this.selected_patient.is_history) return false
            if (this.selected_patient.is_history == "N") return false

            return true
        },

        info_req_perfect () {
            let x = false
            try {
                x = this.$store.state.re_patient.info_req.is_perfect == 'Y';    
            } catch (error) {
            }
            
            return x
        },

        btn_validation_enable() {
           return true
            let x = this.$store.state.re_px.pxs
            // console.log(x)
            let y = 0, n = 0
            for(let i in x) {
                // console.log(i+' : '+x[i].t_testname+' : '+x[i].is_result+' : '+x[i].validation+' : '+x[i].verification)
                if (x[i].is_result == 'Y') {
                    n++
                    if (x[i].validation == 'Y')
                        {y++;}
                }
            }
            // console.log("n:"+n+" y:"+y)
            if (y < 1) return false
            return true
        },

        btn_validation_show() {
            let x = this.$store.state.re_px.pxs
            let z = 0, n = 0
            for(let i in x) {
                if (x[i].is_result == 'Y') {
                    n++
                    if (x[i].validation_old == 'Y')
                        z++
                }
            }
                
            if (z == n) return false
            return true
        }
    },

    methods : {
        releaseResult() {
            var patients = this.$store.state.re_patient.selected_patients
            var selectall = this.$store.state.re_patient.bar_chx_all
            if(selectall || (!selectall && patients.length > 0 ))
                this.$store.dispatch('re_patient/releaseresult')
            else{
                this.msginfo = "<p>Ijinkan daku bertanya, apa yang harus daku serahkan ? tak ada yang bisa daku perbuat, jika tak satupun yang kau pilih</p>"
                this.opendialoginfo = true
            }
        },
        searchs() {
            this.$store.commit('re_patient/update_current_page',1)
            this.$store.commit('re_patient/update_bar_chx_all', false)
            this.$store.dispatch('re_patient/search')
        },
        keySearch(e) {
            if (e.which == 13) {
                this.searchs()
            }
        },
        save_result() {
            this.$store.dispatch('re_px/confirm')
        },
        histories() {
            this.$store.commit('re_history/update_dialog_history', true)
        },
        printMe() {
            this.$store.commit('re_patient/update_rpt_url', this.$store.state.re_patient.selected_patient.T_OrderHeaderID)
            this.$store.commit('re_patient/update_print_dialog', true)
            this.$store.dispatch('re_px/print_count')
        },
        img_lang_2 (lang, si) {
            
            if (lang == "ID" && si == "N")
                return "inako.png"
            if (lang == "ID" && si == "Y")
                return "inasi.png"
            if (lang == "EN" && si == "N")
                return "engko.png"
            if (lang == "EN" && si == "Y")
                return "engsi.png"
        },
        changeDate(x) {
            this.sdate = x.new_date
            this.searchs()
        },
        note() {
            this.$store.commit('re_patient/update_dialog_note', true)
        },

        info() {
            this.$store.commit('re_patient/update_dialog_req', true)
        },

        unvalidate() {
            this.$store.dispatch('re_px/unvalidate')
        }
    },

    mounted () {
        this.$store.dispatch('re_px/search_group')
    }
}
</script>
