<template>
    <v-layout v-if="xact !== 'new'" column>
        <v-dialog v-model="dialogconfirmationdeletepat" persistent max-width="290">
            <v-card>
                <v-card-title dark class="headline error pt-2 pb-2" primary-title style="color:white">
                    <h4 dark>Konfirmasi</h4>
                </v-card-title>
                <v-card-text>
                    {{ msgconfirmationdeletepat }}
                </v-card-text>
                <v-card-actions>
                    <v-spacer></v-spacer>
                    <v-btn small color="error darken-1 text-sm-left" flat @click="doDeletePat()">Hapus</v-btn>
                    <v-btn small color="primary darken-1 text-sm-right" flat
                        @click="dialogconfirmationdeletepat = false">Batal</v-btn>
                </v-card-actions>
            </v-card>
        </v-dialog>
        <v-dialog v-model="dialogconfirmationsend" persistent max-width="290">
            <v-card>
                <v-card-title dark class="headline success pt-2 pb-2" primary-title style="color:white">
                    <h4 dark>Konfirmasi</h4>
                </v-card-title>
                <v-card-text>
                    {{ msgconfirmationsend }}
                </v-card-text>
                <v-card-actions>
                    <v-spacer></v-spacer>
                    <v-btn small color="success darken-1 text-sm-left" flat @click="doOrderPatient()">Kirim</v-btn>
                    <v-btn small color="primary darken-1 text-sm-right" flat
                        @click="dialogconfirmationsend = false">Batal</v-btn>
                </v-card-actions>
            </v-card>
        </v-dialog>
        <v-dialog v-if="save_error_message !== ''" persistent max-width="290">
            <v-card>
                <v-card-title dark class="headline error pt-2 pb-2" primary-title style="color:white">
                    <h4 dark>Peringatan</h4>
                </v-card-title>
                <v-card-text>
                    {{ save_error_message }}
                </v-card-text>
                <v-card-actions>
                    <v-spacer></v-spacer>
                    <v-btn small color="primary darken-1 text-sm-right" flat
                        @click="save_error_message = ''">OK</v-btn>
                </v-card-actions>
            </v-card>
        </v-dialog>

        <v-card>
            <v-layout row>
                <v-flex xs12>
                    <v-subheader red--text text--lighten-1>
                        <p class="mb-0"> Daftar Pemeriksaan</p>
                        <v-flex text-md-right>
                            <v-btn v-if="unselectedAgreementDetailList.length != 0" :disabled="in_saving" color="blue" class="white--text ma-1"
                                @click="saveMouDetail()">
                                Simpan
                                <v-icon right dark>save_alt</v-icon>
                            </v-btn>
                        </v-flex>
                    </v-subheader>

                    <v-divider></v-divider>
                    <v-layout row>
                    </v-layout row>
                    <v-layout row>
                        <v-flex xs12 v-if="!is_having_detail">
                            <v-layout row>
                                <v-flex class="text-sm-left" xs4 pl-1 pr-1 pt-1 pb-1>
                                    <div class="pa-2" style="font-weight: bold; font-style: italic; color: chocolate;">
                                        Jumlah Pemeriksaan : {{ selectedAgreementDetailList.length }}
                                    </div>
                                </v-flex>
                                <v-flex class="text-sm-left" xs4 pl-1 pr-1 pt-1 pb-1>
                                </v-flex>
                                <v-flex xs4>
                                    <div class="text-tagihan text-xs-right"><kbd>{{ convertMoney(sum_total) }}</kbd>
                                    </div>
                                </v-flex>
                            </v-layout row>
                        </v-flex>
                    </v-layout row>
                    <v-layout row class="scroll-container" style="max-height:400px;max-width:900px;overflow: auto;">
                        <v-flex xs12 pl-2 pr-2 pt-2 pb-2>

                            <v-data-table v-model="selectedAgreementDetailList" :headers="headers" hide-actions
                                :items="agreementDetailListFilter" item-key="numberingx" select-all class="elevation-1">

                                <template v-slot:headers="props">
                                    <tr>
                                        <th v-if="no_tagihan === ''" class="pr-0 py-2 blue lighten-3 white--text"
                                            style="display: flex; align-content: center;">
                                            <v-checkbox color="success" :input-value="props.all"
                                                :indeterminate="props.indeterminate" primary hide-details
                                                @click.stop="selectedAll()"></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">
                                    <tr :active="props.selected" @click="props.selected = !props.selected">
                                        <td @click="selectMe(props.item)" v-if="no_tagihan === ''"
                                            v-bind:class="{ 'amber lighten-4': isSelected(props.item.numberingx) }">
                                            <v-checkbox :input-value="props.selected" primary hide-details></v-checkbox>
                                        </td>
                                        <td @click="selectMe(props.item)"
                                            v-bind:class="{ 'amber lighten-4': isSelected(props.item.numberingx) }">
                                            <span v-if="props.selected">{{ props.item.testname }}</span>
                                            <span v-if="!props.selected" style="text-decoration: line-through;">{{
        props.item.testname }}</span>
                                        </td>
                                        <td @click="selectMe(props.item)"
                                            v-bind:class="{ 'amber lighten-4': isSelected(props.item.numberingx) }">
                                            <span v-if="props.selected">{{ convertMoney(props.item.bruto) }}</span>
                                            <span v-if="!props.selected" style="text-decoration: line-through;">{{
        convertMoney(props.item.bruto)
    }}</span>
                                        </td>
                                        <td @click="selectMe(props.item)"
                                            v-bind:class="{ 'amber lighten-4': isSelected(props.item.numberingx) }">
                                            <span v-if="props.selected">{{ convertMoney(props.item.diskon) }}</span>
                                            <span v-if="!props.selected" style="text-decoration: line-through;">{{
        convertMoney(props.item.diskon)
    }}</span>
                                        </td>
                                        <td @click="selectMe(props.item)"
                                            v-bind:class="{ 'amber lighten-4': isSelected(props.item.numberingx) }">
                                            <span v-if="props.selected">{{ convertMoney(props.item.total) }}</span>
                                            <span v-if="!props.selected"
                                                style="text-decoration: line-through;">{{convertMoney(props.item.total)
                                                }}</span>
                                        </td>
                                    </tr>
                                </template>
                            </v-data-table>

                        </v-flex>
                    </v-layout>
                </v-flex>
            </v-layout>
        </v-card>
    </v-layout>
</template>
<style scoped>
.checkbox-wrapper {
    display: flex;
    align-items: flex-start;
    padding-left: 10px;
    padding-top: 10px;
    padding-bottom: 10px;
    padding-right: 10px;
}

.label-wrapper {
    display: flex;
    flex-direction: column;
    margin-left: 10px;
}

.data-right {
    margin-left: 10px;
}

.data-below {
    margin-left: 10px;
    margin-top: 5px;
    color: #800000;
}

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

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

.text-tagihan {
    text-align: left;
    font-size: 30px;
    font-family: open sans, tahoma, sans-serif;
}

.text-total {
    text-align: left;
    font-size: 15px;
    font-family: open sans, tahoma, sans-serif;
}
</style>

<script>
module.exports = {
    data: () => ({

        oldlabel: '',
        search_test: '',
        menufilterdatestart: false,
        menufilterdateend: false,
        headers: [{
            text: "PEMERIKSAAN",
            align: "left",
            sortable: false,
            value: "mr",
            width: "30%",
            class: "pa-1 blue lighten-3 white--text"
        },
        {
            text: "BRUTO",
            align: "left",
            sortable: false,
            value: "lab",
            width: "15%",
            class: "pa-1 blue lighten-3 white--text"
        },
        {
            text: "DISKON",
            align: "left",
            sortable: false,
            value: "lab",
            width: "15%",
            class: "pa-1 blue lighten-3 white--text"
        },
        {
            text: "TOTAL",
            align: "left",
            sortable: false,
            value: "lab",
            width: "15%",
            class: "pa-1 blue lighten-3 white--text"
        }
        ]
    }),
    computed: {
        sumtotal: {
            get() {
                return this.$store.state.receivereference.sumtotal
            },
            set(val) {
                this.$store.commit("receivereference/update_sumtotal", val)
            }
        },
        sum_total() {
            let tests = this.selectedAgreementDetailList
            console.log(tests)
            sum_total = 0
            tests.forEach(function (t, idx) {
                let total = parseInt(t.total)
                sum_total += total
            })

            return sum_total
        },
        no_tagihan: {
            get() {
                return this.$store.state.receivereference.no_tagihan
            },
            set(val) {
                this.$store.commit("receivereference/update_no_tagihan", val)
                console.log(val)
            }
        },
        ctotal: {
            get() {
                return this.$store.state.receivereference.ctotal
            },
            set(val) {
                this.$store.commit("receivereference/update_ctotal", val)
            }
        },
        bar_chx_all: {
            get() {
                return this.$store.state.receivereference.bar_chx_all
            },
            set(val) {
                this.$store.commit("receivereference/update_bar_chx_all", val)
            }
        },
        indeterminatex: {
            get() {
                return this.$store.state.receivereference.indeterminatex
            },
            set(val) {
                this.$store.commit("receivereference/update_indeterminatex", val)
            }
        },
        selectedAgreementDetailList: {
            get() {
                return this.$store.state.receivereference.selectedAgreementDetailList;
            },
            set(val) {
                console.log("change selectedAgreementDetailList");
                this.$store.commit("receivereference/update_selectedAgreementDetailList", val);
            },
        },
        unselectedAgreementDetailList: {
            get() {
                return this.$store.state.receivereference.unselectedAgreementDetailList;
            },
            set(val) {
                console.log("change unselectedAgreementDetailList");
                this.$store.commit("receivereference/update_unselectedAgreementDetailList", val);
            },
        },
        selectedAgreementDetail: {
            get() {
                return this.$store.state.receivereference.selectedAgreementDetail;
            },
            set(val) {
                this.$store.commit("receivereference/update_selectedAgreementDetail", val);
            },
        },
        unselectedAgreementDetail: {
            get() {
                return this.$store.state.receivereference.unselectedAgreementDetail;
            },
            set(val) {
                this.$store.commit("receivereference/update_unselectedAgreementDetail", val);
            },
        },
        dialogconfirmationdeletepat: {
            get() {
                return this.$store.state.receivereference.dialog_confirmation_delete_pat
            },
            set(val) {
                this.$store.commit("receivereference/update_dialog_confirmation_delete_pat", val)
            }
        },
        msgconfirmationdeletepat() {
            return this.$store.state.receivereference.msg_confirmation_delete_pat
        },
        dialogconfirmationsend: {
            get() {
                return this.$store.state.receivereference.dialog_confirmation_send
            },
            set(val) {
                this.$store.commit("receivereference/update_dialog_confirmation_send", val)
            }
        },
        msgconfirmationsend() {
            return this.$store.state.receivereference.msg_confirmation_send
        },
        xact() {
            return this.$store.state.receivereference.act
        },
        xactpat() {
            return this.$store.state.receivereference.act_pat
        },
        xactsend() {
            return this.$store.state.receivereference.act_send
        },

        dialogformpatient: {
            get() {
                return this.$store.state.receivereference.dialog_form_patient
            },
            set(val) {
                this.$store.commit("receivereference/update_dialog_form_patient", val)
            }
        },
        isLoading() {
            return this.$store.state.receivereference.search_status == 1
        },
        agreementDetailList: {
            get() {
                return this.$store.state.receivereference.agreementDetailList;
            },
            set(val) {
                console.log("change agreementDetailList");
                this.$store.commit("receivereference/update_agreementDetailList", val);
            },
        },
        agreementDetailListFilter: {
            get() {
                return this.$store.state.receivereference.agreementDetailListFilter;
            },
            set(val) {
                console.log("change agreementDetailListFilter");
                this.$store.commit("receivereference/update_agreementDetailListFilter", val);
            },
        },
        agreementDetailkeyword: {
            get() {
                return this.$store.state.receivereference.agreementDetailkeyword;
            },
            set(val) {
                this.$store.commit("receivereference/update_agreementDetailkeyword", val);
            },
        },
        filterComputedDateFormattedStart() {
            return this.formatDate(this.init_sdate)
        },
        filterComputedDateFormattedEnd() {
            return this.formatDate(this.init_edate)
        },
        xsearch: {
            get() {
                return this.$store.state.receivereference.xsearch
            },
            set(val) {
                this.$store.commit("receivereference/update_xsearch", val)
            }
        },
        init_sdate: {
            get() {
                return this.$store.state.receivereference.init_sdate
            },
            set(val) {
                this.$store.commit("receivereference/update_init_sdate", val)
            }
        },
        init_edate: {
            get() {
                return this.$store.state.receivereference.init_edate
            },
            set(val) {
                this.$store.commit("receivereference/update_init_edate", val)
            }
        },
        xnoref: {
            get() {
                return this.$store.state.receivereference.noref
            },
            set(val) {
                this.$store.commit("receivereference/update_noref", val)
            }
        },
        namapasien: {
            get() {
                return this.$store.state.receivereference.namapasien
            },
            set(val) {
                this.$store.commit("receivereference/update_nama_pasien", val)
            }
        },
        xdob: {
            get() {
                return this.$store.state.receivereference.dob
            },
            set(val) {
                this.$store.commit("receivereference/update_dob", val)
            }
        },
        xsexes() {
            return this.$store.state.receivereference.sexes
        },
        xsex: {
            get() {
                return this.$store.state.receivereference.selected_sex
            },
            set(val) {
                this.$store.commit("receivereference/update_selected_sex", val)
            }
        },
        xorderautotests() {
            return this.$store.state.receivereference.orderautotests
        },
        xorderautotest: {
            get() {
                return this.$store.state.receivereference.orderautotest
            },
            set(val) {
                this.$store.commit("receivereference/update_orderautotest", val)
            }
        },
        xordertests() {
            return this.$store.state.receivereference.ordertests
        },
        sub_total() {
            let tests = this.xordertests
            sub_total = 0
            tests.forEach(function (vpx, idx) {
                let total = parseInt(vpx.total)
                sub_total = sub_total + total
            })
            return sub_total
        },
        dp() {
            let mindp = this.$store.state.receivereference.selected_receivereference.M_MouMinDP
            let dp = mindp / 100 * this.sub_total
            return dp
        },
        isbill() {
            let isbill = this.$store.state.receivereference.selected_receivereference.M_MouIsBill
            return isbill
        },
        isagingonhold() {
            let isagingonhold = this.$store.state.receivereference.selected_receivereference.M_MouIsAgingOnHold
            return isagingonhold
        },
        agingonhold() {
            let agingonhold = this.$store.state.receivereference.selected_receivereference.M_MouIsAgingOnHoldNote
            return agingonhold
        },
        is_having_detail() {
            if (this.$store.state.receivereference.selected_receivereference.haveDetail == 'Y') return true
            return false
        },
        in_saving: {
            get() {
                return this.$store.state.receivereference.in_saving
            },
            set(val) {
                this.$store.commit("receivereference/update_in_saving", val)
            }
        },
        save_error_message: {
            get() {
                return this.$store.state.receivereference.save_error_message
            },
            set(val) {
                this.$store.commit("receivereference/update_save_error_message", val)
            }
        }
    },
    methods: {
        async save_patient() {
            let pat = this.$store.state.receivereference.selected_patient
            let billID = this.$store.state.receivereference.selected_receivereference.T_OrderHeaderID
            let prm = {
                token: window.one_token(),
                billID: billID,
                patients: pat
            }
            await this.$store.dispatch("receivereference/save_patient", prm)
        },
        selectMe(item) {
            this.selectedAgreementDetail = item;
            console.log('selectMe')
            console.log(item)


            console.log('unselectMe')
            let unselect = this.$store.state.receivereference.unselectedAgreementDetailList
            if (unselect == undefined) unselect = []
            let idx_exist_test = _.findIndex(unselect, function (o) { return o.numberingx == item.numberingx })
            console.log('idx_exist_test');
            console.log(idx_exist_test);
            if (idx_exist_test > -1) {
                unselect.splice(idx_exist_test, 1)
                console.log('hapus');
            }else{
                unselect.push(item);
                console.log('tambah');
            }
            

            /*     if (unselect.length) {
                     
                     unselect.forEach(function (p, idx) {
                         if (parseInt(p.numberingx) == parseInt(item.numberingx)) {
                             unselect.splice(p.numberingx, 1)
                             console.log('hapus')
                             // this.$store.commit("receivereference/update_unselectedAgreementDetailList", unselect)
                         } else {
                             unselect.push(item)
                             console.log('tambah')
                             // this.$store.commit("receivereference/update_unselectedAgreementDetailList", unselect)
                         }
                     });
     
     
                 } else {
                     unselect.push(item)
                     console.log('tambah baru')
                     //  this.$store.commit("receivereference/update_unselectedAgreementDetailList", unselect)
                 }
     
     */
            // this.$store.commit("receivereference/unselectedAgreementDetailList", unselect)

            console.log(this.unselectedAgreementDetailList)
        },
        isSelected(id) {
            if (this.selectedAgreementDetail.numberingx === id) {
                return true;
            } else {
                return false;
            }
        },
        selectedAll() {
            if (this.selectedAgreementDetailList.length) {
                this.selectedAgreementDetailList = [];

                let a = JSON.stringify(this.agreementDetailListFilter);
                let b = JSON.parse(a);
                const filter = b.filter(
                    (e) =>
                        e.T_OrderHeaderID == null
                );
                console.log(filter);
                //this.agreementDetailListFilter = filter;
                this.unselectedAgreementDetailList = filter.slice();


            }
            else {

                let a = JSON.stringify(this.agreementDetailListFilter);
                let b = JSON.parse(a);
                const filter = b.filter(
                    (e) =>
                        e.T_OrderHeaderID == null
                );
                console.log(filter);
                //this.agreementDetailListFilter = filter;
                this.selectedAgreementDetailList = filter.slice();

                this.unselectedAgreementDetailList = [];

            }
        },
        saveMouDetail() {
            console.log(this.unselectedAgreementDetailList);

             let billID = this.$store.state.receivereference.selected_receivereference.T_OrderHeaderID
             let CorporateName = this.$store.state.receivereference.selected_receivereference.T_OrderHeaderLabNumber
             let prm = {
                 token: window.one_token(),
                 billID: billID,
                 CorporateName: CorporateName,
                 data_delete: this.unselectedAgreementDetailList
             }

             console.log(prm);
 
            if (this.in_saving) return;
             this.in_saving = true;
             this.$store.dispatch(
                 "receivereference/save_patient", prm
             );
             
        },
        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')}`
        },
        convertMoney(money) {
            return one_money(money)
        },
        thr_search: _.debounce(function () {
            this.$store.dispatch("receivereference/getpatient", {
                id: this.$store.state.receivereference.selected_receivereference.T_OrderHeaderID,
                search: this.xsearch
            })
        }, 200),
        searchBillStart() {
            this.$store.dispatch("receivereference/getpatient", {
                id: this.$store.state.receivereference.selected_receivereference.T_OrderHeaderID,
                search: this.xsearch
            })
        },
        searchBillEnd() {
            this.$store.dispatch("receivereference/getpatient", {
                id: this.$store.state.receivereference.selected_receivereference.T_OrderHeaderID,
                search: this.xsearch
            })
        },
        async saveNewPatient() {
            if (this.in_saving) return;
            this.in_saving = true;
            this.$store.dispatch("receivereference/getpatientbeforesave", {
                id: this.$store.state.receivereference.selected_receivereference.T_OrderHeaderID,
                search: '',
                company: this.$store.state.receivereference.selected_receivereference.CorporateName
            })
            /*      
            let patients = this.$store.state.receivereference.patients
            let pat = _.filter(patients, function (it) {
                return it.checx == 'Y'
            })
            var prm = {}
            prm.billID = this.$store.state.receivereference.selected_receivereference.T_OrderHeaderID
            prm.CorporateName = this.$store.state.receivereference.selected_receivereference.CorporateName
            prm.patients = pat
            this.$store.dispatch("receivereference/savenewpatient", prm)
            */

        },
        changeCbxAllold(value) {
            var arr = this.agreementDetailListFilter
            this.indeterminatex = false
            arr.forEach((el) => {
                el.chex = value
            })
            var selected = _.filter(arr, function (o) {
                return o.chex;
            })
            this.$store.commit("receivereference/update_selected_patient", selected)

        },
        checkTopold(pat) {
            let patients = this.$store.state.receivereference.patients
            let idx = _.findIndex(patients, function (p) {
                return p.T_OrderHeaderID == pat.T_OrderHeaderID
            });
            patients[idx].checx = !patients[idx].chex
            var selected = _.filter(patients, function (o) {
                return o.chex;
            })

            console.log(selected)
            this.$store.commit("receivereference/update_selected_patient", selected)
        },
        changeCbxAlloldold(value) {

            var chx_all = value === false ? true : false
            this.$store.commit("receivereference/update_bar_chx_all", chx_all)

            if (this.in_saving) return;
            this.in_saving = true;
            let patients = this.$store.state.receivereference.patients
            let pat = _.filter(patients, function (it) {
                return it.isbill == 'N'
            })
            var prm = {}
            prm.billID = this.$store.state.receivereference.selected_receivereference.T_OrderHeaderID
            prm.status = value === false ? 'Y' : 'N'
            prm.patients = pat
            prm.isallmou = this.$store.state.receivereference.selected_receivereference.F_BillIsAllMou
            prm.mouID = this.$store.state.receivereference.selected_receivereference.F_BillM_MouID
            prm.startdate = this.init_sdate
            prm.enddate = this.init_edate
            prm.search = this.xsearch
            this.$store.dispatch("receivereference/saveall_tempbill", prm)


        },
        changeCbxAll() {
        },
        checkTop(pat) {
            pat.checx === 'N' ? 'Y' : 'N'
            this.selectedAgreementDetail = pat;
            /*  var newval = pat.checx === 'N' ? 'Y' : 'N'
              var prm = pat
              prm.checx = newval
              prm.billid = this.$store.state.receivereference.selected_receivereference.T_OrderHeaderID
              prm.isallmou = this.$store.state.receivereference.selected_receivereference.F_BillIsAllMou
              prm.mouid = pat.M_MouID
              prm.headerid = pat.T_OrderHeaderID
              prm.id = pat.Temp_BillID
              prm.total = pat.total
              prm.startdate = this.init_sdate
              prm.enddate = this.init_edate
              prm.search = this.xsearch
  
              this.$store.dispatch("receivereference/save_tempbill", prm)
              */
        },
        createNewPatient() {
            this.$store.commit("receivereference/update_act_pat", 'new')
            this.xnoref = ''
            this.namapasien = ''
            this.$store.commit("receivereference/update_selected_sex", [])
            this.xdob = ''
            this.$store.commit("receivereference/update_ordertests", [])
            this.$store.commit("receivereference/update_dialog_form_patient", true)
        },
        checkError(value) {
            var errors = this.$store.state.receivereference.errors
            if (errors.includes(value)) {
                return true
            } else {
                return false
            }
        },
        thr_search_test: _.debounce(function () {
            this.$store.dispatch("receivereference/searchtest", {
                tes: this.search_test,
                mouid: this.$store.state.receivereference.selected_receivereference.T_ReceiveReferenceHeaderM_MouID
            })
        }, 2000),
        doDeletePat() {
            var prm = {}
            prm.T_ReceiveReferencePatientT_ReceiveReferenceHeaderID = this.$store.state.receivereference.selected_receivereference
                .T_ReceiveReferenceHeaderID
            prm.T_ReceiveReferencePatientID = this.$store.state.receivereference.x_pat_id
            prm.T_ReceiveReferencePatientName = this.namapasien
            prm.CorporateName = this.$store.state.receivereference.selected_receivereference.CorporateName
            this.$store.dispatch("receivereference/deletepatient", prm)
        },
        sendOrderPatient(value) {
            let msg = "Yakin, akan mengirim permintaan nomor " + this.$store.state.receivereference.selected_receivereference
                .T_ReceiveReferenceHeaderNumber + " ?"
            this.$store.commit("receivereference/update_msg_confirmation_send", msg)
            this.$store.commit("receivereference/update_dialog_confirmation_send", true)
        },
        doOrderPatient() {
            var prm = {}
            prm.T_ReceiveReferenceHeaderID = this.$store.state.receivereference.selected_receivereference
                .T_ReceiveReferenceHeaderID
            prm.T_ReceiveReferenceHeaderNumber = this.$store.state.receivereference.selected_receivereference
                .T_ReceiveReferenceHeaderNumber
            this.$store.dispatch("receivereference/sendorder", prm)
        },
        convertMoney(money) {
            return one_money(money)
        },
        addTest() {
            var oldArr = this.$store.state.receivereference.ordertests
            oldArr.push(this.$store.state.receivereference.orderautotest)
            this.searchtest = ''
            this.$store.commit("receivereference/update_orderautotests", [])
            this.$store.commit("receivereference/update_orderautotest", {})
        },
        deleteDataPx(idx) {
            var inx = parseInt(idx);
            var xrow = this.$store.state.receivereference.ordertests[inx]
            if (parseInt(xrow.xid) !== 0) {
                var xdeltest = this.$store.state.receivereference.deleted_ordertests
                xdeltest.push(xrow)
                this.$store.commit("receivereference/update_deleted_ordertests", xdeltest)
            }
            var oldArr = this.$store.state.receivereference.ordertests
            oldArr.splice(inx, 1)
            this.$store.commit("receivereference/update_ordertests", oldArr)
        },
    },
    watch: {
        agreementDetailkeyword(val, old) {
            let a = JSON.stringify(this.agreementDetailList);
            let b = JSON.parse(a);
            const filter = b.filter(
                (e) =>
                    e.pasienname.toLowerCase().includes(val) ||
                    e.T_OrderHeaderLabNumber.includes(val)
            );
            console.log(filter);
            this.agreementDetailListFilter = filter;
        },
        init_sdate(val, old) {
            let a = JSON.stringify(this.agreementDetailList);
            let b = JSON.parse(a);
            let xdate = this.init_edate;
            const filter = b.filter(
                (e) =>
                    e.T_OrderHeaderDate >= val &&
                    e.T_OrderHeaderDate <= xdate
            );
            console.log(filter);
            this.agreementDetailListFilter = filter;
        },
        init_edate(val, old) {
            let a = JSON.stringify(this.agreementDetailList);
            let b = JSON.parse(a);
            let xdate = this.init_sdate;
            const filter = b.filter(
                (e) =>
                    e.T_OrderHeaderDate >= xdate &&
                    e.T_OrderHeaderDate <= val
            );
            console.log(filter);
            this.agreementDetailListFilter = filter;
        },
        agreementDetailListFilter(val, old) {
            console.log(val);
            // let tmp = this.agreementDetailList;
            // val.forEach((e) => {
            //   tmp.forEach((f) => {
            //     if (e.numberingx === f.numberingx) {
            //       f = e;
            //     }
            //   });
            // });
            // this.agreementDetailList = tmp;
        },
        xsearch(val, old) {
            console.log(val)
            this.xsearch = val
            this.thr_search()
        },
        search_city(val, old) {
            if (val == old) return
            if (!val) return
            if (val.length < 1) return
            if (this.$store.state.receivereference.update_autocomplete_status == 1) return
            this.thr_search_city()
        },
        search_test(val, old) {
            if (val == old) return
            if (!val) return
            if (val.length < 1) return
            if (this.$store.state.receivereference.update_autocomplete_status == 1) return
            this.thr_search_test()
        }
    }
}
</script>