<template>
    <v-layout>
        <v-flex xs12>
            <v-card class="mb-2" color="white">
                <v-toolbar color="blue lighten-3" dark height="50px">
                    <v-toolbar-title>HARGA RUJUKAN {{this.$store.state.rujukantype.selected_rujukantype.code}}</v-toolbar-title>
                    <v-spacer></v-spacer>
                    <!--  <v-btn v-if="this.$store.state.rujukantype.selected_rujukantype.name !== ''" @click="openFormPriceRujukan(0)" icon>
                        <v-icon>library_add</v-icon>
                    </v-btn> -->
                </v-toolbar>
                <v-layout row style="background:#bbdefb;padding-top:5px;" justify-left>
                    <v-flex xs12>
                        <v-layout row>
                            <v-flex xs3>
                                <v-autocomplete label="Regional" style="height: 42px;" class="textinput ma-1" v-model="xautoregional" :items="xautoregionals"
                                    :search-input.sync="search_regional" auto-select-first no-filter item-text="S_RegionalName"
                                    return-object no-data-text="Cari Regional" small :rules="regionalRules" required>
                                    <template slot="item" slot-scope="{ item }">
                                        <v-list-tile-content>
                                            <v-list-tile-title v-text="item.S_RegionalName"></v-list-tile-title>
                                        </v-list-tile-content>
                                    </template>
                                </v-autocomplete>
                            </v-flex>
                            <v-flex xs3>
                                <v-list-tile>

                                    <v-autocomplete label="Pemeriksaan" style="height: 42px;" class="textinput ma-1" v-model="xautotest" :items="xautotests"
                                        :search-input.sync="search_test" auto-select-first no-filter item-text="T_TestName" return-object
                                        no-data-text="Cari Pemeriksaan" small>
                                        <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-sub-title v-text="item.description"></v-list-tile-sub-title></v-list-tile-content>
                                        </template>
                                    </v-autocomplete>


                                </v-list-tile>
                            </v-flex>
                            <v-flex xs3>
                                <v-list-tile>
                                    <v-text-field style="height: 42px;" class="textinput ma-1" v-model="xprice" label="Harga" hide-details></v-text-field>
                                </v-list-tile>
                            </v-flex>
                            <v-flex xs3>
                                <v-list-tile>

                                    <v-btn color="primary" class="ma-0 one-btn-icon" fill-height @click="saveFormPriceRujukan()" :disabled="!btn_add_enabled">
                                        <span class="icon-add"></span>
                                    </v-btn>
                                </v-list-tile>
                            </v-flex>
                        </v-layout>
                    </v-flex>
                </v-layout>
                <v-divider></v-divider>
                <v-layout row wrap 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="pricerujukans" :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)" v-html="props.item.S_RegionalName">
                                </td>
                                <td class="text-xs-left pa-2" v-bind:class="{'amber lighten-4':isSelected(props.item)}" @click="selectMe(props.item)">
                                
                                <p class="mb-0">{{ props.item.T_TestName}}</p>
                                <p class="mb-0 caption">{{ props.item.description}}</p>
                                </td>
                                <td class="text-xs-left pa-2" v-bind:class="{'amber lighten-4':isSelected(props.item)}" @click="selectMe(props.item)" v-html="props.item.Nat_PriceRujukanAmount">
                                </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="editFormPriceRujukan(props.item)">edit</v-icon>
                                    <v-icon small class="ml-3" color="error" @click="deleteFormPriceRujukan(props.item)">clear</v-icon>
                                </td>
                            </template>
                        </v-data-table>
                    </v-flex>
                </v-layout>
                <v-divider></v-divider>
                <v-pagination style="margin-top:10px;margin-bottom:10px" v-model="curr_page" :length="xtotal_page"></v-pagination>

                <template>
                    <v-layout row justify-center>
                        <v-dialog v-model="dialogpricerujukan" persistent max-width="750px">
                            <v-card>
                                <v-card-title>
                                    <span class="headline">FORM HARGA RUJUKAN</span>
                                </v-card-title>
                                <v-card-text class="pt-0 pb-0">
                                    <v-form ref="formrujukantypepricerujukan" v-model="validpricerujukan" lazy-validation>
                                        <v-layout wrap>
                                            <v-flex xs12>
                                                <v-autocomplete label="Tipe Rujukan*" v-model="xautorujukantype" :items="xautorujukantypes" :search-input.sync="search_rujukantype"
                                                    auto-select-first no-filter item-text="Nat_PriceRujukanTypeName" return-object
                                                    no-data-text="Cari Tipe Rujukan" small :rules="rujukantypeRules" required>
                                                    <template slot="item" slot-scope="{ item }">
                                                        <v-list-tile-content>
                                                            <v-list-tile-title v-text="item.Nat_PriceRujukanTypeName"></v-list-tile-title>
                                                        </v-list-tile-content>
                                                    </template>
                                                </v-autocomplete>
                                            </v-flex>
                                            <v-flex xs12>
                                                <v-autocomplete label="Regional*" v-model="xautoregional" :items="xautoregionals" :search-input.sync="search_regional" auto-select-first
                                                    no-filter item-text="S_RegionalName" return-object no-data-text="Cari Regional"
                                                    small :rules="regionalRules" required>
                                                    <template slot="item" slot-scope="{ item }">
                                                        <v-list-tile-content>
                                                            <v-list-tile-title v-text="item.S_RegionalName"></v-list-tile-title>
                                                        </v-list-tile-content>
                                                    </template>
                                                </v-autocomplete>
                                            </v-flex>
                                            <v-flex xs12>
                                                <v-autocomplete label="Pemeriksaan" v-model="xautotest" :items="xautotests" :search-input.sync="search_test" auto-select-first
                                                    no-filter item-text="T_TestName" return-object no-data-text="Cari Pemeriksaan"
                                                    small>
                                                    <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-sub-title v-text="item.description"></v-list-tile-sub-title></v-list-tile-content>
                                                    </template>
                                                </v-autocomplete>
                                            </v-flex>
        </v-flex>

        <v-flex xs12>
            <v-text-field v-model="xprice" label="Harga*" :rules="xpriceRules" required></v-text-field>
        </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="updateDialogFormPriceRujukan()">Tutup</v-btn>
            <v-btn color="blue darken-1" flat @click="saveFormPriceRujukan()">Simpan</v-btn>
        </v-card-actions>
        </v-form>
        </v-card>
        </v-dialog>
        </v-layout>
        </template>

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

        <one-dialog-print :title="printtitle" :width="printwidth" :height="500" :status="openprint" :urlprint="urlprint" @close-dialog-print="closePrint"></one-dialog-print>
        <template>

            <v-dialog v-model="dialogdeletealertpricerujukan" 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>
                                                {{msgalertpricerujukan}}
                                            </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="dialogdeletealertpricerujukan = false">
                            Tutup
                        </v-btn>
                        <v-btn color="primary" flat @click="closeDeleteAlertPriceRujukan()">
                            Yakin lah
                        </v-btn>
                    </v-card-actions>
                </v-card>
            </v-dialog>

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

    .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-date-picker': httpVueLoader('../../../common/oneDatePicker.vue'),
            'one-dialog-print': httpVueLoader('../../../common/oneDialogPrintX.vue')
        },
        data() {
            return {
                query: "",
                items: [],
                openprint: false,
                urlprint: '',
                printtitle: '',
                printwidth: 600,
                formatreport: 'pdf',
                readonlydefault: false,
                page: 1,
                xname: '',
                xphone: '',
                xcode: '',
                xaddress: '',
                xipaddress: '',
                xbasename: '',
                isdefault: false,
                issatellite: false,
                search_rujukantype: '',
                search_regional: '',
                search_district: '',
                search_kelurahan: '',
                search_test: '',
                search_mou: '',
                search_doctor: '',
                xpriceRules: [
                    v => !!v || 'Harga harus diisi'
                ],
                xcodeRules: [
                    v => !!v || 'Kode harus diisi'
                ],
                addressRules: [
                    v => !!v || 'Alamat harus diisi'
                ],
                xipaddressRules: [
                    v => !!v || 'Alamat IP harus diisi'
                ],
                rujukantypeRules: [
                    v => !!v || 'RujukanType harus dipilih'
                ],
                regionalRules: [
                    v => !!v || 'Kota harus dipilih'
                ],
                districtRules: [
                    v => !!v || 'Kecamatan harus dipilih'
                ],
                kelurahanRules: [
                    v => !!v || 'Kelurahan harus dipilih'
                ],
                headers: [{
                        text: "REGIONAL",
                        align: "left",
                        sortable: false,
                        value: "lab",
                        width: "15%",
                        class: "blue lighten-3 white--text"
                    },
                    {
                        text: "PEMERIKSAAN",
                        align: "left",
                        sortable: false,
                        value: "name",
                        width: "15%",
                        class: "blue lighten-3 white--text"
                    },
                    {
                        text: "HARGA",
                        align: "left",
                        sortable: false,
                        value: "name",
                        width: "10%",
                        class: "blue lighten-3 white--text"
                    },
                    {
                        text: "AKSI",
                        align: "left",
                        sortable: false,
                        value: "status",
                        width: "10%",
                        class: "blue lighten-3 white--text"
                    }
                ],
                pagination: {
                    descending: false,
                    page: 1,
                    rowsPerPage: 100,
                    sortBy: 'Nat_PriceRujukanName ASC',
                    totalItems: this.$store.state.pricerujukan.total_transactions
                },
                statuss: [{
                        waktu: '16-07-2019 10:00',
                        status: 'Order Dibuat',
                        pricerujukan: 'Nagita Slavina'
                    },
                    {
                        waktu: '16-07-2019 11:00',
                        status: 'Order Dikirim',
                        pricerujukan: 'Nagita Slavina'
                    },
                    {
                        waktu: '16-07-2019 12:00',
                        status: 'Order dikonfirmasi',
                        pricerujukan: 'Chacha Frederica'
                    },
                    {
                        waktu: '16-07-2019 13:00',
                        status: 'Telah dibuat Surat Jalan',
                        pricerujukan: 'Chacha Frederica'
                    },
                    {
                        waktu: '16-07-2019 14:00',
                        status: 'Kurir akan mengambil sampel',
                        pricerujukan: 'Satria Subiantoro'
                    }
                ],
                color: "success",
                validpricerujukan: false,
                xid: 0,
                isinput: "N",
                countprice: 0,
                pricerujukanpricerujukanid: 0,
                pricerujukanxname: "",
                pricerujukanlang: "",
                pricerujukantext: "",
                isadvance: "N",
                pricerujukanformatadvance: "",
                issenttorujukantype: "N",
                menustartdate: false,
                menuenddate: false,
                date: new Date().toISOString().substr(0, 10),

                dialogdeletealertpricerujukan: false,
                dialogverifyalertpricerujukan: false,
                dialogreleasealertpricerujukan: false,
                alertverify: false,
                dialogunreleasealertpricerujukan: false,
                dialogunverifyalertpricerujukan: false,
                msgalertpricerujukan: ""
            };
        },
        mounted() {},
        computed: {
            pricerujukans() {
                return this.$store.state.pricerujukan.pricerujukans
            },
            xrujukantype() {
                return this.$store.state.rujukantype.selected_rujukantype
            },
            dialogpricerujukan() {
                return this.$store.state.pricerujukan.dialog_form_pricerujukan
            },
            xerrors() {
                return this.$store.state.pricerujukan.errors
            },
            isLoading() {
                return this.$store.state.pricerujukan.search_status == 1
            },
            startComputedDateFormatted() {
                return this.formatDate(this.xstartdate)
            },
            xstartdate: {
                get() {
                    return this.$store.state.pricerujukan.startdate
                },
                set(val) {
                    this.$store.commit("pricerujukan/update_startdate", val)
                }
            },
            endComputedDateFormatted() {
                return this.formatDate(this.xenddate)
            },
            xenddate: {
                get() {
                    return this.$store.state.pricerujukan.enddate
                },
                set(val) {
                    this.$store.commit("pricerujukan/update_enddate", val)
                }
            },
            xautoregionals() {
                return this.$store.state.pricerujukan.autoregionals
            },
            xautoregional: {
                get() {
                    return this.$store.state.pricerujukan.autoregional
                },
                set(val) {
                    this.$store.commit("pricerujukan/update_autoregional", val)
                    this.$store.dispatch("pricerujukan/searchdistrict", {
                        search: this.search_district,
                        id: val.S_RegionalID
                    })
                    this.$store.dispatch("pricerujukan/lookupbyname", {
                        rujukantype: this.$store.state.rujukantype.selected_rujukantype.code,
                        pricerujukan: this.xsearch,
                        regional: this.$store.state.pricerujukan.autoregional.S_RegionalID ? this.$store.state.pricerujukan.autoregional.S_RegionalID :
                        0,
                        test: this.$store.state.pricerujukan.autotest.T_TestID ? this.$store.state.pricerujukan.autotest.T_TestID :
                        0,
                        price: this.xprice,
                        current_page: 1,
                        lastid: -1
                    })
                }
            },
            btn_add_enabled() {
                if (this.$store.state.rujukantype.selected_rujukantype.name !== '' && this.$store.state.pricerujukan
                    .autoregional.S_RegionalID && this.$store.state.pricerujukan.autotest.T_TestID && this.xprice !==
                    '')
                    return true

                return false
            },
            xautodistricts() {
                return this.$store.state.pricerujukan.autodistricts
            },
            xautodistrict: {
                get() {
                    return this.$store.state.pricerujukan.autodistrict
                },
                set(val) {
                    this.$store.commit("pricerujukan/update_autodistrict", val)
                    this.$store.dispatch("pricerujukan/searchkelurahan", {
                        search: this.search_kelurahan,
                        id: val.M_DistrictID
                    })
                }
            },
            xautokelurahans() {
                return this.$store.state.pricerujukan.autokelurahans
            },
            xautokelurahan: {
                get() {
                    return this.$store.state.pricerujukan.autokelurahan
                },
                set(val) {
                    this.$store.commit("pricerujukan/update_autokelurahan", val)
                }
            },
            xautotests() {
                return this.$store.state.pricerujukan.autotests
            },
            xautotest: {
                get() {
                    return this.$store.state.pricerujukan.autotest
                },
                set(val) {
                    this.$store.commit("pricerujukan/update_autotest", val)
                    this.$store.dispatch("pricerujukan/searchmou", {
                        search: this.search_mou,
                        id: val.T_TestID
                    })
                    this.$store.dispatch("pricerujukan/lookupbyname", {
                        rujukantype: this.$store.state.rujukantype.selected_rujukantype.code,
                        pricerujukan: this.xsearch,
                        regional: this.$store.state.pricerujukan.autoregional.S_RegionalID ? this.$store.state.pricerujukan.autoregional.S_RegionalID :
                        0,
                        test: this.$store.state.pricerujukan.autotest.T_TestID ? this.$store.state.pricerujukan.autotest.T_TestID :
                        0,
                        price: this.xprice,
                        current_page: 1,
                        lastid: -1
                    })
                }
            },
            xautomous() {
                return this.$store.state.pricerujukan.automous
            },
            xautomou: {
                get() {
                    return this.$store.state.pricerujukan.automou
                },
                set(val) {
                    this.$store.commit("pricerujukan/update_automou", val)
                }
            },
            xautodoctors() {
                return this.$store.state.pricerujukan.autodoctors
            },
            xautodoctor: {
                get() {
                    return this.$store.state.pricerujukan.autodoctor
                },
                set(val) {
                    this.$store.commit("pricerujukan/update_autodoctor", val)
                    this.$store.dispatch("pricerujukan/selectaddressdoctor", {
                        id: val.M_DoctorID
                    })
                }
            },
            xaddressdoctors() {
                return this.$store.state.pricerujukan.addressdoctors
            },
            xaddressdoctor: {
                get() {
                    return this.$store.state.pricerujukan.addressdoctor
                },
                set(val) {
                    this.$store.commit("pricerujukan/update_addressdoctor", val)
                }
            },
            xstatuss() {
                return this.$store.state.pricerujukan.statuss
            },
            dialogstatusorder() {
                return this.$store.state.pricerujukan.dialog_status_order
            },
            xautorujukantypes() {
                return this.$store.state.pricerujukan.autorujukantypes
            },
            xautorujukantype: {
                get() {
                    return this.$store.state.pricerujukan.autorujukantype
                },
                set(val) {
                    this.$store.commit("pricerujukan/update_autorujukantype", val)
                }
            },
            xprice: {
                get() {
                    return this.$store.state.pricerujukan.xprice
                },
                set(val) {
                    this.$store.commit("pricerujukan/update_xprice", val)
                    this.$store.dispatch("pricerujukan/lookupbyname", {
                        rujukantype: this.$store.state.rujukantype.selected_rujukantype.code,
                        pricerujukan: this.xsearch,
                        regional: this.$store.state.pricerujukan.autoregional.S_RegionalID ? this.$store.state.pricerujukan.autoregional.S_RegionalID :
                        0,
                        test: this.$store.state.pricerujukan.autotest.T_TestID ? this.$store.state.pricerujukan.autotest.T_TestID :
                        0,
                        price: this.xprice,
                        current_page: 1,
                        lastid: -1
                    })
                }
            },
            xsearch: {
                get() {
                    return this.$store.state.pricerujukan.x_search
                },
                set(val) {
                    this.$store.commit("pricerujukan/update_x_search", val)
                }
            },
            curr_page: {
                get() {
                    return this.$store.state.pricerujukan.current_page
                },
                set(val) {
                    this.$store.commit("pricerujukan/update_current_page", val)
                    this.$store.dispatch("pricerujukan/lookupbyname", {
                        rujukantype: this.$store.state.rujukantype.selected_rujukantype.code,
                        pricerujukan: this.xsearch,
                        regional: this.$store.state.pricerujukan.autoregional.S_RegionalID ? this.$store.state.pricerujukan.autoregional.S_RegionalID :
                        0,
                        test: this.$store.state.pricerujukan.autotest.T_TestID ? this.$store.state.pricerujukan.autotest.T_TestID :
                        0,
                        price: this.xprice,
                        current_page: val,
                        lastid: -1
                    })
                }
            },
            xtotal_page: {
                get() {
                    return this.$store.state.pricerujukan.total_data
                },
                set(val) {
                    this.$store.commit("pricerujukan/update_total_data", val)
                }
            }
        },
        methods: {
            isSelected(p) {
                return p.id == this.$store.state.pricerujukan.selected_pricerujukan.id
            },
            selectMe(sc) {
                this.$store.commit("pricerujukan/update_selected_pricerujukan", sc)

            },
            updateDialogFormPriceRujukan() {
                this.$store.commit("pricerujukan/update_dialog_form_pricerujukan", false)
            },
            updateDialogStatusOrder() {
                this.$store.commit("pricerujukan/update_dialog_status_order", false)
            },
            setStatusOrder(val) {
                this.$store.commit("pricerujukan/update_pricerujukans", {})
                this.$store.commit("pricerujukan/update_dialog_status_order", true)
                this.$store.commit("pricerujukan/update_statuss", val.statuss)
            },
            doPriceList(val) {
                console.log(location)
                var id = val.id
                location.replace("/one-ui/rujukantype/vuex/one-md-price/" + "?id=" + id)
            },
            doPrice() {
                console.log(location)
                var id = this.xid
                location.replace("/one-ui/rujukantype/vuex/one-md-price/" + "?id=" + id)
            },
            thr_search_rujukantype: _.debounce(function () {
                this.$store.dispatch("pricerujukan/searchrujukantype", {
                    tes: this.search_rujukantype
                })
            }, 200),
            thr_search_regional: _.debounce(function () {
                this.$store.dispatch("pricerujukan/searchregional", {
                    search: this.search_regional
                })
            }, 200),
            thr_search_district: _.debounce(function () {
                this.$store.dispatch("pricerujukan/searchdistrict", {
                    search: this.search_district,
                    id: this.xautoregional.S_RegionalID
                })
            }, 200),
            thr_search_kelurahan: _.debounce(function () {
                this.$store.dispatch("pricerujukan/searchkelurahan", {
                    search: this.search_kelurahan,
                    id: this.xautodistrict.M_DistrictID
                })
            }, 200),
            thr_search: _.debounce(function () {
                this.$store.dispatch("rujukantype/lookupbyname", {
                    rujukantype: this.$store.state.rujukantype.x_search,
                    pricerujukan: this.xsearch,
                    current_page: 1,
                    lastid: -1
                })
                this.$store.dispatch("pricerujukan/lookupbyname", {
                    rujukantype: this.$store.state.rujukantype.selected_rujukantype.code,
                    pricerujukan: this.xsearch,
                    regional: this.$store.state.pricerujukan.autoregional.S_RegionalID ? this.$store.state.pricerujukan.autoregional.S_RegionalID :
                        0,
                        test: this.$store.state.pricerujukan.autotest.T_TestID ? this.$store.state.pricerujukan.autotest.T_TestID :
                        0,
                    price: this.xprice,
                    current_page: 1,
                    lastid: -1
                })
            }, 200),
            thr_search_test: _.debounce(function () {
                this.$store.dispatch("pricerujukan/searchtest", {
                    search: this.search_test
                })
            }, 200),
            thr_search_mou: _.debounce(function () {
                this.$store.dispatch("pricerujukan/searchmou", {
                    search: this.search_mou,
                    id: this.xautotest.T_TestID
                })
            }, 200),
            thr_search_doctor: _.debounce(function () {
                this.$store.dispatch("pricerujukan/searchdoctor", {
                    search: this.search_doctor
                })
            }, 200),
            searchRujukanType() {
                this.$store.dispatch("pricerujukan/lookup", {
                    id: this.xrujukantype.name === "" ? "0" : this.$store.state.rujukantype.selected_rujukantype
                        .id,
                    search: this.xsearch,
                    regional: this.$store.state.pricerujukan.autoregional.S_RegionalID ? this.$store.state.pricerujukan.autoregional.S_RegionalID :
                        0,
                        test: this.$store.state.pricerujukan.autotest.T_TestID ? this.$store.state.pricerujukan.autotest.T_TestID :
                        0,
                    price: this.xprice,
                    current_page: 1,
                    lastid: -1
                })
            },
            doPrint() {
                console.log('doprint')
                this.printwidth = 1028
                this.printtitle = ""
                let pricerujukan = one_pricerujukan()
                var id = this.xid
                var d = new Date();
                var n = d.getTime()
                var rptname = 'rujukantype_price'
                var formatrpt = this.formatreport

                this.urlprint = "/birt/run?__report=report/one/md/" + rptname +
                    ".rptdesign&__format=" +
                    formatrpt + "&PPriceRujukanID=" + id + "&pricerujukanxname=" + pricerujukan.Nat_PriceRujukanPriceRujukanname +
                    "&tm=" + n

                this.openprint = true
            },
            closePrint() {
                this.openprint = false
            },
            openFormPriceRujukan(val) {
                this.xid = val
                this.xname = ''
                this.xphone = ''
                this.xcode = ''
                this.xaddress = ''
                this.xipaddress = ''
                this.xbasename = ''
                this.isdefault = false
                this.issatellite = false
                this.$store.commit("pricerujukan/update_autorujukantypes", [])
                this.$store.commit("pricerujukan/update_autorujukantype", {})
                this.$store.commit("pricerujukan/update_autoregionals", [])
                this.$store.commit("pricerujukan/update_autoregional", {})
                this.$store.commit("pricerujukan/update_autotests", [])
                this.$store.commit("pricerujukan/update_autotest", {})
                this.$store.commit("pricerujukan/update_automous", [])
                this.$store.commit("pricerujukan/update_automou", {})
                this.$store.commit("pricerujukan/update_autodoctors", [])
                this.$store.commit("pricerujukan/update_autodoctor", {})
                this.$store.commit("pricerujukan/update_autodistricts", [])
                this.$store.commit("pricerujukan/update_autodistrict", {})
                this.$store.commit("pricerujukan/update_autokelurahans", [])
                this.$store.commit("pricerujukan/update_autokelurahan", {})
                this.$store.commit("pricerujukan/update_addressdoctors", [])
                this.$store.commit("pricerujukan/update_addressdoctor", {})
                this.$store.commit("pricerujukan/update_dialog_form_pricerujukan", true)
            },
            editFormPriceRujukan(val) {
                this.xid = val.id
                this.xprice = val.Nat_PriceRujukanAmount
                this.$store.commit("pricerujukan/update_autorujukantypes", [{
                    Nat_PriceRujukanTypeCode: val.Nat_PriceRujukanTypeCode,
                    Nat_PriceRujukanTypeName: val.Nat_PriceRujukanTypeName
                }])
                this.$store.commit("pricerujukan/update_autorujukantype", {
                    Nat_PriceRujukanTypeCode: val.Nat_PriceRujukanTypeCode,
                    Nat_PriceRujukanTypeName: val.Nat_PriceRujukanTypeName
                })
                this.$store.commit("pricerujukan/update_autoregionals", [{
                    S_RegionalID: val.S_RegionalID,
                    S_RegionalName: val.S_RegionalName
                }])
                this.$store.commit("pricerujukan/update_autoregional", {
                    S_RegionalID: val.S_RegionalID,
                    S_RegionalName: val.S_RegionalName
                })
                this.$store.commit("pricerujukan/update_autotests", [{
                    T_TestID: val.T_TestID,
                    T_TestName: val.T_TestName
                }])
                this.$store.commit("pricerujukan/update_autotest", {
                    T_TestID: val.T_TestID,
                    T_TestName: val.T_TestName
                })
                this.$store.commit("pricerujukan/update_dialog_form_pricerujukan", true)
            },
            checkError(value) {
                var errors = this.$store.state.pricerujukan.errors
                if (errors.includes(value)) {
                    return true
                } else {
                    return false
                }
            },
            saveFormPriceRujukan() {
                this.$store.dispatch("pricerujukan/save", {
                    xid: this.xid,
                    rujukantypeid: this.xautorujukantype ? this.$store.state.pricerujukan.autorujukantype
                        .Nat_PriceRujukanTypeCode : 0,
                    rujukantypename: this.$store.state.pricerujukan.autorujukantype.Nat_PriceRujukanTypeName,
                    regionalid: this.$store.state.pricerujukan.autoregional.S_RegionalID ? this.$store.state.pricerujukan.autoregional.S_RegionalID :
                        0,
                    regionalname: this.$store.state.pricerujukan.autoregional.S_RegionalID ? this.$store.state.pricerujukan.autoregional.S_RegionalName :
                        '',
                    testid: this.$store.state.pricerujukan.autotest.T_TestID ? this.$store.state.pricerujukan.autotest.T_TestID : 0,
                    testname: this.$store.state.pricerujukan.autotest.T_TestID ? this.$store.state.pricerujukan.autotest.T_TestName : '',
                    price: this.xprice,
                    srujukantype: this.$store.state.rujukantype.x_search,
                    spricerujukan: this.xsearch
                })


            },
            set_date2(x) {
                this.startdate = x.new_date
            },
            set_date3(x) {
                this.enddate = x.new_date
            },
            formatDate(date) {
                if (!date) return null

                const [year, month, day] = date.split('-')
                return `${day}-${month}-${year}`
            },
            deFormatedDate(date) {
                if (!date) return null

                const [day, month, year] = date.split('-')
                return `${year}-${month.padStart(2, '0')}-${day.padStart(2, '0')}`
            },
            updateAlert_success(val) {
                this.$store.commit("rujukantype/update_alert_success", val)
            },
            deleteFormPriceRujukan(data) {
                this.xid = data.id

                this.msgalertpricerujukan = "Yakin, mau hapus " + "harga rujukan pemeriksaan " + data.T_TestName  +  " regional " + data.S_RegionalName + " ini?"
                this.dialogdeletealertpricerujukan = true
            },
            closeDeleteAlertPriceRujukan() {
                this.$store.dispatch("pricerujukan/delete", {
                    xid: this.xid,
                    rujukantypeid: this.xautorujukantype ? this.$store.state.pricerujukan.autorujukantype
                        .Nat_PriceRujukanTypeCode : 0,
                    rujukantypename: this.$store.state.pricerujukan.autorujukantype.Nat_PriceRujukanTypeName,
                    regionalid: this.$store.state.pricerujukan.autoregional.S_RegionalID ? this.$store.state.pricerujukan.autoregional.S_RegionalID :
                        0,
                    regionalname: this.$store.state.pricerujukan.autoregional.S_RegionalID ? this.$store.state.pricerujukan.autoregional.S_RegionalName :
                        '',
                    testid: this.$store.state.pricerujukan.autotest.T_TestID ? this.$store.state.pricerujukan.autotest.T_TestID : 0,
                    testname: this.$store.state.pricerujukan.autotest.T_TestID ? this.$store.state.pricerujukan.autotest.T_TestName : '',
                    price: this.xprice,
                    srujukantype: this.$store.state.rujukantype.x_search,
                    spricerujukan: this.xsearch
                })
                this.dialogdeletealertpricerujukan = false
            }
        },
        watch: {
            xsearch(val, old) {
                console.log(val)
                this.xsearch = val
                this.thr_search()

            },
            search_rujukantype(val, old) {
                if (val == old) return
                if (!val) return
                if (val.length < 1) return
                if (this.$store.state.pricerujukan.update_autocomplete_status == 1) return
                this.thr_search_rujukantype()
            },
            search_regional(val, old) {
                if (val == old) return
                if (!val) return
                if (val.length < 1) return
                if (this.$store.state.pricerujukan.update_autocomplete_status == 1) return
                this.thr_search_regional()
            },
            search_district(val, old) {
                if (val == old) return
                if (!val) return
                if (val.length < 1) return
                if (this.$store.state.pricerujukan.update_autocomplete_status == 1) return
                this.thr_search_district()
            },
            search_kelurahan(val, old) {
                if (val == old) return
                if (!val) return
                if (val.length < 1) return
                if (this.$store.state.pricerujukan.update_autocomplete_status == 1) return
                this.thr_search_kelurahan()
            },
            search_test(val, old) {
                if (val == old) return
                if (!val) return
                if (val.length < 1) return
                if (this.$store.state.pricerujukan.update_autocomplete_status == 1) return
                this.thr_search_test()
            },
            search_mou(val, old) {
                if (val == old) return
                if (!val) return
                if (val.length < 1) return
                if (this.$store.state.pricerujukan.update_autocomplete_status == 1) return
                this.thr_search_mou()
            },
            search_doctor(val, old) {
                if (val == old) return
                if (!val) return
                if (val.length < 1) return
                if (this.$store.state.pricerujukan.update_autocomplete_status == 1) return
                this.thr_search_doctor()
            }
        }
    }
</script>