<template>
    <v-layout>
        <template>

            <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="closeDeleteAlert()">
                            Yakin lah
                        </v-btn>
                    </v-card-actions>
                </v-card>
            </v-dialog>

            <!-- Alert dialog Form Kosong Start -->
            <v-dialog v-model="dialogalertshow" max-width="30%">
                <v-card>
                    <v-card-title class="headline grey lighten-2 pt-2 pb-2" primary-title>
                        Peringatan Form Kosong!
                    </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>
                                                <!-- <p id="error-break-line">{{ msgalertshow }}</p> -->
                                                <p style="white-space:pre-wrap;">{{ msgalertshow }}</p>
                                            </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="dialogalertshow = false">
                            Tutup
                        </v-btn>
                    </v-card-actions>
                </v-card>
            </v-dialog>
            <!-- End alert dialog Form Kosong End -->

            <v-dialog v-model="dialogdokter" persistent max-width="600px">
                <v-card>
                    <v-card-title>
                        <span class="headline">FORM USER DOKTER</span></v-card-title>
                    <v-card-text class="pt-0 pb-0">
                        <v-form ref="formdokter" v-model="valid" lazy-validation>
                            <v-layout wrap>
                                <!-- dokter -->
                                <v-flex xs12>
                                    <v-autocomplete label="Dokter*" v-model="xitemdokter" :items="xitemdokters"
                                        :search-input.sync="search_autocomplete_dokter" auto-select-first no-filter
                                        item-text="M_DoctorName" return-object :loading="isLoading"
                                        no-data-text="Pilih Dokter" placeholder="Ketikkan minimal 3 karakter">
                                        <template slot="item" slot-scope="{ item }">
                                            <v-list-tile-content>
                                                <v-list-tile-title v-text="item.M_DoctorName"></v-list-tile-title>
                                            </v-list-tile-content>
                                        </template>
                                    </v-autocomplete>
                                </v-flex>
                                <!-- doctor id -->
                                <v-flex xs12>
                                    <v-text-field v-model="xdoctorid" label="Doktor ID*" type="number"
                                        readonly></v-text-field>
                                </v-flex>
                                <!-- username -->
                                <v-flex xs12>
                                    <v-text-field v-model="xusername" label="Username*"></v-text-field>
                                </v-flex>
                                <!-- password -->
                                <v-flex xs12 v-if="xact === 'new'">
                                    <v-text-field v-if="xact === 'new'" v-model="xpassword" type="password"
                                        label="Password*"></v-text-field>
                                </v-flex>
                                <!-- konfirmasi password -->
                                <v-flex xs12 v-if="xact === 'new'">
                                    <v-text-field v-if="xact === 'new'" v-model="xpasswordconfirm" type="password"
                                        label="Konfirmasi Password*"></v-text-field>
                                </v-flex>
                                <!-- aggrement -->
                                <v-flex xs12>
                                    <v-autocomplete label="Aggrement*" v-model="xitemmou" :items="xitemmous"
                                        :search-input.sync="search_autocomplete_mou" auto-select-first no-filter
                                        item-text="M_MouName" return-object :loading="isLoading"
                                        no-data-text="Pilih Aggrement" placeholder="Ketikkan minimal 3 karakter">
                                        <template slot="item" slot-scope="{ item }">
                                            <v-list-tile-content>
                                                <v-list-tile-title v-text="item.M_MouName"></v-list-tile-title>
                                            </v-list-tile-content>
                                        </template>
                                    </v-autocomplete>
                                </v-flex>
                                <v-flex>
                                    <p v-for="(xerror, idx) in xerrors" class="error pl-2 pr-2" style="color:#fff">
                                        {{ xerror.msg }}</p>
                                </v-flex>
                            </v-layout>
                    </v-card-text>
                    <v-card-actions>
                        <v-spacer></v-spacer>
                        <v-btn color="blue darken-1" flat @click="updateDialogFormdokter()">Tutup</v-btn>
                        <v-btn v-if="xact === 'new'" color="blue darken-1" flat @click="saveFormdokter()">Simpan</v-btn>
                        <v-btn v-if="xact === 'edit'" color="blue darken-1" flat @click="updateFormdokter()">Simpan
                            Perubahan</v-btn>
                    </v-card-actions>
                    </v-form>
                </v-card>
            </v-dialog>
        </template>


        <v-flex xs12>
            <v-card>
                <v-toolbar color="blue lighten-3" dark height="50px">
                    <v-toolbar-title>USER DOKTER</v-toolbar-title>
                    <v-spacer></v-spacer>
                    <v-btn @click="openFormdokter(0)" icon>
                        <v-icon>library_add</v-icon>
                    </v-btn>
                </v-toolbar>
                <v-snackbar v-model="snackbar" :timeout="5000" :multi-line="false" :vertical="false" :top="true">
                    {{ msgsnackbar }}
                    <v-btn flat @click="updateAlert_success(false)">
                        Tutup
                    </v-btn>
                </v-snackbar>
                <v-snackbar v-model="alerterror" :timeout="5000" :multi-line="false" :vertical="false" :top="true">
                    {{ msgerror }}
                    <v-btn flat @click="updateAlert_error(false)">
                        Tutup
                    </v-btn>
                </v-snackbar>
                <v-layout row style="background:#bbdefb;padding-top:5px;" justify-left>
                    <v-flex xs3>
                        <v-list-tile>
                            <input type="text" v-model="xsearch" class="textinput" label="Nama Spesialist"
                                placeholder="Cari ..." />
                            </v-list-tile-content>
                        </v-list-tile>
                    </v-flex>

                    <v-flex xs6>
                        <v-btn @click="doPrint()" small color="default" dark>cetak <v-icon small right
                                dark>print</v-icon></v-btn>
                    </v-flex>
                </v-layout>

                <v-divider></v-divider>
                <div>

                    <v-layout row class="scroll-container" style="max-height:600px;overflow: auto;">
                        <v-flex xs12 pl-2 pr-2 pt-2 pb-2>
                            <v-data-table :headers="headers" :items="vdokters" :loading="isLoading" hide-actions
                                class="elevation-1">
                                <template slot="items" slot-scope="props">
                                    <td class="text-xs-left pa-2"
                                        v-bind:class="{ 'amber lighten-4': isSelected(props.item) }"
                                        @click="selectMe(props.item)">
                                        {{ props.item.M_UserM_DoctorCode }}</td>
                                    <td class="text-xs-left pa-2"
                                        v-bind:class="{ 'amber lighten-4': isSelected(props.item) }"
                                        @click="selectMe(props.item)">
                                        {{ props.item.M_DoctorName }}</td>
                                    <td class="text-xs-left pa-2"
                                        v-bind:class="{ 'amber lighten-4': isSelected(props.item) }"
                                        @click="selectMe(props.item)">
                                        {{ props.item.M_UserUsername }}</td>
                                    <td class="text-xs-left pa-2"
                                        v-bind:class="{ 'amber lighten-4': isSelected(props.item) }"
                                        @click="selectMe(props.item)">
                                        {{ props.item.M_MouName }}</td>
                                    <td class="text-xs-left pa-2"
                                        v-bind:class="{ 'amber lighten-4': isSelected(props.item) }"
                                        @click="selectMe(props.item)">
                                        <v-icon small class="ml-3" color="primary"
                                            @click="editdokter(props.item)">edit</v-icon>
                                        <v-icon small class="ml-3" color="error"
                                            @click="deletedokter(props.item)">clear</v-icon>
                                    </td>
                                </template>
                            </v-data-table>
                        </v-flex>

                        <!-- print -->
                        <one-dialog-print :title="printtitle" :width="printwidth" :height="550" :status="openprintnote"
                            :urlprint="urlprintnote" @close-dialog-print="openprintnote = false"></one-dialog-print>
                    </v-layout>



                    <v-divider></v-divider>
                    <v-pagination style="margin-top:10px;margin-bottom:10px" v-model="curr_page"
                        :length="xtotal_page"></v-pagination>
                </div>




            </v-card>
        </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;
}

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

.boxoutline {
    color: red;
    border: 1px solid red;
    justify-content: center;
    height: 45px;
    line-height: 45px;
    padding-left: 10px;
    background: #ffffff;
    font-size: 14px;
    font-weight: 500;
    border-radius: 1px
}

.boxoutline:hover {
    background: rgba(0, 0, 0, 0.07) !important;
    font-size: 15px;
    font-weight: 700;
}

.boxsolid {
    color: #ffffff;
    border: 1px solid #ffffff;
    justify-content: center;
    height: 45px;
    line-height: 45px;
    padding-left: 10px;
    background: #f44336;
    font-size: 14px;
    font-weight: 500;
    border-radius: 1px
}

.boxsolid:hover {
    background: #f44336de;
    font-size: 15px;
    font-weight: 700;
}

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

/* if both the vertical and the horizontal bars appear, then perhaps the right bottom corner also needs to be styled */
</style>

<script>
module.exports = {
    components: {
        'one-dialog-print': httpVueLoader('../../../common/oneDialogPrintX.vue')
    },
    data() {
        return {
            urlprintnote: '',
            printtitle: '',
            printwidth: '80%',
            msgalertconfirmation: "Perubahan yang telah dilakukan belum disimpan dong !",
            dialogdeletealert: false,
            msgalert: "",
            valid: false,
            xid: 0,
            search_instrument: '',
            items: [],

            // tambahan
            xdoctorid: '',
            xusername: '',
            xpassword: '',
            xpasswordconfirm: '',

            // dropdown dokter
            search_autocomplete_dokter: '',

            // dropdown mou
            search_autocomplete_mou: '',

            dialogalertshow: false,
            msgalertshow: '',
            msgalertshowobj: {},

            xname: '',
            xcode: '',
            xnameRules: [
                v => !!v || 'Nama harus diisi'
            ],
            instrumentRules: [
                v => !!v || 'Instrument harus dipilih'
            ],
            name: '',
            isdefault: false,
            scode: '',
            search_dokter: '',
            search_testheader: '',
            search_template: '',
            page: 1,
            headers: [
                {
                    text: "DOCTOR ID",
                    align: "left",
                    sortable: false,
                    value: "mr",
                    width: "20%",
                    class: "pa-2 blue lighten-3 white--text"
                },
                {
                    text: "NAMA",
                    align: "left",
                    sortable: false,
                    value: "mr",
                    width: "20%",
                    class: "pa-2 blue lighten-3 white--text"
                },
                {
                    text: "USERNAME",
                    align: "left",
                    sortable: false,
                    value: "mr",
                    width: "20%",
                    class: "pa-2 blue lighten-3 white--text"
                },
                {
                    text: "AGGREMENT",
                    align: "left",
                    sortable: false,
                    value: "mr",
                    width: "20%",
                    class: "pa-2 blue lighten-3 white--text"
                },
                {
                    text: "AKSI",
                    align: "left",
                    sortable: false,
                    value: "mr",
                    width: "10%",
                    class: "pa-2 blue lighten-3 white--text"
                }
            ],
            pagination: {
                descending: true,
                page: 1,
                rowsPerPage: 100,
                sortBy: 'M_UserID DESC',
                totalItems: this.$store.state.dokter.total_filter_dokters
            }
        };
    },
    mounted() {
        this.$store.dispatch("dokter/search", {
            search: this.xsearch,
            search: this.$store.state.dokter.x_search,
            current_page: 1,
            lastid: -1
        })

        // dropdown item dokter initial load
        this.$store.dispatch("dokter/searchdokterautocomplete", this.search_autocomplete_dokter)

        // dropdown item mou initial load
        // this.$store.dispatch("dokter/searchmouautocomplete", this.search_autocomplete_mou)
    },
    computed: {
        // dropdown dokter
        xitemdokters() {
            return this.$store.state.dokter.itemdokters
        },
        xitemdokter: {
            get() {
                return this.$store.state.dokter.itemdokter
            },
            set(val) {
                this.$store.commit("dokter/update_itemdokter", val)
                // set doctor code
                !_.isEmpty(val) ? this.xdoctorid = val.M_DoctorCode : this.xdoctorid = ''
            }
        },

        // dropdown mou
        xitemmous() {
            return this.$store.state.dokter.itemmous
        },
        xitemmou: {
            get() {
                // console.log('item mou ', this.$store.state.dokter.itemmou)
                return this.$store.state.dokter.itemmou
            },
            set(val) {
                this.$store.commit("dokter/update_itemmou", val)
            }
        },

        xact() {
            return this.$store.state.dokter.act
        },
        xerrors() {
            return this.$store.state.dokter.errors
        },
        xshowall() {
            return this.$store.state.dokter.show_all
        },
        vdokters() {
            return this.$store.state.dokter.dokters
        },
        xtotaldokters() {
            return this.$store.state.dokter.total_dokters
        },
        xtotalfilterdokters() {
            return this.$store.state.dokter.total_filter_dokters
        },
        xsearch: {
            get() {
                return this.$store.state.dokter.x_search
            },
            set(val) {
                this.$store.commit("dokter/update_x_search", val)
            }
        },
        curr_page: {
            get() {
                return this.$store.state.dokter.current_page
            },
            set(val) {
                this.$store.commit("dokter/update_current_page", val)
                this.$store.dispatch("dokter/search", {
                    search: this.xsearch,
                    search: this.$store.state.dokter.x_search,
                    current_page: val,
                    lastid: -1
                })
            }
        },
        xtotal_page: {
            get() {
                return this.$store.state.dokter.total_dokters
            },
            set(val) {
                this.$store.commit("dokter/update_total_dokters", val)
            }
        },
        dialogdokter() {
            return this.$store.state.dokter.dialog_form_dokter
        },
        snackbar: {
            get() {
                return this.$store.state.dokter.alert_success
            },
            set(val) {
                this.$store.commit("dokter/update_alert_success", val)
            }
        },
        msgsnackbar() {
            return this.$store.state.dokter.msg_success
        },

        // error
        alerterror: {
            get() {
                return this.$store.state.dokter.alert_error
            },
            set(val) {
                this.$store.commit("dokter/update_alert_error", val)
            }
        },
        msgerror() {
            return this.$store.state.dokter.msg_error
        },

        lookupstatus() {
            return this.$store.state.dokter.lookup_dokter
        },
        isLoading() {
            return this.$store.state.dokter.search_status == 1
        },

        // print
        openprintnote: {
            get() {
                return this.$store.state.dokter.open_print_note
            },
            set(val) {
                this.$store.commit("dokter/update_open_print_note", false)
            }
        }
    },
    methods: {

        isSelected(p) {
            return p.id == this.$store.state.dokter.selected_dokter.M_UserID
        },

        selectMe(sc) {
            this.$store.commit("dokter/update_selected_dokter", sc)
        },
        updateDialogFormdokter() {
            this.$store.commit("dokter/update_dialog_form_dokter", false)
        },

        openFormdokter() {
            // this.xcode = ""
            // this.xname = ""
            this.xusername = ""
            this.xpassword = ""
            this.xpasswordconfirm = ""
            this.xdoctorid = ""
            // this.isdefault = "N"
            this.$store.commit("dokter/update_itemdokters", [
                {
                    M_DoctorID: '',
                    M_DoctorName: ''
                }
            ])

            this.$store.commit("dokter/update_itemdokter",
                {
                    M_DoctorID: '',
                    M_DoctorName: ''
                }
            )

            if (this.xact == 'new') {
                // console.log('update xact ',this.xact)
                this.$store.commit("dokter/update_itemmous", [
                    {
                        M_MouID: '',
                        M_MouName: ''
                    }
                ])

                this.$store.commit("dokter/update_itemmou",
                    {
                        M_MouID: '',
                        M_MouName: ''
                    }
                )
            }


            this.$refs.formdokter.reset()
            this.$refs.formdokter.resetValidation()
            this.$store.commit("dokter/update_act", 'new')
            this.$store.commit("dokter/update_dialog_form_dokter", true)
        },

        // thr_search_instrument: _.debounce(function () {
        //     this.$store.dispatch("dokter/searchinstrument", {
        //         tes: this.search_instrument
        //     })
        // }, 2000),

        // tambahan
        // dropdown item dokter
        thr_search_autocomplete_dokter: _.debounce(function () {
            this.$store.dispatch("dokter/searchdokterautocomplete", this.search_autocomplete_dokter)
        }, 2000),

        // dropdown item mou
        thr_search_autocomplete_mou: _.debounce(function () {
            this.$store.dispatch("dokter/searchmouautocomplete", this.search_autocomplete_mou)
        }, 2000),

        saveFormdokter() {
            this.msgalertshow = ''
            // var prm = {};
            // console.log(this.xitemdokter.M_DoctorID)
            // prm = {
            //     M_UserUsername: this.xusername,
            //     M_UserPassword: this.xpassword,
            //     M_UserM_DoctorID : this.xitemdokter.M_DoctorID
            // };

            // console.log(prm);

            if (_.isEmpty(this.xitemdokter)) {
                this.msgalertshow = 'Anda belum memilih dokter'
                // this.error_form = true
                this.dialogalertshow = true
            } else {
                if (_.isEmpty(this.xdoctorid)) {
                    this.msgalertshow = 'Anda belum mengisi doctor id'
                    // this.error_form = true
                    this.dialogalertshow = true
                } else {
                    if (_.isEmpty(this.xusername)) {
                        this.msgalertshow = 'Anda belum mengisi username'
                        // this.error_form = true
                        this.dialogalertshow = true
                    } else {
                        if (_.isEmpty(this.xpassword)) {
                            this.msgalertshow = 'Anda belum mengisi password'
                            // this.error_form = true
                            this.dialogalertshow = true
                        } else {
                            if (_.isEmpty(this.xpasswordconfirm)) {
                                this.msgalertshow = 'Anda belum mengisi konfirmasi password'
                                // this.error_form = true
                                this.dialogalertshow = true
                            } else {
                                if (_.isEmpty(this.xitemmou)) {
                                    this.msgalertshow = 'Anda belum memilih aggrement'
                                    // this.error_form = true
                                    this.dialogalertshow = true
                                } else {
                                    // if (this.xdoctorid == this.xusername) {
                                    //     this.msgalertshow = 'doctor id dan username tidak boleh sama'
                                    //     // this.error_form = true
                                    //     this.dialogalertshow = true
                                    // } else {
                                    if (this.xpassword == this.xpasswordconfirm) {
                                        // console.log('masuk sini')
                                        this.$store.dispatch("dokter/save", {
                                            // name: this.xname,
                                            search: this.xsearch,
                                            username: this.xusername,
                                            password: this.xpassword,
                                            confirm_password: this.xpasswordconfirm,
                                            id_doctor_prm: this.xitemdokter.M_DoctorID,
                                            id_mou: this.xitemmou.M_MouID,
                                            doctor_id: this.xdoctorid,

                                            // sdokter: this.xsearch,
                                            // sdokter: this.$store.state.dokter.x_search
                                        })
                                    } else {
                                        this.msgalertshow = 'password dan konfirmasi password harus sama'
                                        // this.error_form = true
                                        this.dialogalertshow = true
                                    }
                                    // }
                                }
                            }
                        }
                    }
                }
            }

            // if (this.$refs.formdokter.validate()) {


            // }
        },
        updateFormdokter() {
            // if (this.$refs.formdokter.validate()) {
            this.msgalertshow = ''
            if (_.isEmpty(this.xitemdokter)) {
                this.msgalertshow = 'Anda belum memilih dokter'
                // this.error_form = true
                this.dialogalertshow = true
            } else {
                if (_.isEmpty(this.xdoctorid)) {
                    this.msgalertshow = 'Anda belum mengisi doctor id'
                    // this.error_form = true
                    this.dialogalertshow = true
                } else {
                    if (_.isEmpty(this.xusername)) {
                        this.msgalertshow = 'Anda belum mengisi username'
                        // this.error_form = true
                        this.dialogalertshow = true
                    } else {
                        if (_.isEmpty(this.xitemmou)) {
                            this.msgalertshow = 'Anda belum memilih aggrement'
                            // this.error_form = true
                            this.dialogalertshow = true
                        } else {
                            // if (this.xdoctorid == this.xusername) {
                            //     this.msgalertshow = 'doctor id dan username tidak boleh sama'
                            //     // this.error_form = true
                            //     this.dialogalertshow = true
                            // } else {
                            if (this.xpassword == this.xpasswordconfirm) {
                                // console.log('masuk sini')

                                // console.log("current page : ", this.$store.state.dokter.current_page)
                                // console.log("current page x : ", this.$store.state.dokter.curr_page)

                                this.$store.dispatch("dokter/update", {
                                    // name: this.xname,
                                    id: this.xid,
                                    search: this.xsearch,
                                    search:this.$store.state.dokter.x_search,
                                    username: this.xusername,
                                    id_doctor_prm: this.xitemdokter.M_DoctorID,
                                    id_mou: this.xitemmou.M_MouID,
                                    doctor_id: this.xdoctorid,
                                    curr_pagex: this.$store.state.dokter.current_page

                                    // sdokter: this.xsearch,
                                    // sdokter: this.$store.state.dokter.x_search
                                })
                            } else {
                                this.msgalertshow = 'password dan konfirmasi password harus sama'
                                // this.error_form = true
                                this.dialogalertshow = true
                            }
                            // }
                        }
                    }
                }
            }
            // }
        },
        updateAlert_success(val) {
            this.$store.commit("dokter/update_alert_success", val)
        },
        // error backend
        updateAlert_error(val) {
            this.$store.commit("dokter/update_alert_error", val)
            this.alerterror = false
        },
        editdokter(data) {
            // console.log("edit data ", data)
            this.xid = data.id
            // this.xcode = data.code

            // dropdown dokter
            this.$store.commit("dokter/update_itemdokters", [
                {
                    M_DoctorID: data.M_UserM_DoctorID,
                    M_DoctorName: data.M_DoctorName
                }
            ])

            this.$store.commit("dokter/update_itemdokter",
                {
                    M_DoctorID: data.M_UserM_DoctorID,
                    M_DoctorName: data.M_DoctorName
                }
            )

            // this.xname = data.name
            this.xusername = data.M_UserUsername
            this.xdoctorid = data.M_UserM_DoctorCode

            // dropdown mou
            // if (data.M_MouID !== "") {
            // console.log("update mou", data)
            this.$store.commit("dokter/update_itemmous", [
                {
                    M_MouID: data.M_MouID,
                    M_MouName: data.M_MouName
                }
            ])
            this.$store.commit("dokter/update_itemmou",
                {
                    M_MouID: data.M_MouID,
                    M_MouName: data.M_MouName
                }
            )
            // }


            // this.xitemmous.M_MouID = data.M_MouID
            // this.xitemmous.M_MouName = data.M_MouName

            // this.$store.commit("dokter/update_itemmou",
            //     {
            //         M_MouID: data.M_MouID,
            //         M_MouName: data.M_MouName
            //     }
            // )

            // this.xpassword = data.M_UserPassword

            // this.isdefault = data.T_dokterIsDefault === 'N' ? false : true
            this.$store.commit("dokter/update_act", 'edit')
            this.$store.commit("dokter/update_dialog_form_dokter", true)
        },
        deletedokter(data) {
            this.xid = data.id
            var xdata = {
                id: data.id,
                M_UserUsername: data.M_UserUsername,
                // dokters: 'xxx'
            }
            this.$store.commit("dokter/update_selected_dokter", xdata)
            this.msgalert = "Yakin, mau hapus dokter " + data.M_UserUsername + "  ?"
            this.dialogdeletealert = true
        },

        closeDeleteAlert() {
            // console.log(this.$store.state.dokter.selected_dokter.id)
            this.$store.dispatch("dokter/delete", {
                id: this.$store.state.dokter.selected_dokter.id,
                M_UserUsername: this.$store.state.dokter.selected_dokter.M_UserUsername
            })
            this.dialogdeletealert = false
        },
        thr_search: _.debounce(function () {
            this.$store.dispatch("dokter/search", {
                search: this.xsearch,
                search: this.$store.state.dokter.x_search,
                current_page: 1,
                lastid: -1
            })
        }, 1000),

        // print
        doPrint() {
            const d = new Date();
            let time = d.getTime();
            let user = one_user()
            console.log(user)
            this.printwidth = 1200
            this.printtitle = ""
            let rpt = 'rpt_user_doctor'
            this.urlprintnote = "/birt/run?__report=report/one/regional/" + rpt + ".rptdesign&__format=pdf&username=" + user.M_UserUsername + "&PID=" + user.M_UserID + "&tm=" + time
            this.$store.commit("dokter/update_open_print_note", true)
        }
    },
    watch: {
        xsearch(val, old) {
            // console.log(val)
            this.xsearch = val
            this.thr_search()

        },

        // autocomplete dokter
        search_autocomplete_dokter(val, old) {
            // console.log(this.$store.state.dokter.update_autocomplete_status)
            if (val == old) return
            if (!val) return
            if (val.length < 1) {
                // console.log('cek dropdown dokter');
                // console.log("test search dropdown item dokter length < 1")
                this.$store.dispatch("dokter/searchdokterautocomplete", this.search_autocomplete_dokter)
                return this.thr_search_autocomplete_dokter()
            }

            // setelah di search load data max 10 item sesuai filter
            if (val.length > 2) {
                // console.log('cek dropdown dokter');

                // console.log("test search dropdown item dokter");
                // if (this.$store.state.item.update_autocomplete_status == 1) {
                this.$store.dispatch("dokter/searchdokterautocomplete", this.search_autocomplete_dokter)
                return this.thr_search_autocomplete_dokter()
                // }
            }
        },

        // autocomplete mou
        search_autocomplete_mou(val, old) {

            // console.log(this.$store.state.dokter.update_autocomplete_status)
            if (val == old) return
            if (!val) return
            // if (val.length < 1) {
            //     console.log('cek dropdown mou');

            //     // console.log("test search dropdown item mou length < 1")
            //     this.$store.dispatch("dokter/searchmouautocomplete", this.search_autocomplete_mou)
            //     return this.thr_search_autocomplete_mou()
            // }

            // setelah di search load data max 10 item sesuai filter
            if (val.length >= 2) {
                // console.log('cek dropdown mou',val);

                // console.log("test search dropdown item mou", val);
                // if (this.$store.state.item.update_autocomplete_status == 1) {
                // this.$store.dispatch("dokter/searchmouautocomplete", this.search_autocomplete_mou)
                return this.thr_search_autocomplete_mou()
                // }
            }
        },
    }
}
</script>