<template>
    <v-layout row justify-center>
        <v-dialog v-model="deliverydialog" persistent max-width="30%">
            <v-card>
                <v-card-title
                    dark
                    class="headline success  pt-2 pb-2"
                    primary-title
                    style="color:white"
                >
                <h4>Pengiriman Hasil</h4>
                </v-card-title>
                <v-card-text class="pt-2 pb-2">
                    <v-layout ma-4 row wrap>
                       <!-- <v-flex v-if="vstatusdone === 'Y'" xs6 pr-1 mb-2>
                            <v-card elevation="1"> 
                                <v-list two-line subheader>
                                    <v-subheader>Pengiriman Hasil ( Tidak ada tambahan dari Verifikasi )</v-subheader>

                                    <v-list-tile avatar v-for="(vdelreg,index) in vdeliveryregister">
                                        <v-list-tile-content>
                                        <v-list-tile-title>
                                            {{vdelreg.label}} 
                                        </v-list-tile-title>
                                        <v-list-tile-sub-title>{{vdelreg.destination}}</v-list-tile-sub-title>
                                        </v-list-tile-content>
                                    </v-list-tile>

                                </v-list>
                            </v-card>
                        </v-flex>
                        <v-flex v-if="vstatusdone === 'N'" xs6 pr-1 mb-2>
                            <v-card elevation="1"> 
                                <v-list two-line subheader>
                                    <v-subheader>Pengiriman Hasil dari Registrasi</v-subheader>

                                    <v-list-tile avatar v-for="(vdelreg,index) in vdeliveryregister">
                                        <v-list-tile-content>
                                        <v-list-tile-title>
                                            {{vdelreg.label}} 
                                            <v-icon v-if="vdelreg.chex === 'Y'" color="success" left>check</v-icon>
                                            <v-icon v-if="vdelreg.chex === 'N'" color="error" left>close</v-icon>
                                        </v-list-tile-title>
                                        <v-list-tile-sub-title>{{vdelreg.destination}}</v-list-tile-sub-title>
                                        </v-list-tile-content>
                                    </v-list-tile>

                                </v-list>

                                <v-divider v-if="vdeliveryverification.length > 0"></v-divider>

                                <v-list
                                subheader
                                v-if="vdeliveryverification.length > 0"
                                >
                                    <v-subheader>
                                        Tambahan dari Verifikasi
                                        <div>
                                            <v-btn @click="saveDeliveryAdditionVerification()" small color="primary" dark>Simpan</v-btn>
                                        </div>
                                    </v-subheader>

                                    <v-list-tile @click="" v-for="(vdelver,index) in vdeliveryverification">


                                        <v-list-tile-content>
                                        <v-list-tile-title>
                                            {{vdelver.label}} 
                                        </v-list-tile-title>
                                        <v-list-tile-sub-title>{{vdelver.destination}}</v-list-tile-sub-title>
                                        </v-list-tile-content>
                                    </v-list-tile>

                                </v-list>
                            </v-card>
                        </v-flex>-->
                        <v-flex pl-1 xs12>
                            <v-card elevation="1">
                                <v-list
                                subheader
                                two-line
                                >
                                    <v-subheader>
                                         Pengiriman Hasil 
                                        <div>
                                            <v-btn  v-if="vstatussave !== 1" @click="saveDeliveryAdditionOther()" small color="primary" dark>Simpan</v-btn>
                                        </div>
                                        <code v-if="vmsgsave">Sudah diperbarui</code>
                                    </v-subheader>

                                    <v-list-tile @click="" v-for="(vdelot,index) in vdeliveryother">
                                        <v-list-tile-action>
                                        <v-checkbox @change="updateDeliveryOther(vdelot.chex,index)" v-model="vdelot.chex"></v-checkbox>
                                        </v-list-tile-action>

                                        <v-list-tile-content>
                                        <v-list-tile-title>{{vdelot.label}}</v-list-tile-title>
                                        <v-list-tile-sub-title>{{vdelot.destination}}</v-list-tile-sub-title>
                                        </v-list-tile-content>
                                    </v-list-tile>

                                </v-list>
                            </v-card>
                        </v-flex>
                    </v-layout>
                </v-card-text>
                <v-divider></v-divider>
                <v-card-actions>
                    <v-spacer></v-spacer>
                    <v-btn
                        flat
                        @click="deliverydialog = false"
                    >
                    Tutup
                    </v-btn>
                </v-card-actions>
            </v-card>
        </v-dialog>
  </v-layout>
</template>

<style scoped>

    ::-webkit-scrollbar-track
{
    -webkit-box-shadow: inset 0 0 6px rgba(0,0,0,0.3);
    background-color: #F5F5F5;
}

::-webkit-scrollbar
{
    width: 10px;
    background-color: #F5F5F5;
}

::-webkit-scrollbar-thumb
{
    background-color: #0ae;
    
    background-image: -webkit-gradient(linear, 0 0, 0 100%,
                       color-stop(.5, rgba(255, 255, 255, .2)),
                       color-stop(.5, transparent), to(transparent));
}
</style>
<script>
module.exports = {
    data () {
      return {
        printwidth:600
      }
    },
    computed: {
        vmsgsave(){
            return this.$store.state.delivery.save_message
        },
        vstatussave(){
            return this.$store.state.delivery.save_status
        },
        vstatusdone(){
            return this.$store.state.delivery.status_done
        },
        vdeliveryregister(){
            return this.$store.state.delivery.delivery_register
        },
        vdeliveryverification(){
            return this.$store.state.delivery.delivery_verification
        },
        vdeliveryother(){
            return this.$store.state.delivery.delivery_other
        },
        deliverydialog:{
            get() {
                return this.$store.state.delivery.delivery_dialog
            },
            set(val) {
                this.$store.commit("delivery/update_delivery_dialog",val)
            }
        },
        savestatus(){
            return this.$store.state.delivery.save_status
        }
    },
    methods : {
        doSave(){
            let prm = {
                'orderid':this.$store.state.patient.selected_patient.orderid,
                'delivery':this.$store.state.delivery.delivery
            }
            this.$store.dispatch("delivery/save",prm)
        },
        closeDialogBarcode(){
            if(this.savestatus !== 2){
                this.$store.commit("delivery/update_delivery_dialog",false)
            }
            else{
                let arrpatient = this.$store.state.patient.patients
                var idx = _.findIndex(arrpatient, item => item.idx === this.$store.state.patient.selected_patient.idx)
                console.log(idx)
                this.$store.dispatch("patient/search",{
                    search: this.$store.state.patient.search,
                    status: this.$store.state.patient.selected_status.value,
                    lastidx:idx
                })
                this.$store.commit("delivery/update_delivery_dialog",false)
            }
             
        },
        checkstatus(delivery){
            if(delivery.id > 0 && delivery.chex === 'N'){
                return 'Tidak Aktif'
            }
            else if(delivery.id > 0 && delivery.chex === 'Y'){
                return 'Aktif'
            }
            else if((delivery.id === 0 || delivery.id === '0') && delivery.chex === 'Y'){
                return 'Tambahan dari verification'
            }
        },
        updateDeliveryVerification(value,idx){
            var oldArr = this.$store.state.delivery.delivery_verification
            oldArr[idx].chex = value
            this.$store.commit("delivery/update_delivery_verification",oldArr)
        },
        updateDeliveryOther(value,idx){
            var oldArr = this.$store.state.delivery.delivery_other
            oldArr[idx].chex = value
            this.$store.commit("delivery/update_delivery_other",oldArr)
        },
        saveDeliveryAdditionVerification(){
            var prm = {
                    orderid:this.$store.state.patient.selected_patient.orderid,
                    delver:this.$store.state.delivery.delivery_verification
                }
            this.$store.dispatch("delivery/savedeliveryadditionalverification",prm)
        },
        saveDeliveryAdditionOther(){
            var prm = {
                    orderid:this.$store.state.patient.selected_patient.orderid,
                    delot:this.$store.state.delivery.delivery_other
                }
            this.$store.dispatch("delivery/savedeliveryadditionalother",prm)
        }
   }
}
</script>
