<template>
    <v-layout class="fill-height" column>

        <v-card class="mb-2">
            <v-subheader red--text text--lighten-1>
                MULTI RULE DETAIL
                <v-flex text-md-right>
                    <v-btn small @click="openFormMultiruleDetail()" 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="xcriterias" :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.T_TestName">

                            </td>
                            <td class="text-xs-left pa-2" v-html="props.item.M_ValueName">
                            </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="dialogmultiruledetail" persistent max-width="600px">
                    <v-card>
                        <v-card-title>
                            <span class="headline">Form Multirule Detail</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="Pemeriksaan*" v-model="xtest" :items="xtests" :search-input.sync="search_test" auto-select-first no-filter
                                            item-text="T_TestName" return-object :loading="isLoading" no-data-text="Pilih Pemeriksaan">
                                            <template slot="item" slot-scope="{ item }">
                                                <v-list-tile-content>
                                                    <v-list-tile-title v-text="item.T_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="xvaluexs" v-model="xvaluex" label="Hasil"></v-select>
                                    </v-flex>
                                </v-layout>
                        </v-card-text>
                        <v-card-actions>
                            <v-spacer></v-spacer>
                            <v-btn color="blue darken-1" flat @click="updateDialogFormMultiruleDetail()">Tutup</v-btn>
                            <v-btn color="blue darken-1" flat @click="saveFormMultiruleDetail()">Simpan</v-btn>
                        </v-card-actions>
                        </v-form>
                    </v-card>
                </v-dialog>
            </v-layout>
        </template>
    </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: {
            updateDialogFormMultiruleDetail() {
                this.$store.commit("sample/update_dialog_form_multiruledetail", false)
            },
            openFormMultiruleDetail() {
                this.$refs.formmultirule.reset()
                this.$refs.formmultirule.resetValidation()
                this.$store.commit("sample/update_dialog_form_multiruledetail", true)
            },
            saveFormMultiruleDetail() {
                this.$store.dispatch("sample/savemultiruledetail", {
                    testid: this.xtest.T_TestID,
                    multiruleid: this.$store.state.sample.selected_detail.Nat_MultiruleID,
                    valueid: this.xvaluex.M_ValueID,
                    mastertest: this.$store.state.sample.selected_transaction.T_TestID
                })

            },
            thr_search_test: _.debounce(function () {
                this.$store.dispatch("sample/searchtest", this.search_test)
            }, 2000)
        },
        computed: {
            dialogmultiruledetail() {
                return this.$store.state.sample.dialog_form_multiruledetail
            },
            isLoading() {
                return this.$store.state.sample.search_status == 1
            },
            xcriterias() {
                return this.$store.state.sample.criterias
            },
            xfiltermethode() {
                return this.$store.state.sample.filter_methodes
            },
            xselected_filter_methode: {
                get() {
                    return this.$store.state.sample.selected_filter_methode
                },
                set(val) {
                    this.$store.commit("form/update_selected_filter_methode", val)
                }
            },
            xtests() {
                return this.$store.state.sample.tests
            },
            xtest: {
                get() {
                    return this.$store.state.sample.test
                },
                set(val) {
                    this.$store.commit("sample/update_test", val)
                }
            },
            xvaluexs() {
                return this.$store.state.sample.valuexs
            },
            xvaluex: {
                get() {
                    return this.$store.state.sample.valuex
                },
                set(val) {
                    this.$store.commit("sample/update_valuex", val)
                }
            },
            xspilih: {
                get() {
                    return this.$store.state.sample.spilih
                },
                set(val) {
                    this.$store.commit("sample/update_spilih", val)
                }
            },
            xsmultiruleid: {
                get() {
                    return this.$store.state.sample.smultiruleid
                },
                set(val) {
                    this.$store.commit("sample/update_smultiruleid", val)
                }
            }
        },
        data() {
            return {
                msgalertconfirmation: "Perubahan yang telah dilakukan belum disimpan dong !",
                menufilterdatestart: false,
                menufilterdateend: false,
                date: new Date().toISOString().substr(0, 10),
                items: [],
                name: '',
                search_test: '',
                page: 1,
                headers: [{
                        text: "PEMERIKSAAN",
                        align: "center",
                        sortable: false,
                        width: "30%",
                        class: "pa-2 blue lighten-3 white--text"
                    },
                    {
                        text: "HASIL",
                        align: "center",
                        sortable: false,
                        width: "10%",
                        class: "pa-2 blue lighten-3 white--text"
                    }

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

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