<template>
    <v-layout>
        <v-flex xs12>
            <v-card class="mb-2">
                <v-subheader red--text text--lighten-1>
                    Reflex Test Kualitatif
                    <v-flex text-md-right>
                        <v-btn small @click="openFormMultiRule()" color="info">TAMBAH DATA</v-btn>
                    </v-flex>
                </v-subheader>
                <v-divider></v-divider>
                <v-layout row>
                    <v-flex xs12 pl-2 pr-2 pt-2 pb-2>
                        <v-data-table :headers="headers" :items="xnatmultirules" :loading="isLoading" :pagination.sync="pagination" class="elevation-1">
                            <template slot="items" slot-scope="props">
                                <td class="text-xs-left pa-2" v-html="props.item.Nat_TestName">
                                </td>
                                <td class="text-xs-left pa-2" v-html="props.item.Nat_TestName">
                                </td>
                            </template>
                            <template>
                                <div class="text-xs-center">
                                    <v-pagination v-model="page" :length="15" :total-visible="7"></v-pagination>
                                </div>
                            </template>
                        </v-data-table>
                    </v-flex>
                </v-layout>
            </v-card>
            <template>
                <v-layout row justify-center>
                    <v-dialog v-model="dialogqualitative" persistent max-width="600px">
                        <v-card>
                            <v-card-title>
                                <span class="headline">Form Reflex Test Kualitatif</span>
                            </v-card-title>
                            <v-card-text class="pt-0 pb-0">
                                <v-form ref="formmultirule" lazy-validation>
                                    <v-layout wrap>
                                        <v-flex xs12>
                                            <v-autocomplete label="Test" v-model="xtestqualitative" :items="xtestqualitatives" :search-input.sync="search_testqualitative" auto-select-first no-filter
                                                item-text="Nat_TestName" return-object :loading="isLoading" no-data-text="Pilih Test">
                                                <template slot="item" slot-scope="{ item }">
                                                    <v-list-tile-content>
                                                        <v-list-tile-title v-text="item.Nat_TestName"></v-list-tile-title>
                                                    </v-list-tile-content>
                                                </template>
                                            </v-autocomplete>
                                        </v-flex>
                                        <v-flex xs12>
                                            <v-select item-text="M_ValueName" return-object :items="xvaluequalitativees" v-model="xvaluequalitative" label="Nilai"></v-select>
                                        </v-flex>
                                    </v-layout>
                            </v-card-text>
                            <v-card-actions>
                                <v-spacer></v-spacer>
                                <v-btn color="blue darken-1" flat @click="updateDialogFormMultiRule()">Tutup</v-btn>
                                <v-btn color="blue darken-1" flat @click="saveFormMultiRule()">Simpan</v-btn>
                            </v-card-actions>
                            </v-form>
                        </v-card>
                    </v-dialog>
                </v-layout>
            </template>
        </v-flex>
    </v-layout>
</template>

<style scoped>
    .searchbox .v-input.v-text-field .v-input__slot {
        min-height: 60px;
    }

    .searchbox .v-btn {
        min-height: 60px;
    }

    table.v-table tbody td,
    table.v-table tbody th {
        height: 40px;
    }

    table.v-table thead tr {
        height: 40px;
    }
</style>

<script>
    module.exports = {
        components: {
            'one-md-test-conclusion-dialog-normal-value': httpVueLoader(
                './oneMdTestConclusionDialogNormalValue.vue'),
            'one-dialog-alert': httpVueLoader('../../common/oneDialogAlert.vue')
        },
        methods: {
            updateDialogFormMultiRule() {
                this.$store.commit("multirule/update_dialog_form_qualitative", false)
            },
            openFormMultiRule() {
                this.$refs.formmultirule.reset()
                this.$refs.formmultirule.resetValidation()
                this.$store.commit("multirule/update_dialog_form_qualitative", true)
            },
            saveFormMultiRule() {
                this.$store.dispatch("multirule/savemultirule", {
                    testid: this.xtest.Nat_TestID,
                    multiruleid: this.$store.state.multirule.selected_detail.Nat_MultiruleID,
                    valueid: this.xvaluex.M_ValueID,
                    mastertest: this.$store.state.multirule.selected_transaction.Nat_TestID
                })

            },
            thr_search_testqualitative: _.debounce(function () {
                this.$store.dispatch("multirule/searchtestqualitative", this.search_testqualitative)
            }, 2000)
        },
        computed: {
            dialogqualitative() {
                return this.$store.state.multirule.dialog_form_qualitative
            },
            isLoading() {
                return this.$store.state.multirule.search_status == 1
            },
            xnattest() {
                return this.$store.state.multirule.selected_multirule
            },
            xnatmultirules() {
                return this.$store.state.multirule.natmultirules
            },
            xfiltermethode() {
                return this.$store.state.multirule.filter_methodes
            },
            xselected_filter_methode: {
                get() {
                    return this.$store.state.multirule.selected_filter_methode
                },
                set(val) {
                    this.$store.commit("form/update_selected_filter_methode", val)
                }
            },
            xtestqualitatives() {
                return this.$store.state.multirule.testqualitatives
            },
            xtestqualitative: {
                get() {
                    return this.$store.state.multirule.testqualitative
                },
                set(val) {
                    this.$store.commit("multirule/update_testqualitative", val)
                }
            },
            xvaluexs() {
                return this.$store.state.multirule.valuexs
            },
            xvaluex: {
                get() {
                    return this.$store.state.multirule.valuex
                },
                set(val) {
                    this.$store.commit("multirule/update_valuex", val)
                }
            },
            xspilih: {
                get() {
                    return this.$store.state.multirule.spilih
                },
                set(val) {
                    this.$store.commit("multirule/update_spilih", val)
                }
            },
            xsmultiruleid: {
                get() {
                    return this.$store.state.multirule.smultiruleid
                },
                set(val) {
                    this.$store.commit("multirule/update_smultiruleid", val)
                }
            },
            xvaluequalitativees() {
                return this.$store.state.multirule.valuequalitativees
            },
            xvaluequalitative: {
                get() {
                    return this.$store.state.multirule.selected_valuequalitative
                },
                set(val) {
                    this.$store.commit("multirule/update_selected_valuequalitative", val)
                }
            }
        },
        data() {
            return {
                msgalertconfirmation: "Perubahan yang telah dilakukan belum disimpan dong !",
                menufilterdatestart: false,
                menufilterdateend: false,
                date: new Date().toISOString().substr(0, 10),
                items: [],
                name: '',
                xnilai: '',
                xelow: '',
                xehigh: '',
                search_testqualitative: '',
                page: 1,
                headers: [{
                        text: "TEST",
                        align: "center",
                        sortable: false,
                        width: "30%",
                        class: "pa-2 grey lighten-1 white--text"
                    },
                    {
                        text: "NILAI",
                        align: "center",
                        sortable: false,
                        width: "20%",
                        class: "pa-2 grey lighten-1 white--text"
                    }

                ],
                headers_search: [{
                        text: "PASIEN",
                        align: "left",
                        sortable: false,
                        width: "20%",
                        class: "pa-2 grey lighten-1 white--text"
                    },
                    {
                        text: "BARCODE",
                        align: "center",
                        sortable: false,
                        width: "15%",
                        class: "pa-2 grey lighten-1 white--text"
                    },
                    {
                        text: "ALMARI",
                        align: "left",
                        sortable: false,
                        width: "25%",
                        class: "pa-2 grey lighten-1 white--text"
                    },
                    {
                        text: "RAK",
                        align: "center",
                        sortable: false,
                        width: "15%",
                        class: "pa-2 grey lighten-1 white--text"
                    },

                    {
                        text: "POSISI",
                        align: "center",
                        sortable: false,
                        width: "10%",
                        class: "pa-2 grey lighten-1 white--text"
                    },
                    {
                        text: "AKSI",
                        align: "center",
                        sortable: false,
                        width: "10%",
                        class: "pa-2 grey lighten-1 white--text"
                    }
                ],
                pagination: {
                    descending: false,
                    page: 1,
                    rowsPerPage: 5,
                    sortBy: 'trx_id ASC',
                    totalItems: this.$store.state.multirule.total_transactions
                }
            };
        },
        watch: {
            search_testqualitative(val, old) {
                if (val == old) return
                if (!val) return
                if (val.length < 1) return
                if (this.$store.state.multirule.update_autocomplete_status == 1) return
                this.thr_search_testqualitative()
            }
        }
    }
</script>