<template>
    <v-layout>
        <!-- Alert dialog -->
        <v-dialog v-model="dialogdeletealert" max-width="30%">
            <v-card>
                <v-card-title class="headline grey lighten-2 pt-2 pb-2" primary-title>
                    Peringatan !
                </v-card-title>
                <v-card-text class="pt-2 pb-2">
                    <v-layout row>
                        <v-flex xs12 d-flex>
                            <v-layout row>
                                <v-flex pb-1 xs12>
                                    <v-layout row>
                                        <v-flex pt-2 pr-2 xs12>
                                            {{ msgalert }}
                                        </v-flex>
                                    </v-layout>
                                </v-flex>
                            </v-layout>
                        </v-flex>
                    </v-layout>
                </v-card-text>
                <v-divider></v-divider>
                <v-card-actions>
                    <v-spacer></v-spacer>
                    <v-btn color="primary" flat @click="dialogdeletealert = false">
                        Tutup
                    </v-btn>
                    <v-btn color="primary" flat @click="deleteRow()">
                        Yakin lah
                    </v-btn>
                </v-card-actions>
            </v-card>
        </v-dialog>
        <!-- End alert dialog -->
        <!-- ERROR DIALOG -->
        <v-dialog v-model="dialog_error" max-width="500px">
            <v-card>
                <v-card-title>
                    <span>ERROR !</span>
                    <v-spacer></v-spacer>
                </v-card-title>
                <v-divider></v-divider>
                <div class="ma-3 red--text">{{ msgError }}</div>
                <v-divider></v-divider>
                <v-card-actions>
                    <v-spacer></v-spacer>
                    <v-btn color="primary" flat @click="dialog_error = false">Close</v-btn>
                </v-card-actions>
            </v-card>
        </v-dialog>
        <!-- END ERROR DIALOG -->
        <!-- Snackbar -->
        <v-snackbar v-model="snackbar" :timeout="5000" :multi-line="false" :vertical="false" :top="true" :color="clr"
            :value="snackbar">
            {{ msgsnackbar }}
            <v-btn flat @click="snackbar = false"> Tutup </v-btn>
        </v-snackbar>
        <!-- End Snackbar -->

        <!-- Form Dialog -->
        <v-dialog v-model="dialog_form" persistent width="50%">
            <v-card>
                <v-card-title>
                    <span class="title">Form Input Summary Kelainan Non Lab</span>
                </v-card-title>
                <v-divider></v-divider>
                <v-progress-linear v-if="loading_save" :indeterminate="true"></v-progress-linear>
                <v-card-text class="pt-3 pb-0">
                    <v-layout row wrap>
                        <v-flex xs12>
                            <v-autocomplete :disabled="isEdit" label="Nama Pemeriksaan*" :items="xtests" v-model="vtest"
                                :search-input.sync="search_item_test" auto-select-first no-filter
                                item-text="codeNameTest" return-object no-data-text="Pilih Nama Pemeriksaan" clearable
                                :error="test_error_message !== ''" :error-messages="test_error_message"
                                @blur="testValidation">
                                <template slot="item" slot-scope="{ item }">
                                    <v-list-tile-content>
                                        <v-list-tile-title v-text="item.codeNameTest"></v-list-tile-title>
                                    </v-list-tile-content>
                                </template>
                            </v-autocomplete>
                        </v-flex>
                    </v-layout>
                </v-card-text>

                <v-card-text class="pt-0 pb-0">
                    <v-layout row wrap>
                        <v-flex xs12>
                            <v-autocomplete :disabled="isEdit" label="Kelainan*" :items="xdatakelainans"
                                v-model="vdatakelainan" :search-input.sync="search_item_datakelainan" auto-select-first
                                no-filter item-text="Mcu_KelainanName" return-object no-data-text="Pilih Nama Kelainan"
                                clearable :error="kelainan_error_message !== ''"
                                :error-messages="kelainan_error_message" @blur="kelainanValidation">
                                <template slot="item" slot-scope="{ item }">
                                    <v-list-tile-content>
                                        <v-list-tile-title v-text="item.Mcu_KelainanName"></v-list-tile-title>
                                    </v-list-tile-content>
                                </template>
                            </v-autocomplete>
                        </v-flex>
                    </v-layout>
                </v-card-text>

                <v-card-text class="pt-0 pb-3">
                    <v-layout row wrap>
                        <v-flex xs12>
                            <v-select 
                                :error="fitness_error_message !== ''"
                                :error-messages="fitness_error_message" @blur="fitnessValidation"
                                v-model="vdatafitness"
                                :items="xdatafitness"
                                item-text="fitnessname"
                                item-value="Mcu_FitnessCategoryID" 
                                return-object label="Pilih Fitness Kategori">
                            </v-select>
                        </v-flex>
                    </v-layout>
                </v-card-text>

                <v-card-text class="pt-0 pb-0">
                    <v-layout row wrap>
                        <v-flex xs12>
                            <v-layout>
                                <v-flex xs7 pa-1>
                                    <v-autocomplete label="Nilai" v-model="xorderautostatusresult"
                                        :items="xorderautostatusresults" :search-input.sync="search_statusresult"
                                        auto-select-first no-filter item-text="NonlabConclusionDetailName" return-object
                                        no-data-text="Cari Nilai" outline small>
                                        <template slot="item" slot-scope="{ item }">
                                            <v-list-tile-content>
                                                <v-list-tile-title
                                                    v-text="item.NonlabConclusionDetailName"></v-list-tile-title>
                                            </v-list-tile-content>
                                        </template>
                                    </v-autocomplete>
                                </v-flex>
                                <v-flex xs5 pa-1>
                                    <v-btn @click="addStatus()" color="blue en-3">Tambah Nilai</v-btn>
                                </v-flex>
                            </v-layout>

                        </v-flex>

                        <v-flex v-for="(vst, idx) in xorderstatusresults" :key="vst.NonlabConclusionDetailID">
                            <v-btn class="mt-1 mb-2" @click="deleteDataStatus(idx)" small dark :color="'green'">
                                <v-icon left>close</v-icon>{{ vst.NonlabConclusionDetailName }}</v-btn>
                        </v-flex>

                </v-card-text>


                <v-divider></v-divider>
                <v-card-actions>
                    <v-spacer></v-spacer>
                    <v-btn color="primary" flat @click="dialog_form = false" :disabled="loading_save">Tutup</v-btn>
                    <v-btn v-if="xact === 'add'" color="primary" flat :disabled="loading_save"
                        @click="saveAdd()">Simpan</v-btn>
                    <v-btn v-if="xact === 'edit'" color="primary" flat :disabled="loading_save"
                        @click="saveEdit()">Simpan
                        Perubahan</v-btn>
                </v-card-actions>
            </v-card>
        </v-dialog>
        <!-- End Form Dialog -->

        <v-flex xs12>
            <v-card class="mb-2" color="white">
                <v-toolbar color="blue lighten-3" dark height="50px">
                    <v-toolbar-title>Master Summary Kelainan Non Lab</v-toolbar-title>
                    <v-spacer></v-spacer>
                    <v-btn @click="openForm(0)" icon>
                        <v-icon>library_add</v-icon>
                    </v-btn>
                </v-toolbar>
                <v-layout row style="background:white;padding-top:5px;padding-left: 2px;">
                    <v-layout row justify-left>
                        <v-flex xs3>
                            <v-text-field class="ma-1" label="Cari" placeholder="Cari Pemeriksaan atau Kelainan" outline
                                v-model="xsearch" hide-details></v-text-field>
                        </v-flex>
                    </v-layout>
                </v-layout>
                <v-divider></v-divider>
                <v-layout row class="scroll-container" style="max-height:645px;overflow: auto;">
                    <v-flex xs12 pl-2 pr-2 pt-2 pb-2>
                        <v-data-table :headers="headers" :items="xkelainanlab" :loading="isLoading" hide-actions
                            class="elevation-1">
                            <template slot="items" slot-scope="props">
                                <td class="text-xs-center pa-2"
                                    v-bind:class="{ 'amber lighten-4': isSelected(props.item) }"
                                    @click="selectMe(props.item)">{{ props.item.rownumber }}
                                </td>
                                <td class="text-xs-left pa-2"
                                    v-bind:class="{ 'amber lighten-4': isSelected(props.item) }"
                                    @click="selectMe(props.item)">{{ props.item.codeNameTest }}
                                </td>
                                <td class="text-xs-left pa-2"
                                    v-bind:class="{ 'amber lighten-4': isSelected(props.item) }"
                                    @click="selectMe(props.item)">
                                    {{ props.item.Mcu_KelainanName }}
                                </td>
                                <td class="text-xs-left pa-2"
                                    v-bind:class="{ 'amber lighten-4': isSelected(props.item) }"
                                    @click="selectMe(props.item)">
                                    <v-layout row wrap>
                                        <v-flex v-for="(p, i) in props.item.xvalue" v-bind:key="i">
                                            <v-btn class="mt-1 mb-2" small dark :color="'green'">{{
            p.NonlabConclusionDetailName }}</v-btn>
                                        </v-flex>
                                    </v-layout>
                                </td>
                                <td class="text-xs-center pa-2"
                                    v-bind:class="{ 'amber lighten-4': isSelected(props.item) }"
                                    @click="selectMe(props.item)">
                                    <v-tooltip bottom>
                                        <template v-slot:activator="{ on, attrs }">
                                            <v-icon v-bind="attrs" v-on="on" class="mr-3" @click="openEdit(props.item)"
                                                color="primary">edit
                                            </v-icon>
                                        </template>
                                        <span>Edit</span>
                                    </v-tooltip>
                                    <v-tooltip bottom>
                                        <template v-slot:activator="{ on, attrs }">
                                            <v-icon v-bind="attrs" v-on="on" @click="confirmDelete(props.item)"
                                                color="error">delete
                                            </v-icon>
                                        </template>
                                        <span>Hapus</span>
                                    </v-tooltip>
                                </td>
                            </template>
                        </v-data-table>
                        <v-divider></v-divider>
                        <v-layout>
                            <v-flex>
                                <v-pagination style="margin-top:10px;margin-bottom:10px" v-model="curr_page"
                                    :length="xtotal_page">
                                </v-pagination>
                            </v-flex>
                        </v-layout>
                    </v-flex>
                </v-layout>

            </v-card>
        </v-flex>

    </v-layout>
</template>

<style scoped>
.dot-text {
    position: relative;
    padding-left: 1.5em;
    /* Menambahkan padding untuk memberi ruang pada titik */
}

.dot-text::before {
    content: '•';
    /* Menambahkan titik di depan teks */
    position: absolute;
    left: 1em;
    /* Atur posisi titik */
    top: 0;
    transform: translateX(-100%);
}

.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;
}

.textinput {
    -webkit-transition: width 0.4s ease-in-out;
    transition: width 0.4s ease-in-out;
    background-color: white;
    background-position: 10px 10px;
    background-repeat: no-repeat;
    padding-left: 40px;
    width: 100%;
    padding: 8px 10px;
    margin-bottom: 5px;
    box-sizing: border-box;
    border: 1px solid #607d8b;

}

.textinput:focus {
    width: 100%;
}

.textinput:focus::-webkit-input-placeholder {
    color: transparent;
}

.textinput:focus::-moz-placeholder {
    color: transparent;
}

.textinput:-moz-placeholder {
    color: transparent;
}

.scroll-container {
    scroll-padding: 50px 0 0 50px;
}

::-webkit-scrollbar {
    width: 7px;
}

/* this targets the default scrollbar (compulsory) */

::-webkit-scrollbar-track {
    background-color: #73baf3;
}

/* the new scrollbar will have a flat appearance with the set background color */

::-webkit-scrollbar-thumb {
    background-color: #2196f3;
}

/* this will style the thumb, ignoring the track */

::-webkit-scrollbar-button {
    background-color: #0079da;
}

/* optionally, you can style the top and the bottom buttons (left and right for horizontal bars) */

::-webkit-scrollbar-corner {
    background-color: black;
}
</style>

<script>
module.exports = {
    data() {
        return {
            search_item_test: "",
            search_item_datakelainan: "",
            search_item_datafitness: "",
            xOperatorPerbandingan: "",
            nilaiPerbandingan: "",
            test_error_message: "",
            kelainan_error_message: "",
            fitness_error_message: "",
            operatorPerbandingan_error_message: "",
            clr: "success",
            xid: "",
            vtestcode: "",
            dialogdeletealert: false,
            msgalert: "",
            search_statusresult: "",
            headers: [{
                text: "NO",
                align: "Center",
                sortable: false,
                value: "mr",
                width: "5%",
                class: "pa-2 blue lighten-3 white--text"
            },
            {
                text: "PEMERIKSAAN",
                align: "Center",
                sortable: false,
                value: "mr",
                width: "20%",
                class: "pa-2 blue lighten-3 white--text"
            },
            {
                text: "KELAINAN",
                align: "Center",
                sortable: false,
                value: "mr",
                width: "20%",
                class: "pa-2 blue lighten-3 white--text"
            },
            {
                text: "STATUS NILAI",
                align: "Center",
                sortable: false,
                value: "mr",
                width: "40%",
                class: "pa-2 blue lighten-3 white--text"
            },
            {
                text: "AKSI",
                align: "Center",
                sortable: false,
                value: "mr",
                width: "10%",
                class: "pa-2 blue lighten-3 white--text"
            }]

        };
    },
    mounted() {
        this.$store.dispatch("kelainan/search")
        this.$store.dispatch("kelainan/getfitness")
    },
    computed: {
        xdatafitness() {
            return this.$store.state.kelainan.fitness
        },
        vdatafitness: {
            get() {
                return this.$store.state.kelainan.selected_fitness
            },
            set(val) {
                this.$store.commit("kelainan/update_selected_fitness", val)
            }
        },
        isEdit() {
            return this.xact === 'edit';
        },
        xkelainanlab() {
            return this.$store.state.kelainan.kelainanlab
        },
        isLoading() {
            return this.$store.state.kelainan.search_status == 1
        },
        curr_page: {
            get() {
                return this.$store.state.kelainan.current_page
            },
            set(val) {
                this.$store.commit("kelainan/update_current_page", val)
                this.$store.commit("kelainan/update_last_id", -1)
                this.$store.dispatch("kelainan/search")
            }
        },
        xtotal_page: {
            get() {
                return this.$store.state.kelainan.total_kelainanlab_page
            },
            set(val) {
                this.$store.commit("kelainan/update_total_kelainanlab_page", val)
            }
        },
        xsearch: {
            get() {
                return this.$store.state.kelainan.x_search
            },
            set(val) {
                this.$store.commit("kelainan/update_x_search", val)
            }
        },
        dialog_form: {
            get() {
                return this.$store.state.kelainan.dialog_form
            },
            set(val) {
                this.$store.commit("kelainan/update_dialog_form", val)
            },
        },
        loading_save: {
            get() {
                return this.$store.state.kelainan.loading_save
            },
            set(val) {
                this.$store.commit("kelainan/update_loading_save", val)
            },
        },
        xact: {
            get() {
                return this.$store.state.kelainan.act
            },
            set(val) {
                this.$store.commit("kelainan/update_act", val)
            }
        },
        xtests() {
            return this.$store.state.kelainan.tests
        },
        vtest: {
            get() {
                return this.$store.state.kelainan.selected_test
            },
            set(val) {
                this.$store.commit("kelainan/update_selected_test", val)
            }
        },
        xdatakelainans() {
            return this.$store.state.kelainan.datakelainans
        },
        vdatakelainan: {
            get() {
                return this.$store.state.kelainan.selected_datakelainan
            },
            set(val) {
                this.$store.commit("kelainan/update_selected_datakelainan", val)
            }
        },
        isNilaiNormal: {
            get() {
                return this.$store.state.kelainan.selected_isNilaiNormal
            },
            set(val) {
                this.$store.commit("kelainan/update_selected_isNilaiNormal", val)
            }
        },
        snackbar: {
            get() {
                return this.$store.state.kelainan.alert_success
            },
            set(val) {
                this.$store.commit("kelainan/update_alert_success", val)
            }
        },
        msgsnackbar() {
            return this.$store.state.kelainan.msg_success
        },
        dialog_error: {
            get() {
                return this.$store.state.kelainan.alert_error
            },
            set(val) {
                this.$store.commit("kelainan/update_alert_error", val)
            },
        },
        msgError() {
            return this.$store.state.kelainan.error_message
        },
        message_existing: {
            get() {
                return this.$store.state.kelainan.message_existing
            },
            set(val) {
                this.$store.commit("kelainan/update_message_existing", val)
            },
        },
        xorderautostatusresults() {
            return this.$store.state.kelainan.orderautostatusresults
        },
        xorderautostatusresult: {
            get() {
                return this.$store.state.kelainan.orderautostatusresult
            },
            set(val) {
                this.$store.commit("kelainan/update_orderautostatusresult", val)
            }
        },
        xorderstatusresults() {
            return this.$store.state.kelainan.orderstatusresults
        }
    },
    methods: {
        isSelected(p) {
            return p.Mcu_SummaryNonlabID == this.$store.state.kelainan.selected_kelainanlab.Mcu_SummaryNonlabID
        },
        selectMe(selected) {
            this.$store.commit("kelainan/update_selected_kelainanlab", selected)
            this.$store.commit("kelainan/update_last_id", selected.Mcu_SummaryNonlabID)

            // set value selected test
            this.$store.commit("kelainan/update_tests", [
                {
                    Nat_TestID: selected.Nat_TestID,
                    codeNameTest: selected.codeNameTest,
                    Nat_TestCode: selected.Nat_TestCode
                }
            ])
            this.$store.commit("kelainan/update_selected_test", {
                Nat_TestID: selected.Nat_TestID,
                codeNameTest: selected.codeNameTest,
                Nat_TestCode: selected.Nat_TestCode
            })

            // set value selected kelainan
            this.$store.commit("kelainan/update_datakelainans", [
                {
                    Mcu_KelainanID: selected.Mcu_KelainanID,
                    Mcu_KelainanName: selected.Mcu_KelainanName
                }
            ])
            this.$store.commit("kelainan/update_selected_datakelainan", {
                Mcu_KelainanID: selected.Mcu_KelainanID,
                Mcu_KelainanName: selected.Mcu_KelainanName
            })

            // set value selected fitness
            this.$store.commit("kelainan/update_fitness", [
                {
                    Mcu_FitnessCategoryID: selected.Mcu_FitnessCategoryID,
                    fitnessname: selected.fitnessname
                }
            ])
            this.$store.commit("kelainan/update_selected_fitness", {
                Mcu_FitnessCategoryID: selected.Mcu_FitnessCategoryID,
                fitnessname: selected.fitnessname
            })

            this.$store.dispatch("kelainan/getfitness")
        },
        thr_search: _.debounce(function () {
            this.$store.dispatch("kelainan/search")
        }, 1000),
        thr_search_test: _.debounce(function () {
            this.$store.dispatch("kelainan/searchtest", this.search_item_test)
        }, 2000),
        thr_search_datakelainan: _.debounce(function () {
            this.$store.dispatch("kelainan/searchkelainan", this.search_item_datakelainan)
        }, 2000),
        thr_search_statusresult: _.debounce(function () {
            this.$store.dispatch("kelainan/search_statusresult", this.search_statusresult)
        }, 2000),
        testValidation() {
            if (_.isEmpty(this.vtest)) {
                this.test_error_message = 'Anda belum memilih pemeriksaan'
            }
            if (this.vtest) {
                this.test_error_message = ""
            }
        },
        addStatus() {
            var oldArr = this.$store.state.kelainan.orderstatusresults
            oldArr.push(this.$store.state.kelainan.orderautostatusresult)
            this.search_statusresult = ''
            this.$store.commit("kelainan/update_orderautostatusresults", [])
            this.$store.commit("kelainan/update_orderautostatusresult", {})
        },
        deleteDataStatus(idx) {
        var inx = parseInt(idx);
        var xrow = this.$store.state.kelainan.orderstatusresults[inx]
        if (parseInt(xrow.xid) !== 0) {
          var xdeltest = this.$store.state.kelainan.deleted_orderstatusresults
          xdeltest.push(xrow)
          this.$store.commit("kelainan/update_deleted_orderstatusresults", xdeltest)
        }
        var oldArr = this.$store.state.kelainan.orderstatusresults
        oldArr.splice(inx, 1)
        this.$store.commit("kelainan/update_orderstatusresults", oldArr)
      },
        kelainanValidation() {
            if (_.isEmpty(this.vdatakelainan)) {
                this.kelainan_error_message = 'Anda belum memilih kelainan'
            }
            if (this.vdatakelainan) {
                this.kelainan_error_message = ""
            }
        },
        operatorValidation() {
            if (_.isEmpty(this.xOperatorPerbandingan)) {
                this.operatorPerbandingan_error_message = 'Anda belum memilih operator perbandingan'
            }
            if (this.xOperatorPerbandingan) {
                this.operatorPerbandingan_error_message = ""
            }
        },
        fitnessValidation() {
            if (_.isEmpty(this.vdatafitness)) {
                this.fitness_error_message = 'Anda belum memilih fitness'
            }
            if (this.vdatafitness) {
                this.fitness_error_message = ""
            }
        },
        resetAllInput() {
            this.vtest = ""
            this.vdatakelainan = ""
            this.vdatafitness = ""
            this.xorderstatusresults = [{NonlabConclusionDetailID:"0",NonlabConclusionDetailCode:"",NonlabConclusionDetailName:""}]
            this.test_error_message = ""
            this.kelainan_error_message = ""
            this.operatorPerbandingan_error_message = ""
            this.fitness_error_message = ""
            this.message_existing = ""
        },
        resetAllError() {
            this.test_error_message = ""
            this.kelainan_error_message = ""
            this.operatorPerbandingan_error_message = ""
            this.fitness_error_message = ""
            this.message_existing = ""
        },
        openForm() {
            this.dialog_form = true
            this.$store.commit("kelainan/update_act", "add")
            this.$store.commit("kelainan/update_last_id", -1)
            this.resetAllInput()
        },
        handleSwitchChange() {
            if (this.isNilaiNormal) {
                this.nilaiPerbandingan = '';
            }
        },
        saveAdd() {
            this.testValidation()
            this.kelainanValidation()
            this.fitnessValidation()
            if (this.test_error_message === "" &&
                this.kelainan_error_message === "" &&
                this.fitness_error_message === ""
            ) {
                let prm = {
                    testId: this.vtest.Nat_TestID,
                    testCode: this.vtest.Nat_TestCode,
                    kelainanId: this.vdatakelainan.Mcu_KelainanID,
                    orderstatusresults: this.xorderstatusresults,
                    fitnessId: this.vdatafitness.Mcu_FitnessCategoryID
                }

                // console.log('cek prm',prm)
                this.$store.dispatch("kelainan/add", prm)
            }
        },
        openEdit(data) {


            this.selectMe(data)
            this.dialog_form = true
            this.$store.commit("kelainan/update_act", "edit")
            this.xid = data.Mcu_SummaryNonlabID
            this.vtest = data.Nat_TestID
            this.vdatakelainan = data.Mcu_KelainanID
            this.vdatafitness = data.Mcu_FitnessCategoryID
            this.$store.commit("kelainan/update_orderstatusresults", data.xvalue)
            this.$store.commit("kelainan/update_last_id", data.Mcu_SummaryNonlabID)
            this.resetAllError()
        },
        saveEdit() {
            this.testValidation()
            this.kelainanValidation()
            this.fitnessValidation()
            if (this.test_error_message === "" &&
                this.kelainan_error_message === "" &&
                this.fitness_error_message === ""
            ) {
                let prm = {
                    xid: this.xid,
                    orderstatusresults: this.xorderstatusresults,
                    fitnessId: this.vdatafitness.Mcu_FitnessCategoryID
                }
                this.$store.dispatch("kelainan/edit", prm)
            }
        },
        confirmDelete(data) {
            this.selectMe(data)
            this.xid = data.Mcu_SummaryNonlabID
            this.msgalert = "Yakin, mau hapus kelainan lab " + data.codeNameTest + " ?"

            this.dialogdeletealert = true
        },
        deleteRow() {
            this.$store.commit("kelainan/update_last_id", -1)
            let prm = {
                xid: this.xid
            }
            this.$store.dispatch("kelainan/deleterow", prm)
            this.dialogdeletealert = false
        }
    },
    watch: {
        xsearch(val, old) {
            this.xsearch = val
            this.thr_search()
        },
        search_statusresult(val, old) {
            if (val == old) return
            if (!val) return
            if (val.length < 1) return
            if (this.$store.state.kelainan.update_autocomplete_status == 1) return
            this.thr_search_statusresult()
        },
        search_item_test(val, old) {
            if (val == old) return
            if (!val) return

            if (val.length < 1) {
                this.$store.dispatch("kelainan/searchtest", this.search_item_test)
                return this.thr_search_test()
            }

            if (val.length > 2) {
                this.$store.dispatch("kelainan/searchtest", this.search_item_test)
                return this.thr_search_test()
            }
        },

        search_item_datakelainan(val, old) {
            if (val == old) return
            if (!val) return

            if (val.length < 1) {
                this.$store.dispatch("kelainan/searchkelainan", this.search_item_datakelainan)
                return this.thr_search_datakelainan()
            }

            if (val.length > 2) {
                this.$store.dispatch("kelainan/searchkelainan", this.search_item_datakelainan)
                return this.thr_search_datakelainan()
            }
        }
    }
}
</script>