<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.name}}"</v-toolbar-title>
                    <v-spacer></v-spacer>
                    <v-btn class="xs1 v-btn--flat one-btn-icon" color="transparent" @click="openCopyPriceRujukan(0)" v-if="pricerujukans.length == 0 && this.$store.state.rujukantype.selected_rujukantype.name !== '[Belum Pilih Tipe Rujukan]'">
                        <span class="icon-import"></span>
                    </v-btn> 
                    <v-btn v-if="this.$store.state.rujukantype.selected_rujukantype.name !== '[Belum Pilih Tipe Rujukan]'" @click="openFormPriceRujukan(0)"
                        icon>
                        <v-icon>library_add</v-icon>
                    </v-btn>
                    <v-btn class="xs1 v-btn--flat one-btn-icon" color="transparent" @click="deletePriceRujukanAll(0)" v-if="this.$store.state.rujukantype.selected_rujukantype.name !== '[Belum Pilih Tipe Rujukan]'">
                        <span class="icon-delete"></span>
                    </v-btn> 
                </v-toolbar>
                <v-layout row style="background:#bbdefb;padding-top:5px;" justify-left>
                    <input type="text" v-model="xfilter" class="textinput" label="Nama Station" placeholder="Cari ..." />
                        </v-list-tile-content>
                  <!--  <v-autocomplete label="Regional" outline style="height: 63px;" class="xs3 textinput ma-1" v-model="xautoregional" :items="xautoregionals"
                        :search-input.sync="search_regional" clearable auto-select-first no-filter item-text="S_RegionalName" return-object
                        no-data-text="Cari Regional" small>
                        <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-menu class="xs3 pr-2" 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 class="textinput ma-1" outline style="height: 63px;" v-model="filterComputedDateFormattedStart" label="Tgl Mulai"
                                readonly v-on="on" @blur="date = deFormatedDate(filterComputedDateFormattedStart)"></v-text-field>
                        </template>
                        <v-date-picker v-model="xstartdate" no-title @input="menufilterdatestart = false"></v-date-picker>
                    </v-menu>
                    <v-menu class="xs3 pr-2" v-model="menufilterdateedate" :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 class="textinput ma-1" outline style="height: 63px;" v-model="filterComputedDateFormattedEnd" label="Tgl. Selesai"
                                readonly v-on="on" @blur="date = deFormatedDate(filterComputedDateFormattedEnd)"></v-text-field>
                        </template>
                        <v-date-picker v-model="xenddate" no-title @input="menufilterdateedate = false"></v-date-picker>
                    </v-menu> -->
                   <!-- <v-autocomplete label="Pemeriksaan" clearable outline style="height: 63px;" class="xs4 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-text-field style="height: 63px;" outline class="xs3 textinput ma-1" v-model="xprice" label="Harga" hide-details></v-text-field>
                    <v-text-field style="height: 63px;" outline class="xs3 textinput ma-1" v-model="xpriority" label="Prioritas" hide-details></v-text-field>
                    <v-btn style="height: 55px;" color="primary" class="ma-0 one-btn-icon" fill-height @click="saveFormPriceRujukan()" :disabled="!btn_add_enabled">
                        <span class="icon-add"></span> -->
                    </v-btn>
                </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)" v-html="props.item.sdate">
                                </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.edate">
                                </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-html="props.item.Nat_PriceRujukanPriority">
                                </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>
                                                    <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="xautoregionalform" :items="xautoregionalforms" :search-input.sync="search_regionalform"
                                                    auto-select-first no-filter item-text="S_RegionalName" return-object no-data-text="Cari Regional"
                                                    small>
                                                    <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-layout>
                                                    <v-flex xs6>
                                                        <v-menu class="xs3 pr-2" v-model="menufilterdatestartform" :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 class="textinput ma-1" v-model="filterComputedDateFormattedStartForm" label="Tgl Mulai" outline readonly v-on="on"
                                                                    @blur="date = deFormatedDate(filterComputedDateFormattedStartForm)"></v-text-field>
                                                            </template>
                                                            <v-date-picker v-model="xstartdateform" no-title @input="menufilterdatestartform = false"></v-date-picker>
                                                        </v-menu>
                                                    </v-flex>
                                                    <v-flex xs6>
                                                        <v-menu class="xs3 pr-2" v-model="menufilterdateedateform" :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 class="textinput ma-1" v-model="filterComputedDateFormattedEndForm" label="Tgl. Selesai" outline readonly v-on="on"
                                                                    @blur="date = deFormatedDate(filterComputedDateFormattedEndForm)"></v-text-field>
                                                            </template>
                                                            <v-date-picker v-model="xenddateform" no-title @input="menufilterdateedateform = false"></v-date-picker>
                                                        </v-menu>
                                                    </v-flex>
                                                </v-layout>
                                            </v-flex>
                                            <v-flex xs12>
                                                <v-autocomplete label="Pemeriksaan" v-model="xautotestform" :items="xautotestforms" :search-input.sync="search_testform"
                                                    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*"></v-text-field>
        </v-flex>
        <v-flex xs12>
            <v-text-field v-model="xpriority" label="Prioritas*"></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" :disabled="in_saving" flat @click="saveFormPriceRujukanForm()">Simpan</v-btn>
        </v-card-actions>
        </v-form>
        </v-card>
        </v-dialog>



        <v-dialog v-model="dialogpricerujukancopy" persistent max-width="1000px">
            <v-card>
                <v-card-title>
                    <span class="headline">DUPLIKASI 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 xs6>
                                <v-layout mb-1 row>
                                    <v-subheader>TARGET</v-subheader>
                                </v-layout>
                                <v-layout row>
                                    <v-flex xs6 pa-2>
                                        <v-autocomplete label="Tipe Rujukan*" readonly 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 xs6 pa-2>
                                        <v-autocomplete label="Regional*" v-model="xautoregionalform" :items="xautoregionalforms" :search-input.sync="search_regionalform"
                                                    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-layout>
                                <v-layout pl-3 mb-4 row>
                                    <v-flex xs6 pa-2>
                                        <v-menu class="xs3 pr-2" v-model="menufilterdatestartcopy" :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 class="textinput ma-1" v-model="filterComputedDateFormattedStartCopy" label="Tgl Mulai" outline readonly v-on="on"
                                                            @blur="date = deFormatedDate(filterComputedDateFormattedStartCopy)"></v-text-field>
                                                    </template>
                                                    <v-date-picker v-model="xstartdatecopy" no-title @input="menufilterdatestartcopy = false"></v-date-picker>
                                                </v-menu>
                                    </v-flex>
                                    <v-flex xs6 pa-2>
                                        <v-menu class="xs3 pr-2" v-model="menufilterdateedatecopy" :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 class="textinput ma-1" v-model="filterComputedDateFormattedEndCopy" label="Tgl. Selesai" outline readonly v-on="on"
                                                            @blur="date = deFormatedDate(filterComputedDateFormattedEndCopy)"></v-text-field>
                                                    </template>
                                                    <v-date-picker v-model="xenddatecopy" no-title @input="menufilterdateedatecopy = false"></v-date-picker>
                                                </v-menu>
                                    </v-flex>
                                </v-layout>
                                <v-layout mb-1 row>
                                    <v-subheader>SUMBER</v-subheader>
                                </v-layout>
                                <v-layout pl-3 mb-1 row>
                                    <v-flex xs6 pa-2>
                                        <v-autocomplete label="Tipe Rujukan Yang Di Duplikasi" v-model="xautorujukantypedup" :items="xautorujukantypedups" :search-input.sync="search_rujukantypedup"
                                            auto-select-first no-filter item-text="Nat_PriceRujukanTypeName" return-object no-data-text="Cari Tipe Rujukan Yang Di Duplikasi"
                                            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 xs6 pa-2>
                                        <span>Duplikasi Harga Rujukan</span>
                                        <br><span>Dari : Harga Rujukan Regional {{this.copyregional}}</span></br>
                                        <span>Masa berlaku : {{this.copyperiode}}</span>
                                    </v-flex>
                                </v-layout>
                                <v-layout pl-3 mb-2 row>
                                    <v-flex>
                                        <div>
                                            <v-btn block @click="changeBtnFlagCopyAll(copyall)" v-if="copyall === 'N'" color="error">
                                                <v-icon left>close</v-icon> Gandakan semua sekaligus </v-btn>
                                            <v-btn block @click="changeBtnFlagCopyAll(copyall)" v-if="copyall === 'Y'" color="success">
                                                <v-icon left>check</v-icon> Gandakan semua sekaligus</v-btn>
                                        </div>
                                    </v-flex>
                                </v-layout>
                            </v-flex>
                            <v-flex xs6 pl-3>
                                <v-layout row>
                                    <v-flex xs12 pl-2 pr-2 pt-2 pb-2>
                                        <v-data-table :headers="headergroups" :items="xtransactions" :loading="isLoading" hide-actions class="elevation-1">
                                            <template v-slot:headers="props">
                                                <tr>
                                                    <th style="width:20px" class="text-xs-left blue-grey white--text">
                                                        <v-checkbox style="padding-top:0;margin-top:0" hide-details color="white" :disabled="copyall === 'Y'" :indeterminate="indeterminatex"
                                                            @change="changeCbxAll(bar_chx_all)" v-model="bar_chx_all"></v-checkbox>
                                                    </th>
                                                    <th v-for="header in props.headers" :key="header.text" :class="header.class" :width="header.width">
                                                        {{ header.text }}
                                                    </th>
                                                </tr>
                                            </template>

                                            <template v-slot:items="props">
                                                <td style="width:20px" class="text-xs-left">
                                                    <v-checkbox style="padding-top:0;margin-top:0" color="blue-grey" hide-details :disabled="copyall === 'Y'" v-model="props.item.chex"
                                                        @change="checkTop()"></v-checkbox>
                                                </td>
                                                <td class="text-xs-left pa-2">{{ props.item.Nat_JPAGroupName }} ( <span style="color:red">{{fixedDiscount(props.item.Nat_JpaGroupMaxPxDisc)}} %</span>                                                    )</td>
                                                <td class="text-xs-left pa-2">
                                                    <v-text-field label="DISKON (%)" single-line :disabled="copyall === 'Y'" hide-details v-model="props.item.discount"></v-text-field>
                                                </td>
                                            </template>
                                        </v-data-table>
                                    </v-flex>
                                </v-layout>
                            </v-flex>
                        </v-layout>
                        </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-card-actions>
                    <v-spacer></v-spacer>
                    <v-btn color="blue darken-1" flat @click="updateDialogFormPriceRujukanCopy()">Tutup</v-btn>
                    <v-btn color="blue darken-1" flat @click="saveFormPriceRujukanFormCopy()">Simpan</v-btn>
                </v-card-actions>
                        </v-layout>
                </v-card-text>
                </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>
<template>

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

    </template>
<one-dialog-info :status="opendialoginfo" :msg="msginfo" @close-dialog-info="opendialoginfo = false"></one-dialog-info>
    </v-layout>
</template>

<style scoped>
    .searchbox .v-input.v-text-field .v-input__slot {
        min-height: 60px;
    }

    .searchbox .v-btn {
        min-height: 60px;
    }

    table.v-table tbody td,
    table.v-table tbody th {
        height: 40px;
    }

    table.v-table thead tr {
        height: 40px;
    }

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

    }

    .textinput:focus {
        width: 100%;
    }

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    ::-webkit-scrollbar-corner {
        background-color: black;
    }

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

<script>
    module.exports = {
        components: {
            'one-dialog-print': httpVueLoader('../../../common/oneDialogPrintX.vue'),
            'one-dialog-info': httpVueLoader('../../../common/oneDialogInfo.vue')
        },
        data() {
            return {
                indeterminatex: false,
                bar_chx_all: false,
                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_rujukantypedup: '',
                search_regional: '',
                search_regionalform: '',
                search_district: '',
                search_kelurahan: '',
                search_test: '',
                search_testform: '',
                search_mou: '',
                search_doctor: '',
                menufilterdatestart: false,
                menufilterdateedate: false,
                menufilterdatestartform: false,
                menufilterdateedateform: false,
                menufilterdatestartcopy: false,
                menufilterdateedatecopy: false,
                xpriceRules: [
                    v => !!v || 'Harga harus diisi'
                ],
                xpriorityRules: [
                    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: "TGL. MULAI",
                        align: "left",
                        sortable: false,
                        value: "lab",
                        width: "10%",
                        class: "blue lighten-3 white--text"
                    },
                    {
                        text: "TGL. SELESAI",
                        align: "left",
                        sortable: false,
                        value: "lab",
                        width: "10%",
                        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: "PRIORITAS",
                        align: "left",
                        sortable: false,
                        value: "lab",
                        width: "5%",
                        class: "blue lighten-3 white--text"
                    },
                    {
                        text: "AKSI",
                        align: "left",
                        sortable: false,
                        value: "status",
                        width: "10%",
                        class: "blue lighten-3 white--text"
                    }
                ],
                headergroups: [{
                        text: "GROUP",
                        align: "left",
                        sortable: false,
                        value: "name",
                        width: "65%",
                        class: "pa-2 blue-grey text-xs-left white--text"
                    },
                    {
                        text: "DISKON",
                        align: "center",
                        sortable: false,
                        value: "status",
                        width: "15%",
                        class: "pa-2 blue-grey text-xs-left 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,
                xtestid: 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,
                dialogdeletealertpricerujukanall: false,
                dialogverifyalertpricerujukan: false,
                dialogreleasealertpricerujukan: false,
                alertverify: false,
                dialogunreleasealertpricerujukan: false,
                dialogunverifyalertpricerujukan: false,
                msgalertpricerujukan: ""
            };
        },
        mounted() {
            this.$store.dispatch("pricerujukan/getjpagroups")
        },
        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
            },
            dialogpricerujukancopy() {
                return this.$store.state.pricerujukan.dialog_form_pricerujukancopy
            },
            in_saving() {
                return this.$store.state.pricerujukan.in_saving
            },
            in_savingcopy() {
                return this.$store.state.pricerujukan.in_savingcopy
            },
            xerrors() {
                return this.$store.state.pricerujukan.errors
            },
            isLoading() {
                return this.$store.state.pricerujukan.search_status == 1
            },
            filterComputedDateFormattedStart() {
                return this.formatDate(this.xstartdate)
            },
            opendialoginfo: {
                get() {
                    return this.$store.state.pricerujukan.open_dialog_info
                },
                set(val) {
                    this.$store.commit("pricerujukan/update_open_dialog_info", val)
                }
            },
            msginfo() {
                return this.$store.state.pricerujukan.msg_info
            },
            xfilter: {
                get() {
                    return this.$store.state.pricerujukan.xfilter
                },
                set(val) {
                    this.$store.commit("pricerujukan/update_xfilter", val)
                }
            },
            xstartdate: {
                get() {
                    return this.$store.state.pricerujukan.startdate
                },
                set(val) {
                    this.$store.commit("pricerujukan/update_startdate", 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.xfilter,
                        price: this.xprice,
                        sdate: this.xstartdate,
                        edate: this.xenddate,
                        priority: this.xpriority,
                        current_page: 1,
                        lastid: -1
                    })
                }
            },
            filterComputedDateFormattedEnd() {
                return this.formatDate(this.xenddate)
            },
            xenddate: {
                get() {
                    return this.$store.state.pricerujukan.enddate
                },
                set(val) {
                    this.$store.commit("pricerujukan/update_enddate", 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.xfilter,
                        price: this.xprice,
                        sdate: this.xstartdate,
                        edate: this.xenddate,
                        priority: this.xpriority,
                        current_page: 1,
                        lastid: -1
                    })
                }
            },
            filterComputedDateFormattedStartForm() {
                return this.formatDate(this.xstartdateform)
            },
            xstartdateform: {
                get() {
                    return this.$store.state.pricerujukan.startdateform
                },
                set(val) {
                    this.$store.commit("pricerujukan/update_startdateform", val)
                }
            },
            filterComputedDateFormattedEndForm() {
                return this.formatDate(this.xenddateform)
            },
            xenddateform: {
                get() {
                    return this.$store.state.pricerujukan.enddateform
                },
                set(val) {
                    this.$store.commit("pricerujukan/update_enddateform", val)
                }
            },
            filterComputedDateFormattedStartCopy() {
                return this.formatDate(this.xstartdatecopy)
            },
            xstartdatecopy: {
                get() {
                    return this.$store.state.pricerujukan.startdatecopy
                },
                set(val) {
                    this.$store.commit("pricerujukan/update_startdatecopy", val)
                }
            },
            filterComputedDateFormattedEndCopy() {
                return this.formatDate(this.xenddatecopy)
            },
            xenddatecopy: {
                get() {
                    return this.$store.state.pricerujukan.enddatecopy
                },
                set(val) {
                    this.$store.commit("pricerujukan/update_enddatecopy", 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,
                        sdate: this.xstartdate,
                        edate: this.xenddate,
                        priority: this.xpriority,
                        current_page: 1,
                        lastid: -1
                    })
                }
            },
            xautoregionalforms() {
                return this.$store.state.pricerujukan.autoregionalforms
            },
            xautoregionalform: {
                get() {
                    return this.$store.state.pricerujukan.autoregionalform
                },
                set(val) {
                    this.$store.commit("pricerujukan/update_autoregionalform", val)
                }
            },
            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 !==
                    '' && this.xpriority !== '')
                    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: xfilter,
                        price: this.xprice,
                        sdate: this.xstartdate,
                        edate: this.xenddate,
                        priority: this.xpriority,
                        current_page: 1,
                        lastid: -1
                    })
                }
            },
            xautotestforms() {
                return this.$store.state.pricerujukan.autotestforms
            },
            xautotestform: {
                get() {
                    return this.$store.state.pricerujukan.autotestform
                },
                set(val) {
                    this.$store.commit("pricerujukan/update_autotestform", val)
                }
            },
            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)
                }
            },
            xautorujukantypedups() {
                return this.$store.state.pricerujukan.autorujukantypedups
            },
            xautorujukantypedup: {
                get() {
                    return this.$store.state.pricerujukan.autorujukantypedup
                },
                set(val) {
                    this.$store.commit("pricerujukan/update_autorujukantypedup", val)
                    this.$store.commit("pricerujukan/update_copyregional", val.regional)
                    this.$store.commit("pricerujukan/update_copyperiode", val.periode)
                }
            },
            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.xfilter,
                        price: this.xprice,
                        sdate: this.xstartdate,
                        edate: this.xenddate,
                        priority: this.xpriority,
                        current_page: 1,
                        lastid: -1
                    })
                }
            },
            xpriority: {
                get() {
                    return this.$store.state.pricerujukan.xpriority
                },
                set(val) {
                    this.$store.commit("pricerujukan/update_xpriority", 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.xfilter,
                        price: this.xprice,
                        sdate: this.xstartdate,
                        edate: this.xenddate,
                        priority: this.xpriority,
                        current_page: 1,
                        lastid: -1
                    })
                }
            },
            xsearch: {
                get() {
                    return this.$store.state.pricerujukan.x_search
                },
                set(val) {
                    this.$store.commit("pricerujukan/update_x_search", val)
                }
            },
            copyregional: {
                get() {
                    return this.$store.state.pricerujukan.copyregional
                },
                set(val) {
                    this.$store.commit("pricerujukan/update_copyregional", val)
                }
            },
            copyperiode: {
                get() {
                    return this.$store.state.pricerujukan.copyperiode
                },
                set(val) {
                    this.$store.commit("pricerujukan/update_copyperiode", 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.xfilter,
                        price: this.xprice,
                        sdate: this.xstartdate,
                        edate: this.xenddate,
                        priority: this.xpriority,
                        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)
                }
            },
            copyall: {
                get() {
                    return this.$store.state.pricerujukan.copyall
                },
                set(v) {
                    this.$store.commit('pricerujukan/update_copyall', v)
                }
            },
            xtransactions() {
                return this.$store.state.pricerujukan.jpagroups
            }
        },
        methods: {
            isSelected(p) {
                return p.id == this.$store.state.pricerujukan.selected_pricerujukan.id
            },
            selectMe(sc) {
                this.$store.commit("pricerujukan/update_selected_pricerujukan", sc)

            },
            changeBtnFlagCopyAll(value) {
                var newval = (value === 'Y') ? 'N' : 'Y'
                this.copyall = newval
            },
            updateDialogFormPriceRujukan() {
                this.$store.commit("pricerujukan/update_dialog_form_pricerujukan", false)
            },
            updateDialogFormPriceRujukanForm() {
                this.$store.commit("pricerujukan/update_dialog_form_pricerujukanform", false)
            },
            updateDialogFormPriceRujukanCopy() {
                this.$store.commit("pricerujukan/update_dialog_form_pricerujukancopy", 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", {
                    search: this.search_rujukantype
                })
            }, 2000),
            thr_search_rujukantypedup: _.debounce(function () {
                this.$store.dispatch("pricerujukan/searchrujukantypedup", {
                    search: this.search_rujukantypedup
                })
            }, 2000),
            thr_search_regional: _.debounce(function () {
                this.$store.dispatch("pricerujukan/searchregional", {
                    search: this.search_regional
                })
            }, 2000),
            thr_search_regionalform: _.debounce(function () {
                this.$store.dispatch("pricerujukan/searchregionalform", {
                    search: this.search_regionalform
                })
            }, 2000),
            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.xfilter,
                    price: this.xprice,
                    sdate: this.xstartdate,
                    edate: this.xenddate,
                    priority: this.xpriority,
                    current_page: 1,
                    lastid: -1
                })
            }, 200),
            thr_search_test: _.debounce(function () {
                this.$store.dispatch("pricerujukan/searchtest", {
                    search: this.search_test
                })
            }, 2000),
            thr_search_testform: _.debounce(function () {
                this.$store.dispatch("pricerujukan/searchtestform", {
                    tiperujukan: this.$store.state.rujukantype.selected_rujukantype.code,
                    search: this.search_testform,
                    testid: this.xtestid
                })
            }, 2000),
            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.xfilter,
                    price: this.xprice,
                    sdate: this.xstartdate,
                    edate: this.xenddate,
                    priority: this.xpriority,
                    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.xtestid = 0
                this.xprice = ''
                this.xpriority = ''
                this.xstartdateform = moment(new Date()).format('YYYY-MM-DD')
                this.xenddateform = moment(new Date()).format('YYYY-MM-DD')
                console.log('cek regional',this.$store.state.rujukantype.selected_rujukantype.S_RegionalID)
                if(this.$store.state.rujukantype.selected_rujukantype.S_RegionalID > 0){
                    this.$store.commit("pricerujukan/update_autoregionalforms", [{
                    S_RegionalID: this.$store.state.rujukantype.selected_rujukantype.S_RegionalID,
                    S_RegionalName: this.$store.state.rujukantype.selected_rujukantype.S_RegionalName
                }])
                this.$store.commit("pricerujukan/update_autoregionalform", {
                    S_RegionalID: this.$store.state.rujukantype.selected_rujukantype.S_RegionalID,
                    S_RegionalName: this.$store.state.rujukantype.selected_rujukantype.S_RegionalName
                })
                }else{
                    this.$store.commit("pricerujukan/update_autoregionalforms", [])
                    this.$store.commit("pricerujukan/update_autoregionalform", {})
                }                
                this.$store.commit("pricerujukan/update_autotestforms", [])
                this.$store.commit("pricerujukan/update_autotestform", {})
                this.$store.commit("pricerujukan/update_dialog_form_pricerujukan", true)
            },
            openCopyPriceRujukan(val) {
                this.xid = val
                this.xstartdatecopy = moment(new Date()).format('YYYY-MM-DD')
                this.xenddatecopy = moment(new Date()).format('YYYY-MM-DD')
                this.$store.commit("pricerujukan/update_autoregionalforms", [])
                this.$store.commit("pricerujukan/update_autoregionalform", {})
                this.$store.commit("pricerujukan/update_autorujukantypedups", [])
                this.$store.commit("pricerujukan/update_autorujukantypedup", {})
                this.$store.commit("pricerujukan/update_dialog_form_pricerujukancopy", true)
            },
            editFormPriceRujukan(val) {
                this.xid = val.id
                this.xtestid = val.T_TestID
                this.xprice = val.Nat_PriceRujukanAmount
                this.xpriority = val.Nat_PriceRujukanPriority
                this.xstartdateform = val.Nat_PriceRujukanStartDate
                this.xenddateform = val.Nat_PriceRujukanEndDate
                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_autoregionalforms", [{
                    S_RegionalID: val.S_RegionalID,
                    S_RegionalName: val.S_RegionalName
                }])
                this.$store.commit("pricerujukan/update_autoregionalform", {
                    S_RegionalID: val.S_RegionalID,
                    S_RegionalName: val.S_RegionalName
                })
                this.$store.commit("pricerujukan/update_autotestforms", [{
                    T_TestID: val.T_TestID,
                    T_TestName: val.T_TestName
                }])
                this.$store.commit("pricerujukan/update_autotestform", {
                    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.commit("pricerujukan/update_in_saving", true)
                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,
                    sdate: this.xstartdate,
                    edate: this.xenddate,
                    priority: this.xpriority,
                    srujukantype: this.$store.state.rujukantype.x_search,
                    spricerujukan: this.xsearch
                })


            },
            saveFormPriceRujukanForm() {
                var go_action = true
                var errors = []
                var transactions = this.$store.state.pricerujukan.jpagroups
                if ((_.isEmpty(this.xautoregionalform) || !this.xautoregionalform)) {
                    errors.push("Eits tentukan dulu regionalnya")
                    go_action = false
                }

                if ((_.isEmpty(this.xautorujukantype) || !this.xautorujukantype)) {
                    go_action = false
                    errors.push("Pilih tipe rujukan dulu")
                }
                
                if ((_.isEmpty(this.xautotestform) || !this.xautotestform)) {
                    go_action = false
                    errors.push("Pilih pemeriksaan dulu")
                }
                if((this.xprice === "")){
                    go_action = false
                    errors.push("Harganya juga diisi doooong")
                }
                if((this.xpriority === "")){
                    go_action = false
                    errors.push("Prioritasnya diisi ya")
                }
                if (go_action) {
                this.$store.commit("pricerujukan/update_in_saving", true)
                this.$store.dispatch("pricerujukan/saveform", {
                    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.autoregionalform.S_RegionalID ? this.$store.state
                        .pricerujukan.autoregionalform.S_RegionalID : 0,
                    regionalname: this.$store.state.pricerujukan.autoregionalform.S_RegionalID ? this.$store
                        .state
                        .pricerujukan.autoregionalform.S_RegionalName : '',
                    testid: this.$store.state.pricerujukan.autotestform.T_TestID ? this.$store.state.pricerujukan
                        .autotestform.T_TestID : 0,
                    testname: this.$store.state.pricerujukan.autotestform.T_TestID ? this.$store.state.pricerujukan
                        .autotestform.T_TestName : '',
                    price: this.xprice,
                    sdate: this.xstartdateform,
                    edate: this.xenddateform,
                    sdatex: this.xstartdate,
                    edatex: this.xenddate,
                    regionalidx: this.$store.state.pricerujukan.autoregional.S_RegionalID ? this.$store.state
                        .pricerujukan.autoregional.S_RegionalID : 0,
                    regionalnamex: this.$store.state.pricerujukan.autoregional.S_RegionalID ? this.$store.state
                        .pricerujukan.autoregional.S_RegionalName : '',
                    testidx: this.xfilter,
                    testnamex: this.$store.state.pricerujukan.autotest.T_TestID ? this.$store.state.pricerujukan
                        .autotest.T_TestName : '',
                    priority: this.xpriority,
                    srujukantype: this.$store.state.rujukantype.x_search,
                    spricerujukan: this.xsearch
                })
                } else {
                    this.$store.commit("pricerujukan/update_msg_info", errors.join('</br></br>'))
                    this.$store.commit("pricerujukan/update_open_dialog_info", true)
                    console.log('open ' + this.open_dialog_info)
                }

            },
            saveFormPriceRujukanFormCopyLAMA() {
                this.$store.commit("pricerujukan/update_in_savingcopy", true)
                this.$store.dispatch("pricerujukan/savecopy", {
                    xid: this.xid,
                    rujukantypeid: this.xautorujukantype ? this.$store.state.pricerujukan.autorujukantype
                        .Nat_PriceRujukanTypeCode : 0,
                    rujukantypename: this.$store.state.pricerujukan.autorujukantype.Nat_PriceRujukanTypeName,
                    rujukantypeidcopy: this.xautorujukantypedup ? this.$store.state.pricerujukan.autorujukantypedup
                        .Nat_PriceRujukanTypeCode : 0,
                    rujukantypenamecopy: this.$store.state.pricerujukan.autorujukantypedup.Nat_PriceRujukanTypeName,
                    regionalid: this.$store.state.pricerujukan.autoregionalform.S_RegionalID ? this.$store.state
                        .pricerujukan.autoregionalform.S_RegionalID : 0,
                    regionalname: this.$store.state.pricerujukan.autoregionalform.S_RegionalID ? this.$store
                        .state
                        .pricerujukan.autoregionalform.S_RegionalName : '',
                    testid: this.$store.state.pricerujukan.autotestform.T_TestID ? this.$store.state.pricerujukan
                        .autotestform.T_TestID : 0,
                    testname: this.$store.state.pricerujukan.autotestform.T_TestID ? this.$store.state.pricerujukan
                        .autotestform.T_TestName : '',
                    price: this.xprice,
                    sdate: this.xstartdatecopy,
                    edate: this.xenddatecopy,
                    sdatex: this.xstartdate,
                    edatex: this.xenddate,
                    regionalidx: this.$store.state.pricerujukan.autoregional.S_RegionalID ? this.$store.state
                        .pricerujukan.autoregional.S_RegionalID : 0,
                    regionalnamex: this.$store.state.pricerujukan.autoregional.S_RegionalID ? this.$store.state
                        .pricerujukan.autoregional.S_RegionalName : '',
                    testidx: this.xfilter,
                    testnamex: this.$store.state.pricerujukan.autotest.T_TestID ? this.$store.state.pricerujukan
                        .autotest.T_TestName : '',
                    priority: this.xpriority,
                    srujukantype: this.$store.state.rujukantype.x_search,
                    spricerujukan: this.xsearch
                })


            },
            saveFormPriceRujukanFormCopy() {
                var go_action = true
                var errors = []
                var transactions = this.$store.state.pricerujukan.jpagroups
                if (this.copyall === 'Y' && (_.isEmpty(this.xautoregionalform) || !this.xautoregionalform)) {
                    errors.push("Eits tentukan dulu regionalnya")
                    go_action = false
                }

                if (this.copyall === 'Y' && (_.isEmpty(this.xautorujukantypedup) || !this.xautorujukantypedup)) {
                    go_action = false
                    errors.push("Pilih tipe rujukan dulu")
                }

                if (this.copyall === 'N' && (_.isEmpty(this.xautoregionalform) || !this.xautoregionalform)) {
                    errors.push("Eits tentukan dulu regionalnya")
                    go_action = false
                }


                if (this.copyall === 'N' && (_.isEmpty(this.xautorujukantypedup) || !this.xautorujukantypedup)) {
                    go_action = false
                    errors.push("Pilih tipe rujukan dulu")
                }


                if (this.copyall === 'N' && (_.isEmpty(this.$store.state.pricerujukan.selected_transaction) || !this.$store
                        .state.pricerujukan.selected_transaction)) {
                    errors.push("Diet nasi makan kentang, salah satu group harus dicentang")
                    go_action = false
                }

                transactions.forEach(function (entry, index) {
                    if (parseFloat(entry.discount) > parseFloat(entry.Nat_JpaGroupMaxPxDisc)) {
                        go_action = false
                        errors.push("Diskon " + entry.Nat_JPAGroupName +
                            " melebihi dari ketetapan maksimal")
                    }
                })
                // console.log(errors)
                if (go_action) {
                    this.$store.commit("pricerujukan/update_in_savingcopy", true)
                    var prm = {
                        trx: this.$store.state.pricerujukan.jpagroups
                    }
                    prm.copyall = this.$store.state.pricerujukan.copyall
                    prm.xid = this.xid
                    prm.rujukantypeid = this.xautorujukantype ? this.$store.state.pricerujukan.autorujukantype
                        .Nat_PriceRujukanTypeCode : 0
                    prm.rujukantypename = this.$store.state.pricerujukan.autorujukantype.Nat_PriceRujukanTypeName
                    prm.rujukantypeidcopy = this.xautorujukantypedup ? this.$store.state.pricerujukan.autorujukantypedup.Nat_PriceRujukanTypeCode : 0
                    prm.rujukantypenamecopy = this.$store.state.pricerujukan.autorujukantypedup.Nat_PriceRujukanTypeName
                    prm.regionalid = this.$store.state.pricerujukan.autoregionalform.S_RegionalID ? this.$store.state.pricerujukan.autoregionalform.S_RegionalID : 0
                    prm.regionalname = this.$store.state.pricerujukan.autoregionalform.S_RegionalID ? this.$store.state.pricerujukan.autoregionalform.S_RegionalName : ''
                    prm.testid = this.$store.state.pricerujukan.autotestform.T_TestID ? this.$store.state.pricerujukan.autotestform.T_TestID : 0
                    prm.testname = this.$store.state.pricerujukan.autotestform.T_TestID ? this.$store.state.pricerujukan.autotestform.T_TestName : ''
                    prm.price = this.xprice
                    prm.sdate = this.xstartdatecopy
                    prm.edate = this.xenddatecopy
                    prm.sdatex = this.xstartdate
                    prm.edatex = this.xenddate
                    prm.regionalidx = this.$store.state.pricerujukan.autoregional.S_RegionalID ? this.$store.state.pricerujukan.autoregional.S_RegionalID : 0
                    prm.regionalnamex = this.$store.state.pricerujukan.autoregional.S_RegionalID ? this.$store.state.pricerujukan.autoregional.S_RegionalName : ''
                    prm.testidx = this.xfilter
                    prm.testnamex = this.$store.state.pricerujukan.autotest.T_TestID ? this.$store.state.pricerujukan.autotest.T_TestName : ''
                    prm.priority = this.xpriority
                    prm.srujukantype = this.$store.state.rujukantype.x_search
                    prm.spricerujukan = this.xsearch
                    this.$store.dispatch('pricerujukan/save_copy', prm)
                } else {
                    this.$store.commit("pricerujukan/update_msg_info", errors.join('</br></br>'))
                    this.$store.commit("pricerujukan/update_open_dialog_info", true)
                    console.log('open ' + this.open_dialog_info)
                }

            },
            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
            },
            deletePriceRujukanAll() {
                this.xid = this.xautorujukantype ? this.$store.state.pricerujukan.autorujukantype
                        .Nat_PriceRujukanTypeCode : 0
                this.msgalertpricerujukan = "Yakin, mau hapus " + "harga tipe rujukan " + this.$store.state.pricerujukan.autorujukantype.Nat_PriceRujukanTypeName +
                    " regional ini?"
                this.dialogdeletealertpricerujukanall = true
            },
            closeDeleteAlertPriceRujukanAll() {
                this.$store.dispatch("pricerujukan/deleteall", {
                    xid: this.xid,
                    rujukantypeid: this.xautorujukantype ? this.$store.state.pricerujukan.autorujukantype
                        .Nat_PriceRujukanTypeCode : 0,
                    regionalid: this.$store.state.pricerujukan.autoregionalform.S_RegionalID ? this.$store.state
                        .pricerujukan.autoregionalform.S_RegionalID : 0,
                    regionalname: this.$store.state.pricerujukan.autoregionalform.S_RegionalID ? this.$store
                        .state
                        .pricerujukan.autoregionalform.S_RegionalName : '',
                    testid: this.$store.state.pricerujukan.autotestform.T_TestID ? this.$store.state.pricerujukan
                        .autotestform.T_TestID : 0,
                    testid: this.$store.state.pricerujukan.autotestform.T_TestID ? this.$store.state.pricerujukan
                        .autotestform.T_TestID : 0,
                    testname: this.$store.state.pricerujukan.autotestform.T_TestID ? this.$store.state.pricerujukan
                        .autotestform.T_TestName : '',
                    price: this.xprice,
                    sdate: this.xstartdateform,
                    edate: this.xenddateform,
                    sdatex: this.xstartdate,
                    edatex: this.xenddate,
                    regionalidx: this.$store.state.pricerujukan.autoregional.S_RegionalID ? this.$store.state
                        .pricerujukan.autoregional.S_RegionalID : 0,
                    regionalnamex: this.$store.state.pricerujukan.autoregional.S_RegionalID ? this.$store.state
                        .pricerujukan.autoregional.S_RegionalName : '',
                    testidx: this.xfilter,
                    testnamex: this.$store.state.pricerujukan.autotest.T_TestID ? this.$store.state.pricerujukan
                        .autotest.T_TestName : '',
                    priority: this.xpriority,
                    srujukantype: this.$store.state.rujukantype.x_search,
                    spricerujukan: this.xsearch
                })
                this.dialogdeletealertpricerujukanall = false
            },
            closeDeleteAlertPriceRujukan() {
                this.$store.dispatch("pricerujukan/delete", {
                    xid: this.xid,
                    rujukantypeid: this.xautorujukantype ? this.$store.state.pricerujukan.autorujukantype
                        .Nat_PriceRujukanTypeCode : 0,
                    regionalid: this.$store.state.pricerujukan.autoregionalform.S_RegionalID ? this.$store.state
                        .pricerujukan.autoregionalform.S_RegionalID : 0,
                    regionalname: this.$store.state.pricerujukan.autoregionalform.S_RegionalID ? this.$store
                        .state
                        .pricerujukan.autoregionalform.S_RegionalName : '',
                    testid: this.$store.state.pricerujukan.autotestform.T_TestID ? this.$store.state.pricerujukan
                        .autotestform.T_TestID : 0,
                    testid: this.$store.state.pricerujukan.autotestform.T_TestID ? this.$store.state.pricerujukan
                        .autotestform.T_TestID : 0,
                    testname: this.$store.state.pricerujukan.autotestform.T_TestID ? this.$store.state.pricerujukan
                        .autotestform.T_TestName : '',
                    price: this.xprice,
                    sdate: this.xstartdateform,
                    edate: this.xenddateform,
                    sdatex: this.xstartdate,
                    edatex: this.xenddate,
                    regionalidx: this.$store.state.pricerujukan.autoregional.S_RegionalID ? this.$store.state
                        .pricerujukan.autoregional.S_RegionalID : 0,
                    regionalnamex: this.$store.state.pricerujukan.autoregional.S_RegionalID ? this.$store.state
                        .pricerujukan.autoregional.S_RegionalName : '',
                    testidx: this.xfilter,
                    testnamex: this.$store.state.pricerujukan.autotest.T_TestID ? this.$store.state.pricerujukan
                        .autotest.T_TestName : '',
                    priority: this.xpriority,
                    srujukantype: this.$store.state.rujukantype.x_search,
                    spricerujukan: this.xsearch
                })
                this.dialogdeletealertpricerujukan = false
            },
            checkTop() {
                var barcodes = this.xtransactions
                var selected = _.filter(barcodes, function (o) {
                    return o.chex;
                })
                this.bar_chx_all = false
                this.indeterminatex = false
                if (selected.length > 0 && barcodes.length === selected.length) {
                    this.bar_chx_all = true
                    this.indeterminatex = false

                }
                if (selected.length > 0 && barcodes.length > selected.length) {
                    this.bar_chx_all = false
                    this.indeterminatex = true

                }
                this.$store.commit("pricerujukan/update_selected_transaction", selected)

            },
            changeCbxAll(value) {
                var arr = this.xtransactions
                this.indeterminatex = false
                this.btn_hide = true
                arr.forEach((el) => {
                    el.chex = value
                })
                var selected = _.filter(arr, function (o) {
                    return o.chex;
                })
                this.$store.commit("pricerujukan/update_selected_transaction", selected)

            },
            fixedDiscount(value) {
                return +(parseFloat(value)).toFixed(2)
            },
            thr_filter: _.debounce(function () {
                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.xfilter,
                        price: this.xprice,
                        sdate: this.xstartdate,
                        edate: this.xenddate,
                        priority: this.xpriority,
                        current_page: 1,
                        lastid: -1
                })
            }, 1000)
        },
        watch: {
            xsearch(val, old) {
                console.log(val)
                this.xsearch = val
                this.thr_search()

            },
            xfilter(val, old) {
                if (val !== old && this.lookupstatus !== 1) {
                    console.log(val)
                    this.xfilter = val
                    this.thr_filter()
                }
            },
            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_rujukantypedup(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_rujukantypedup()
            },
            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_regionalform(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_regionalform()
            },
            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_testform(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_testform()
            },
            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>