<template>
    <v-layout>
        <v-flex xs12>
            <v-card class="mb-2" color="white">
                <v-card tile flat color=" pa-2 teal lighten-3">
                    <h5 class=" subtitle-1 font-weight-bold">FUTURE ORDER LOG</h5>
                    <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-card>
                <v-layout class="mt-2" row>
                    <v-flex xs2 pr-2>
                    </v-flex>
                    <v-flex xs3 pr-2>
                    </v-flex>
                    <v-flex xs3 pr-2>
                    </v-flex>
                    <v-flex xs3 pr-2>
                    </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>
                       <div v-html="registers"></div> 
                    </v-flex>
                </v-layout>
                <v-divider></v-divider>
               
            </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-layout row justify-center>
                <v-dialog v-model="dialogregister" persistent max-width="1050px">
                    <v-card class="mb-2" color="white">
                        <v-toolbar color="teal lighten-3" dark height="50px">
                            <v-toolbar-title>REGISTRASI</v-toolbar-title>
                            <v-spacer></v-spacer>
                        </v-toolbar>
                        
                        <v-layout class="mt-2" row>
                            <v-flex xs12 class="pa-2">
                                <v-layout>
                                    <v-flex xs6 mr-1>
                                        <v-autocomplete label="Tipe Registrasi" v-model="xorderautoinfo" class="ma-1" :items="xorderautoinfos" :search-input.sync="search_info"
                                            auto-select-first hide-details style="font-size:14px;padding:4px 0" no-filter item-text="Nat_InstrumentName"
                                            clearable no-data-text="Pilih Registrasi" return-object :loading="isLoading">
                                            <template slot="item" slot-scope="{ item }">
                                                <v-list-tile-content>
                                                    <v-list-tile-title v-text="item.Nat_InstrumentName"></v-list-tile-title>
                                                </v-list-tile-content>
                                            </template>
                                        </v-autocomplete>
                                    </v-flex>
                                    <v-flex xs6 ml-1>
                                    </v-flex>
                                </v-layout>
                                <v-layout>
                                    <v-flex xs6 mr-1>
                                        <v-menu v-model="menufilterdatestart" :close-on-content-click="false" :nudge-right="40" lazy transition="scale-transition"
                                            offset-y full-width max-width="290px" min-width="290px">
                                            <template v-slot:activator="{ on }">

                                                <v-text-field single-line hide-details v-model="filterComputedDateFormattedStart" v-on="on" @blur="date = deFormatedDate(filterComputedDateFormattedStart)"
                                                    style="font-size:14px;padding:4px 0"></v-text-field>
                                            </template>
                                            <v-date-picker v-model="xstartdate" no-title @input="menufilterdatestart = false"></v-date-picker>
                                        </v-menu>
                                    </v-flex>

                                    <v-flex xs6 ml-1>
                                        <v-text-field single-line hide-details v-model="xsearch" style="font-size:14px;padding:4px 0" placeholder="Jam"></v-text-field>
                                    </v-flex>

                                </v-layout>
                                <v-layout>
                                    <v-flex xs6 mr-1>
                                        <v-text-field single-line hide-details v-model="xsearch" style="font-size:14px;padding:4px 0" placeholder="PIC"></v-text-field>
                                    </v-flex>

                                    <v-flex xs6 ml-1>
                                        <v-text-field single-line hide-details v-model="xsearch" style="font-size:14px;padding:4px 0" placeholder="No HP"></v-text-field>
                                    </v-flex>

                                </v-layout>
                                <v-layout>
                                    <v-flex xs6 mr-1>
                                        <v-select :search-input.sync="searchxArea" item-text="M_CityName" return-object :items="xcitys" v-model="cityaddress" label="Area"
                                            autocomplete></v-select>
                                    </v-flex>

                                    <v-flex xs6 ml-1>
                                        <v-textarea style="font-size:14px;padding:4px 0" auto-grow rows="3" label="Alamat"></v-textarea>
                                    </v-flex>

                                </v-layout>
                                <v-layout>
                                    <v-flex xs6 mr-1>
                                        <v-textarea style="font-size:14px;padding:4px 0" auto-grow rows="3" label="Catatan"></v-textarea>
                                    </v-flex>

                                    <v-flex xs6 ml-1>
                                    </v-flex>

                                </v-layout>
                            </v-flex>
                        </v-layout>
                        <v-card tile flat color=" pa-2 teal lighten-3">
                            <h5 class=" subtitle-1 font-weight-bold">PEMERIKSAAN</h5>
                        </v-card>
                        <v-layout>
                            <v-flex xs6 mr-1>
                                <v-autocomplete label="Pemeriksaan" v-model="xorderautotest" class="ma-1" :items="xorderautotests" :search-input.sync="search_test"
                                    auto-select-first hide-details style="font-size:14px" outline no-filter item-text="Nat_TestName"
                                    clearable no-data-text="Cari Pemeriksaan" return-object :loading="isLoading">
                                    <template slot="item" slot-scope="{ item }">
                                        <v-list-tile-content>
                                            <v-list-tile-title v-text="item.Nat_TestName"></v-list-tile-title>
                                        </v-list-tile-content>
                                    </template>
                                </v-autocomplete>
                            </v-flex>

                            <v-flex xs6 ml-1>
                            </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="headertests" :items="registers" :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)">
                                        </td>
                                        <td class="text-xs-left pa-2" v-bind:class="{'amber lighten-4':isSelected(props.item)}" @click="selectMe(props.item)">
                                        </td>
                                        <td class="text-xs-left pa-2" v-bind:class="{'amber lighten-4':isSelected(props.item)}" @click="selectMe(props.item)">
                                        </td>
                                        <td class="text-xs-left pa-2" v-bind:class="{'amber lighten-4':isSelected(props.item)}" @click="selectMe(props.item)">
                                        </td>
                                        <td class="text-xs-left pa-2" v-bind:class="{'amber lighten-4':isSelected(props.item)}" @click="selectMe(props.item)"></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>
                        <v-card tile flat color=" pa-2 teal lighten-3">
                            <h5 class=" subtitle-1 font-weight-bold">PASIEN</h5>
                        </v-card>

                        <v-divider></v-divider>
                        <v-layout>
                            <v-flex xs2 mr-1>
                                <v-btn class="ml-4" small @click="openFormQc()" color="teal">
                                    <v-icon center>add</v-icon>
                                </v-btn>
                            </v-flex>

                            <v-flex xs4 ml-1>
                                <input type="text" v-model="xsearch" @click="selectMe(0)" class="textinput" label="Cari Area" placeholder="PID" />

                            </v-flex>
                            <v-flex xs4 ml-1>
                                <input type="text" v-model="xsearch" @click="selectMe(0)" class="textinput" label="Cari Area" placeholder="Nama + HP + DOB + Alamat "
                                />

                            </v-flex>

                        </v-layout>
                        <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="headerpatients" :items="registers" :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)">
                                        </td>
                                        <td class="text-xs-left pa-2" v-bind:class="{'amber lighten-4':isSelected(props.item)}" @click="selectMe(props.item)">
                                        </td>
                                        <td class="text-xs-left pa-2" v-bind:class="{'amber lighten-4':isSelected(props.item)}" @click="selectMe(props.item)">
                                        </td>
                                        <td class="text-xs-left pa-2" v-bind:class="{'amber lighten-4':isSelected(props.item)}" @click="selectMe(props.item)">
                                        </td>
                                    </template>
                                </v-data-table>
                            </v-flex>
                        </v-layout>
                        <v-divider></v-divider>
                        <v-card-actions>
                                    <v-spacer></v-spacer>
                                    <v-btn color="blue darken-1" flat @click="updateDialogFormQc()">Tutup</v-btn>
                                    <v-btn color="blue darken-1" flat @click="saveFormQc()">Simpan</v-btn>
                                </v-card-actions>

                    </v-card>
                </v-dialog>
            </v-layout>
        </template>
        <template>

            <v-dialog v-model="dialogdeletealertregister" max-width="30%">
                <v-card>
                    <v-card-title class="headline grey lighten-2 pt-2 pb-2" primary-title>
                        Konfirmasi
                    </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>
                                                {{msgalertregister}}
                                            </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="dialogdeletealertregister = false">
                            Tutup
                        </v-btn>
                        <v-btn color="primary" flat @click="closeActiveAlertQc()">
                            Yakin lah
                        </v-btn>
                    </v-card-actions>
                </v-card>
            </v-dialog>

        </template>
        <one-dialog-alert :status="openalertconfirmation" :msg="msgalertconfirmation" @forget-dialog-alert="forgetAlertConfirmation()"
            @close-dialog-alert="closeAlertConfirmation()"></one-dialog-alert>
    </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: left;
        height: 45px;
        line-height: 45px;
        padding-left: 10px;
        background: #ffffff;
        font-size: 10px;
        font-weight: 50;
        word-wrap: break-word;
        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'),
            'one-dialog-alert': httpVueLoader('../../common/oneDialogAlert.vue')
        },
        data() {
            return {
                query: "",
                items: [],
                openprint: false,
                urlprint: '',
                printtitle: '',
                printwidth: 600,
                formatreport: 'pdf',
                readonlydefault: false,
                page: 1,
                xname: '',
                xphone: '',
                xcode: '',
                searchxArea: '',
                xdescription: '',
                xipdescription: '',
                xbasename: '',
                isdefault: false,
                issatellite: false,
                search_control: '',
                search_city: '',
                search_district: '',
                search_kelurahan: '',
                search_company: '',
                search_mou: '',
                search_doctor: '',
                search_test: '',
                search_info: '',
                menufilterdatestart: false,
                menufilterdateend: false,
                date: new Date().toISOString().substr(0, 10),
                xnameRules: [
                    v => !!v || 'Nama harus diisi'
                ],
                xcodeRules: [
                    v => !!v || 'Kode harus diisi'
                ],
                descriptionRules: [
                    v => !!v || 'Alamat harus diisi'
                ],
                xipdescriptionRules: [
                    v => !!v || 'Alamat IP harus diisi'
                ],
                controlRules: [
                    v => !!v || 'Control harus dipilih'
                ],
                cityRules: [
                    v => !!v || 'Kota harus dipilih'
                ],
                districtRules: [
                    v => !!v || 'Kecamatan harus dipilih'
                ],
                kelurahanRules: [
                    v => !!v || 'Kelurahan harus dipilih'
                ],
                headertitles: [{
                        text: "FACTORY",
                        align: "left",
                        sortable: false,
                        value: "lab",
                        width: "50%",
                        class: "teal lighten-3 white--text"
                    },
                    {
                        text: "ACTUAL",
                        align: "left",
                        sortable: false,
                        value: "lab",
                        width: "50%",
                        class: "teal lighten-3 white--text"
                    }
                ],
                headers: [{
                        text: "TGL / JAM",
                        align: "left",
                        sortable: false,
                        value: "lab",
                        width: "10%",
                        class: "teal lighten-3 white--text"
                    },
                    {
                        text: "NOMOR",
                        align: "left",
                        sortable: false,
                        value: "name",
                        width: "10%",
                        class: "teal lighten-3 white--text"
                    },
                    {
                        text: "NAMA PEMESAN",
                        align: "left",
                        sortable: false,
                        value: "name",
                        width: "20%",
                        class: "teal lighten-3 white--text"
                    },   
                    {
                        text: "AREA",
                        align: "left",
                        sortable: false,
                        value: "lab",
                        width: "20%",
                        class: "teal lighten-3 white--text"
                    },
                    {
                        text: "ALAMAT",
                        align: "left",
                        sortable: false,
                        value: "name",
                        width: "30%",
                        class: "teal lighten-3 white--text"
                    },
                    {
                        text: "PETUGAS",
                        align: "left",
                        sortable: false,
                        value: "name",
                        width: "20%",
                        class: "teal lighten-3 white--text"
                    },
                    {
                        text: "STATUS",
                        align: "left",
                        sortable: false,
                        value: "name",
                        width: "10%",
                        class: "teal lighten-3 white--text"
                    }
                ],
                pagination: {
                    descending: false,
                    page: 1,
                    rowsPerPage: 100,
                    sortBy: 'Nat_QcName ASC',
                    totalItems: this.$store.state.register.total_transactions
                },
                headerpatients: [{
                        text: "NAMA",
                        align: "left",
                        sortable: false,
                        value: "lab",
                        width: "30%",
                        class: "teal lighten-3 white--text"
                    },
                    {
                        text: "USIA / JENIS KELAMIN",
                        align: "left",
                        sortable: false,
                        value: "lab",
                        width: "10%",
                        class: "teal lighten-3 white--text"
                    },
                    {
                        text: "NO HP",
                        align: "left",
                        sortable: false,
                        value: "name",
                        width: "10%",
                        class: "teal lighten-3 white--text"
                    },
                    {
                        text: "AKSI",
                        align: "left",
                        sortable: false,
                        value: "name",
                        width: "10%",
                        class: "teal lighten-3 white--text"
                    }
                ],
                headertests: [{
                        text: "",
                        align: "left",
                        sortable: false,
                        value: "lab",
                        width: "5%",
                        class: "teal lighten-3 white--text"
                    },
                    {
                        text: "PEMERIKSAAN",
                        align: "left",
                        sortable: false,
                        value: "lab",
                        width: "20%",
                        class: "teal lighten-3 white--text"
                    },
                    {
                        text: "BRUTO",
                        align: "left",
                        sortable: false,
                        value: "name",
                        width: "10%",
                        class: "teal lighten-3 white--text"
                    },
                    {
                        text: "DISKON",
                        align: "left",
                        sortable: false,
                        value: "name",
                        width: "10%",
                        class: "teal lighten-3 white--text"
                    },
                    {
                        text: "TOTAL",
                        align: "left",
                        sortable: false,
                        value: "name",
                        width: "10%",
                        class: "teal lighten-3 white--text"
                    }
                ],
                statuss: [{
                        waktu: '16-07-2019 10:00',
                        status: 'Order Dibuat',
                        register: 'Nagita Slavina'
                    },
                    {
                        waktu: '16-07-2019 11:00',
                        status: 'Order Dikirim',
                        register: 'Nagita Slavina'
                    },
                    {
                        waktu: '16-07-2019 12:00',
                        status: 'Order dikonfirmasi',
                        register: 'Chacha Frederica'
                    },
                    {
                        waktu: '16-07-2019 13:00',
                        status: 'Telah dibuat Surat Jalan',
                        register: 'Chacha Frederica'
                    },
                    {
                        waktu: '16-07-2019 14:00',
                        status: 'Kurir akan mengambil sampel',
                        register: 'Satria Subiantoro'
                    }
                ],
                color: "success",
                validregister: false,
                xid: 0,
                isinput: "N",
                countprice: 0,
                registerid: 0,
                registerxname: "",
                registerlang: "",
                registertext: "",
                isadvance: "N",
                registerformatadvance: "",
                issenttocontrol: "N",
                menustartdate: false,
                menuenddate: false,
                date: new Date().toISOString().substr(0, 10),
                msgalertconfirmation: "Perubahan yang telah dilakukan belum disimpan dong !",
                dialogdeletealertregister: false,
                dialogverifyalertregister: false,
                dialogreleasealertregister: false,
                alertverify: false,
                dialogunreleasealertregister: false,
                dialogunverifyalertregister: false,
                msgalertregister: ""
            };
        },
        mounted() {
            this.$store.dispatch("register/lookupbyname")
        },
        computed: {
            registers() {
                return this.$store.state.register.registers
            },
            registertemp() {
                return this.$store.state.register.registertemp
            },
            xcontrol() {
                return this.$store.state.control.selected_control
            },
            xinfo() {
                return this.$store.state.info.selected_info
            },
            dialogregister() {
                return this.$store.state.register.dialog_form_register
            },
            xerrors() {
                return this.$store.state.register.errors
            },
            xqid() {
                return this.$store.state.register.qid
            },
            isLoading() {
                return this.$store.state.register.search_status == 1
            },
            filterComputedDateFormattedStart() {
                return this.formatDate(this.xstartdate)
            },
            filterComputedDateFormattedEnd() {
                return this.formatDate(this.xenddate)
            },
            flag_control: {
                get() {
                    return this.$store.state.register.flag_control
                },
                set(val) {
                    this.$store.commit("register/update_flag_control", val)
                    this.$store.commit("register/update_orderautocontrol", {})
                    this.$store.commit("register/update_multicontrol", [])
                    this.$store.dispatch("register/lookupbyid", {
                        sdate: this.xstartdate,
                        edate: this.xenddate,
                        controlid: 0,
                        controlname: '',
                        infoid: this.xorderautoinfo.Nat_InstrumentID,
                        infoname: this.xorderautoinfo.Nat_InstrumentName,
                        testid: this.xorderautotest.Nat_TestID,
                        testname: this.xorderautotest.Nat_TestName,
                        ismulticontrol: this.flag_control,
                        ismultitest: this.flag_test,
                        multicontrol: 0,
                        multitest: 0,
                        current_page: 1
                    })
                }
            },
            flag_test: {
                get() {
                    return this.$store.state.register.flag_test
                },
                set(val) {
                    this.$store.commit("register/update_flag_test", val)
                }
            },
            xstartdate: {
                get() {
                    return this.$store.state.register.startdate
                },
                set(val) {
                    this.$store.commit("register/update_startdate", val)
                    this.searchQc()
                }
            },
            endComputedDateFormatted() {
                return this.formatDate(this.xenddate)
            },
            xenddate: {
                get() {
                    return this.$store.state.register.enddate
                },
                set(val) {
                    this.$store.commit("register/update_enddate", val)
                    this.searchQc()
                }
            },
            xorderautotests() {
                return this.$store.state.register.orderautotests
            },
            xorderautotest: {
                get() {
                    return this.$store.state.register.orderautotest
                },
                set(val) {
                    this.$store.commit("register/update_orderautotest", val)

                    if (val) {
                        this.searchQc()
                    } else {
                        this.searchcontrol = ''
                        this.$store.commit("register/update_orderautocontrols", [])
                        this.$store.commit("register/update_orderautocontrol", {})
                        this.$store.commit("register/update_flag_control", 'N')
                        this.$store.commit("register/update_multicontrol", [])
                        this.$store.dispatch("register/lookupbyid", {
                            sdate: this.xstartdate,
                            edate: this.xenddate,
                            controlid: 0,
                            controlname: '',
                            infoid: 0,
                            infoname: '',
                            testid: 0,
                            testname: '',
                            ismulticontrol: 'N',
                            ismultitest: 'N',
                            multicontrol: 0,
                            multitest: 0,
                            current_page: 1
                        })
                    }
                }
            },
            xorderautocontrols() {
                return this.$store.state.register.orderautocontrols
            },
            xorderautocontrol: {
                get() {
                    return this.$store.state.register.orderautocontrol
                },
                set(val) {
                    this.$store.commit("register/update_orderautocontrol", val)
                    if (this.flag_control == 'Y') {
                        var oldArr = this.$store.state.register.multicontrol
                        oldArr.push(this.$store.state.register.orderautocontrol)
                        this.searchcontrol = ''
                        this.$store.commit("register/update_orderautocontrols", [])
                        this.$store.commit("register/update_orderautocontrol", {})
                        var tot = oldArr.length
                        console.log(oldArr.length)
                        this.$store.dispatch("register/lookuprule", {
                            control: tot
                        })
                        this.searchQc()
                    } else {
                        this.searchQc()
                        this.$store.dispatch("register/lookuprule", {
                            control: 1
                        })
                    }
                }
            },
            xorderautoinfos() {
                return this.$store.state.register.orderautoinfos
            },
            xorderautoinfo: {
                get() {
                    return this.$store.state.register.orderautoinfo
                },
                set(val) {

                    this.$store.commit("register/update_orderautoinfo", val)
                    if (val) {
                        this.searchQc()
                    } else {
                        this.searchcontrol = ''
                        this.$store.commit("register/update_orderautocontrols", [])
                        this.$store.commit("register/update_orderautocontrol", {})
                        this.searchtest = ''
                        this.$store.commit("register/update_orderautotests", [])
                        this.$store.commit("register/update_orderautotest", {})
                        this.$store.commit("register/update_flag_control", 'N')
                        this.$store.commit("register/update_multicontrol", [])
                        this.$store.dispatch("register/lookupbyid", {
                            sdate: this.xstartdate,
                            edate: this.xenddate,
                            controlid: 0,
                            controlname: '',
                            infoid: 0,
                            infoname: '',
                            testid: 0,
                            testname: '',
                            ismulticontrol: 'N',
                            ismultitest: 'N',
                            multicontrol: 0,
                            multitest: 0,
                            current_page: 1
                        })
                    }

                }
            },
            xordertests() {
                return this.$store.state.register.ordertests
            },
            xmulticontrol() {
                return this.$store.state.register.multicontrol
            },
            xrule() {
                return this.$store.state.register.xrule
            },
            xmultitest() {
                return this.$store.state.register.multitest
            },
            xautocitys() {
                return this.$store.state.register.autocitys
            },
            xautocity: {
                get() {
                    return this.$store.state.register.autocity
                },
                set(val) {
                    this.$store.commit("register/update_autocity", val)
                    this.$store.dispatch("register/searchdistrict", {
                        search: this.search_district,
                        id: val.M_CityID
                    })
                }
            },
            xautodistricts() {
                return this.$store.state.register.autodistricts
            },
            xautodistrict: {
                get() {
                    return this.$store.state.register.autodistrict
                },
                set(val) {
                    this.$store.commit("register/update_autodistrict", val)
                    this.$store.dispatch("register/searchkelurahan", {
                        search: this.search_kelurahan,
                        id: val.M_DistrictID
                    })
                }
            },
            xautokelurahans() {
                return this.$store.state.register.autokelurahans
            },
            xautokelurahan: {
                get() {
                    return this.$store.state.register.autokelurahan
                },
                set(val) {
                    this.$store.commit("register/update_autokelurahan", val)
                }
            },
            xautocompanys() {
                return this.$store.state.register.autocompanys
            },
            xautocompany: {
                get() {
                    return this.$store.state.register.autocompany
                },
                set(val) {
                    this.$store.commit("register/update_autocompany", val)
                    this.$store.dispatch("register/searchmou", {
                        search: this.search_mou,
                        id: val.M_CompanyID
                    })
                }
            },
            xautomous() {
                return this.$store.state.register.automous
            },
            xautomou: {
                get() {
                    return this.$store.state.register.automou
                },
                set(val) {
                    this.$store.commit("register/update_automou", val)
                }
            },
            xautodoctors() {
                return this.$store.state.register.autodoctors
            },
            xautodoctor: {
                get() {
                    return this.$store.state.register.autodoctor
                },
                set(val) {
                    this.$store.commit("register/update_autodoctor", val)
                    this.$store.dispatch("register/selectdescriptiondoctor", {
                        id: val.M_DoctorID
                    })
                }
            },
            xdescriptiondoctors() {
                return this.$store.state.register.descriptiondoctors
            },
            xdescriptiondoctor: {
                get() {
                    return this.$store.state.register.descriptiondoctor
                },
                set(val) {
                    this.$store.commit("register/update_descriptiondoctor", val)
                }
            },
            xstatuss() {
                return this.$store.state.register.statuss
            },
            dialogstatusorder() {
                return this.$store.state.register.dialog_status_order
            },
            xautocontrols() {
                return this.$store.state.register.autocontrols
            },
            xautocontrol: {
                get() {
                    return this.$store.state.register.autocontrol
                },
                set(val) {
                    this.$store.commit("register/update_autocontrol", val)
                }
            },
            xsearch: {
                get() {
                    return this.$store.state.register.x_search
                },
                set(val) {
                    this.$store.commit("register/update_x_search", val)
                }
            },
            no_save: {
                get() {
                    return this.$store.state.register.no_save
                },
                set(val) {
                    this.$store.commit("register/update_no_save", val)
                }
            },
            openalertconfirmation: {
                get() {
                    return this.$store.state.register.open_alert_confirmation
                },
                set(val) {
                    this.$store.commit("register/update_open_alert_confirmation", val)
                }
            },
            curr_page: {
                get() {
                    return this.$store.state.register.current_page
                },
                set(val) {
                    if (this.$store.state.register.no_save == 0) {
                        this.$store.commit("register/update_current_page", val)
                        this.searchQc()

                    } else {
                        this.$store.commit("register/update_open_alert_confirmation", true)
                    }


                }
            },

            snackbar: {
                get() {
                    return this.$store.state.register.alert_success
                },
                set(val) {
                    this.$store.commit("register/update_alert_success", val)
                }
            },
            msgsnackbar() {
                return this.$store.state.register.msg_success
            },
            xtotal_page: {
                get() {
                    return this.$store.state.register.total_data
                },
                set(val) {
                    this.$store.commit("register/update_total_data", val)
                }
            }
        },
        methods: {
            isSelected(p) {
                return p.id == this.$store.state.register.selected_register.id
            },
            selectMe(sc) {



            },
            updateDialogFormQc() {
                this.$store.commit("register/update_dialog_form_register", false)
            },
            updateDialogStatusOrder() {
                this.$store.commit("register/update_dialog_status_order", false)
            },
            setStatusOrder(val) {
                this.$store.commit("register/update_registers", {})
                this.$store.commit("register/update_dialog_status_order", true)
                this.$store.commit("register/update_statuss", val.statuss)
            },
            deleteDataPx(idx) {
                var inx = parseInt(idx);
                var xrow = this.$store.state.register.ordertests[inx]
                if (parseInt(xrow.xid) !== 0) {
                    var xdeltest = this.$store.state.register.deleted_ordertests
                    xdeltest.push(xrow)
                    this.$store.commit("register/update_deleted_ordertests", xdeltest)
                }
                var oldArr = this.$store.state.register.ordertests
                oldArr.splice(inx, 1)
                this.$store.commit("register/update_ordertests", oldArr)
            },
            deleteDataQc(idx) {
                var inx = parseInt(idx);
                var xrow = this.$store.state.register.multicontrol[inx]
                if (parseInt(xrow.xid) !== 0) {
                    var xdeltest = this.$store.state.register.deleted_multicontrol
                    xdeltest.push(xrow)
                    this.$store.commit("register/update_deleted_multicontrol", xdeltest)
                }
                var oldArr = this.$store.state.register.multicontrol
                oldArr.splice(inx, 1)
                this.$store.commit("register/update_multicontrol", oldArr)
                this.searchQc()
                var tot = oldArr.length
                console.log(oldArr.length)
                this.$store.dispatch("register/lookuprule", {
                    control: tot
                })
            },
            changeRule(idx, value) {
                let arr = this.$store.state.register.xrule
                arr[idx].isactive = value.isactive === 'N' ? 'Y' : 'N'
                this.$store.commit("register/update_xrule", arr)
            },
            doPriceList(val) {
                console.log(location)
                var id = val.id
                location.replace("/one-ui/control/vuex/one-md-price/" + "?id=" + id)
            },
            doPrice() {
                console.log(location)
                var id = this.xid
                location.replace("/one-ui/control/vuex/one-md-price/" + "?id=" + id)
            },
            thr_search_control: _.debounce(function () {
                this.$store.dispatch("register/searchcontrol", {
                    search: this.search_control,
                    infoid: this.xorderautoinfo.Nat_InstrumentID,
                    testid: this.xorderautotest.Nat_TestID,
                    controls: this.xmulticontrol
                })

            }, 200),
            thr_search_test: _.debounce(function () {
                this.$store.dispatch("register/searchtest", {
                    search: this.search_test,
                    infoid: this.xorderautoinfo.Nat_InstrumentID,
                    controlid: this.xorderautocontrol.Nat_QcControlID
                })
            }, 500),
            thr_search_info: _.debounce(function () {
                this.$store.dispatch("register/searchinfo", {
                    search: this.search_info,
                    id: this.xorderautocontrol.Nat_QcControlID
                })
            }, 200),
            thr_search_district: _.debounce(function () {
                this.$store.dispatch("register/searchdistrict", {
                    search: this.search_district,
                    id: this.xautocity.M_CityID
                })
            }, 200),
            thr_search_kelurahan: _.debounce(function () {
                this.$store.dispatch("register/searchkelurahan", {
                    search: this.search_kelurahan,
                    id: this.xautodistrict.M_DistrictID
                })
            }, 200),
            thr_search: _.debounce(function () {
                this.$store.dispatch("control/lookupbyname", {
                    control: this.$store.state.control.x_search,
                    info: this.$store.state.info.x_search,
                    register: this.xsearch,
                    current_page: 1,
                    lastid: -1
                })
                this.$store.dispatch("info/lookupbyname", {
                    control: this.$store.state.control.x_search,
                    info: this.$store.state.info.x_search,
                    register: this.xsearch,
                    current_page: 1,
                    lastid: -1
                })
                this.$store.dispatch("register/lookupbyname", {
                    control: this.$store.state.control.x_search,
                    info: this.$store.state.info.x_search,
                    sdate: this.xstartdate,
                    register: this.xsearch,
                    current_page: 1,
                    lastid: -1
                })
                this.$store.commit("info/update_selected_info", {
                    name: "Belum Pilih Instrument"
                })
            }, 200),
            thr_search_company: _.debounce(function () {
                this.$store.dispatch("register/searchcompany", {
                    search: this.search_company
                })
            }, 200),
            thr_search_mou: _.debounce(function () {
                this.$store.dispatch("register/searchmou", {
                    search: this.search_mou,
                    id: this.xautocompany.M_CompanyID
                })
            }, 200),
            thr_search_doctor: _.debounce(function () {
                this.$store.dispatch("register/searchdoctor", {
                    search: this.search_doctor
                })
            }, 200),
            searchControl() {
                this.$store.dispatch("register/lookup", {
                    id: this.xcontrol.Nat_InstrumentName === "Belum Pilih Control" ? "0" : this.$store.state
                        .control.selected_control
                        .id,
                    sdate: this.xstartdate,
                    search: this.xsearch,
                    current_page: 1,
                    lastid: -1
                })
            },
            doPrint() {
                //alert('doprint')
                this.printwidth = 1028
                this.printtitle = ""
                //  let register = one_register()
                var startdate = this.xstartdate
                var enddate = this.xenddate
                var idx = this.xqid
                console.log(idx)
                var ids = ("" + idx).replaceAll('-', ',')
                console.log(("" + idx).replaceAll('-', ','))
                var d = new Date();
                var n = d.getTime()
                var rptname = 'rpt_r_register'
                var formatrpt = 'pdf'
                let user = one_user()
                this.urlprint = "/birt/run?__report=report/one/rekap/rpt_r_register.rptdesign&__format=" +
                    formatrpt + "&fromm=" + startdate + "&too=" + enddate + "&ids=" + ids + "&username=" + user.M_UserUsername +
                    "&tm=" + n

                this.openprint = true
            },
            closePrint() {
                this.openprint = false
            },
            openFormQc(val) {
                this.xid = val
                this.$store.commit("register/update_ordertests", [])
                this.$store.commit("register/update_dialog_form_register", true)
            },
            editFormQc(val) {
                this.xid = val.id
                this.xname = val.Nat_QcName
                this.xdescription = val.Nat_QcDescription
                this.$store.commit("register/update_autocontrols", [{
                    Nat_QcControlID: val.Nat_QcControlID,
                    Nat_QcControlName: val.Nat_QcControlName
                }])
                this.$store.commit("register/update_autocontrol", {
                    Nat_QcControlID: val.Nat_QcControlID,
                    Nat_QcControlName: val.Nat_QcControlName
                })
                this.$store.commit("register/update_dialog_form_register", true)
            },
            checkError(value) {
                var errors = this.$store.state.register.errors
                if (errors.includes(value)) {
                    return true
                } else {
                    return false
                }
            },
            forgetAlertConfirmation() {
                this.$store.commit("register/update_no_save", 0)
                this.$store.commit("register/update_open_alert_confirmation", false)
            },
            closeAlertConfirmation() {
                this.$store.commit("register/update_open_alert_confirmation", false)
            },
            changeQc() {
                this.$store.commit("register/update_no_save", 1)
            },
            saveFormQc() {
                if (this.$refs.formcontrolregister.validate()) {
                    this.$store.dispatch("register/save", {
                        xid: this.xid,
                        controlid: this.$store.state.info.selected_info.Nat_QcControlID,
                        controlname: this.$store.state.info.selected_info.Nat_QcControlName,
                        infoid: this.$store.state.info.selected_info.Nat_InstrumentID,
                        infoname: this.$store.state.info.selected_info.Nat_InstrumentName,
                        tests: this.xordertests,
                        scontrol: this.$store.state.control.x_search,
                        sregister: this.xsearch
                    })
                }

            },
            simpanAll() {
                this.$store.dispatch("register/saveall", {
                    xid: this.xid,
                    controlid: this.$store.state.info.selected_info.Nat_QcControlID,
                    controlname: this.$store.state.info.selected_info.Nat_QcControlName,
                    infoid: this.$store.state.info.selected_info.Nat_InstrumentID,
                    infoname: this.$store.state.info.selected_info.Nat_InstrumentName,
                    tests: this.$store.state.register.registers,
                    rules: this.$store.state.register.xrule,
                    sdate: this.xstartdate,
                    scontrol: this.$store.state.control.x_search,
                    sinfo: this.xsearch
                })

            },
            searchQc() {
                this.$store.dispatch("register/lookupbyid", {
                    sdate: this.xstartdate,
                    edate: this.xenddate,
                    controlid: this.xorderautocontrol.Nat_QcControlID,
                    controlname: this.xorderautocontrol.Nat_QcControlName,
                    infoid: this.xorderautoinfo.Nat_InstrumentID,
                    infoname: this.xorderautoinfo.Nat_InstrumentName,
                    testid: this.xorderautotest.Nat_TestID,
                    testname: this.xorderautotest.Nat_TestName,
                    ismulticontrol: this.flag_control,
                    ismultitest: this.flag_test,
                    multicontrol: this.$store.state.register.multicontrol,
                    multitest: this.$store.state.register.multitest,
                    current_page: this.curr_page
                })
            },
            addTest() {
                this.$store.dispatch("register/addregister", {
                    sdate: this.xstartdate,
                    edate: this.xenddate,
                    controlid: this.xorderautocontrol.Nat_QcControlID,
                    controlname: this.xorderautocontrol.Nat_QcControlName,
                    infoid: this.xorderautoinfo.Nat_InstrumentID,
                    infoname: this.xorderautoinfo.Nat_InstrumentName,
                    testid: this.xorderautotest.Nat_TestID,
                    testname: this.xorderautotest.Nat_TestName,
                    current_page: 1
                })
            },
            printNote() {
                this.printwidth = 900
                this.printtitle = ""
                let user = one_user()
                var rpt = 'rpt_t_010'
                if (val.note_amount < 0)
                    rpt = 'rpt_t_010'
                this.urlprintnote = "/birt/run?__report=report/one/fo/" + rpt + ".rptdesign&__format=pdf&username=" +
                    user.M_UserUsername + "&PID=" + val.note_id
                this.$store.commit("register/update_open_print_register", true)
            },
            prosesQc() {
                this.$store.dispatch("register/saveall", {
                    xid: this.xid,
                    sdate: this.xstartdate,
                    edate: this.xenddate,
                    controlid: this.xorderautocontrol.Nat_QcControlID,
                    controlname: this.xorderautocontrol.Nat_QcControlName,
                    infoid: this.xorderautoinfo.Nat_InstrumentID,
                    infoname: this.xorderautoinfo.Nat_InstrumentName,
                    testid: this.xorderautotest.Nat_TestID,
                    testname: this.xorderautotest.Nat_TestName,
                    registers: this.$store.state.register.registers,
                    scontrol: this.$store.state.control.x_search,
                    sinfo: this.xsearch,
                    ismulticontrol: this.flag_control,
                    ismultitest: this.flag_test,
                    multicontrol: this.$store.state.register.multicontrol,
                    multitest: this.$store.state.register.multitest,
                    rule: this.$store.state.register.xrule,
                    qid: this.xqid,
                    current_page: this.curr_page
                })

            },
            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("register/update_alert_success", val)
            },
            activeFormQc(data) {
                this.xid = data.id

                this.msgalertregister = "Yakin, mau mengaktifkan register ini?"
                this.dialogdeletealertregister = true
            },
            closeActiveAlertQc() {
                this.$store.dispatch("register/activeregister", {
                    xid: this.xid,
                    controlid: this.$store.state.info.selected_info.Nat_QcControlID,
                    controlname: this.$store.state.info.selected_info.Nat_QcControlName,
                    infoid: this.$store.state.info.selected_info.Nat_InstrumentID,
                    infoname: this.$store.state.info.selected_info.Nat_InstrumentName,
                    name: this.xname,
                    scontrol: this.$store.state.control.x_search,
                    sregister: this.xsearch
                })
                this.dialogdeletealertregister = false
            }
        },
        watch: {
            xsearch(val, old) {
                console.log(val)
                this.xsearch = val
                this.thr_search()

            },
            search_control(val, old) {
                if (val == old) return
                if (!val) return
                if (val.length < 1) return
                if (this.$store.state.register.update_autocomplete_status == 1) return
                this.thr_search_control()
            },
            search_test(val, old) {
                if (val == old) return
                if (!val) return
                if (val.length < 1) return
                if (this.$store.state.register.update_autocomplete_status == 1) return
                this.thr_search_test()
            },
            search_info(val, old) {
                if (val == old) return
                if (!val) return
                if (val.length < 1) return
                if (this.$store.state.register.update_autocomplete_status == 1) return
                this.thr_search_info()
            },
            search_district(val, old) {
                if (val == old) return
                if (!val) return
                if (val.length < 1) return
                if (this.$store.state.register.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.register.update_autocomplete_status == 1) return
                this.thr_search_kelurahan()
            },
            search_company(val, old) {
                if (val == old) return
                if (!val) return
                if (val.length < 1) return
                if (this.$store.state.register.update_autocomplete_status == 1) return
                this.thr_search_company()
            },
            search_mou(val, old) {
                if (val == old) return
                if (!val) return
                if (val.length < 1) return
                if (this.$store.state.register.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.register.update_autocomplete_status == 1) return
                this.thr_search_doctor()
            }
        }
    }
</script>