<template>
    <div style="width: 100%;">

        <!-- SNACKBAR -->
        <v-snackbar v-model="snackbar" :timeout="5000" :multi-line="false" :vertical="false" :top="true">
            {{ msgSnackbar }}
            <v-btn flat @click="updateAlertSuccess(false)"> Tutup </v-btn>
        </v-snackbar>

        <!-- ERROR DIALOG -->
        <v-dialog v-model="dialog_error" max-width="500px">
            <v-card>
                <v-card-title>
                    <span>ERROR !</span>
                    <v-spacer></v-spacer>
                </v-card-title>
                <v-divider></v-divider>
                <div class="ma-3 red--text">{{ msgError }}</div>
                <v-divider></v-divider>
                <v-card-actions>
                    <v-spacer></v-spacer>
                    <v-btn color="primary" flat @click="dialog_error = false">Tutup</v-btn>
                </v-card-actions>
            </v-card>
        </v-dialog>
        <!-- END ERROR DIALOG -->

        <!-- table list start -->
        <v-toolbar color="primary" dark>
            <v-toolbar-title class="white--text">FA CLASS</v-toolbar-title>
            <v-spacer></v-spacer>
            <v-btn icon @click="openDialogAdd()">
                <v-icon>add_box</v-icon>
            </v-btn>
        </v-toolbar>
        <v-card class="pa-2">
            <v-layout row>
                <v-flex xs2 pl-2>
                    <v-text-field v-model="xsearch" label="Cari" outline hide-details></v-text-field>
                </v-flex>
                <v-flex pl-2>
                    <v-btn class="ml-2" dark color="primary" style="min-width: 50px; height: 50px; margin: 0;"
                        @click="searchCoa()">
                        <v-icon>search</v-icon>
                    </v-btn>
                </v-flex>
            </v-layout>
        </v-card>
        <v-card class="pa-2 mt-2">
            <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="xcoas" :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)">
                                <!-- <span class="font-weight-bold">
                                    {{ props.item.Nat_GroupCode }}
                                </span>
                                <br /> -->
                                {{ props.item.Fa_ClassName }}
                            </td>
                            <td class="text-xs-left pa-2" v-bind:class="{ 'amber lighten-4': isSelected(props.item) }"
                                @click="selectMe(props.item)">
                                <span class="font-weight-bold">
                                    {{ props.item.Fa_ClassCoaAccountNo }}
                                </span>
                                <br />
                                {{ props.item.Fa_ClassCoaDesc }}
                            </td>

                            <td class="text-xs-right pa-2" v-bind:class="{ 'amber lighten-4': isSelected(props.item) }"
                                @click="selectMe(props.item)">
                                <!-- <span class="font-weight-bold">
                                    {{ props.item.Nat_GroupCode }}
                                </span>
                                <br /> -->
                                {{ props.item.Fa_ClassDepreCorp }}
                            </td>
                            <td class="text-xs-left pa-2" v-bind:class="{ 'amber lighten-4': isSelected(props.item) }"
                                @click="selectMe(props.item)">
                                <span class="font-weight-bold">
                                    {{ props.item.Fa_ClassAccumDepreCoaAccountNo }}
                                </span>
                                <br />
                                {{ props.item.Fa_ClassAccumDepreCoaDesc }}
                            </td>
                            <td class="text-xs-left pa-2" v-bind:class="{ 'amber lighten-4': isSelected(props.item) }"
                                @click="selectMe(props.item)">
                                <!-- <span class="font-weight-bold">
                                    {{ props.item.Nat_GroupCode }}
                                </span>
                                <br /> -->
                                {{ props.item.Fa_ClassAccumNote }}
                            </td>
                            <td class="text-xs-right pa-2" v-bind:class="{ 'amber lighten-4': isSelected(props.item) }"
                                @click="selectMe(props.item)">
                                <v-tooltip bottom>
                                    <template v-slot:activator="{ on, attrs }">
                                        <v-icon v-bind="attrs" v-on="on" small
                                            @click="openDeleteCoa(props.item)">delete</v-icon>
                                    </template>
                                    <span>Hapus</span>
                                </v-tooltip>
                                <v-tooltip bottom>
                                    <template v-slot:activator="{ on, attrs }">
                                        <v-icon v-bind="attrs" v-on="on" small
                                            @click="openEditFormCoa(props.item)">edit</v-icon>
                                    </template>
                                    <span>Edit</span>
                                </v-tooltip>
                                <!-- <v-tooltip bottom>
                                    <template v-slot:activator="{ on, attrs }">
                                        <v-icon v-bind="attrs" v-on="on" color="red" small
                                            @click="doPrintVoucher(props.item)">picture_as_pdf</v-icon>
                                    </template>
                                    <span>Voucher</span>
                                </v-tooltip> -->
                            </td>
                        </template>
                    </v-data-table>
                </v-flex>
            </v-layout>
            <v-divider></v-divider>
            <v-pagination style="margin-top: 10px; margin-bottom: 10px;" v-model="curr_page"
                :length="xtotal_page"></v-pagination>
        </v-card>
        <!-- table list end -->

        <!-- add form dialog start -->
        <template>
            <v-layout row justify-center>
                <v-dialog v-model="dialog_add_coa" persistent max-width="550px">
                    <v-toolbar dark class="blue lighten-3 white--text">
                        <v-toolbar-title class="white--text">ADD FORM</v-toolbar-title>
                        <v-spacer></v-spacer>
                    </v-toolbar>
                    <v-card>
                        <v-card-text class="pt-4 pb-2">
                            <v-layout wrap>
                                <v-flex xs12>
                                    <!-- Class Name -->
                                    <v-text-field label="CLASS NAME" v-model="a_classname" hide-details
                                        outline></v-text-field>
                                    <!-- Ac coa -->
                                    <v-autocomplete class="mt-3" label="Acc Coa" :items="a_coa_list" v-model="a_coa"
                                        :search-input.sync="a_coa_search" hide-details auto-select-first no-filter
                                        item-text="coaDescription" outline return-object no-data-text="Pilih Acc Coa">
                                        <template slot="item" slot-scope="{ item }">
                                            <v-list-tile-content>
                                                <v-list-tile-title v-text="item.coaDescription"></v-list-tile-title>
                                                <v-list-tile-sub-title
                                                    v-text="item.coaAccountNo"></v-list-tile-sub-title>
                                            </v-list-tile-content>
                                        </template>
                                    </v-autocomplete>
                                    <!-- Ac coa -->
                                    <!-- depre corpd -->
                                    <v-text-field class="mt-3" label="DEPRE CORP" v-model="a_deprecorp" hide-details
                                        outline></v-text-field>
                                    <!-- Ac accum depre -->
                                    <v-autocomplete class="mt-3" label="Acc Accum Depre" :items="a_coa_accum_depre_list"
                                        v-model="a_coa_accum_depre" :search-input.sync="a_coa_search_accum_depre"
                                        hide-details auto-select-first no-filter item-text="coaDescription" outline
                                        return-object no-data-text="Pilih Acc Accum Depre">
                                        <template slot="item" slot-scope="{ item }">
                                            <v-list-tile-content>
                                                <v-list-tile-title v-text="item.coaDescription"></v-list-tile-title>
                                                <v-list-tile-sub-title
                                                    v-text="item.coaAccountNo"></v-list-tile-sub-title>
                                            </v-list-tile-content>
                                        </template>
                                    </v-autocomplete>
                                    <!-- Ac accum depre -->
                                    <!-- Accum Note -->
                                    <v-text-field class="mt-3" label="UMUR ASET (BULAN)" v-model="a_age" hide-details
                                        outline></v-text-field>
                                    <v-autocomplete class="mt-3" label="Accum Biaya Depre" :items="a_coa_depre_cost_list"
                                        v-model="a_coa_depre_cost" :search-input.sync="a_coa_search_depre_cost"
                                        hide-details auto-select-first no-filter item-text="coaDescription" outline
                                        return-object no-data-text="Pilih Acc Accum Depre">
                                        <template slot="item" slot-scope="{ item }">
                                            <v-list-tile-content>
                                                <v-list-tile-title v-text="item.coaDescription"></v-list-tile-title>
                                                <v-list-tile-sub-title
                                                    v-text="item.coaAccountNo"></v-list-tile-sub-title>
                                            </v-list-tile-content>
                                        </template>
                                    </v-autocomplete>
                                    <v-textarea class="mt-3" label="NOTE" v-model="a_note" hide-details rows="3"
                                        outline></v-textarea>
                                </v-flex>
                            </v-layout>
                        </v-card-text>
                        <v-card-actions class="pr-3">
                            <v-spacer></v-spacer>
                            <v-btn color="error" flat @click="closeDialogAddCoa()">TUTUP</v-btn>
                            <v-btn color="primary" @click="saveFormAdd()">SIMPAN</v-btn>
                        </v-card-actions>
                    </v-card>
                </v-dialog>
            </v-layout>
        </template>
        <!-- add form dialog end -->

        <!-- dialog delete start -->
        <template>
            <v-dialog v-model="dialogdeletealecoa" 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>
                                                {{ msgalertcoa }}
                                            </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="error" flat @click="dialogdeletealecoa = false">
                            Tutup
                        </v-btn>
                        <v-btn color="primary" @click="closeDeleteAlertCoa()">
                            Ya
                        </v-btn>
                    </v-card-actions>
                </v-card>
            </v-dialog>
        </template>
        <!-- dialog delete end -->

        <!-- edit form dialog start -->
        <template>
            <v-layout row justify-center>
                <v-dialog v-model="dialog_edit_coa" persistent max-width="550px">
                    <v-toolbar dark class="blue lighten-3 white--text">
                        <v-toolbar-title class="white--text">EDIT FORM</v-toolbar-title>
                        <v-spacer></v-spacer>
                    </v-toolbar>
                    <v-card>
                        <v-card-text class="pt-4 pb-2">
                            <v-layout wrap>
                                <v-flex xs12>
                                    <!-- Class Name -->
                                    <v-text-field label="CLASS NAME" v-model="e_classname" hide-details
                                        outline></v-text-field>
                                    <!-- Ac coa -->
                                    <v-autocomplete class="mt-3" label="Acc Coa" :items="e_coa_list" v-model="e_coa"
                                        :search-input.sync="e_coa_search" hide-details auto-select-first no-filter
                                        item-text="coaDescription" outline return-object no-data-text="Pilih Acc Coa">
                                        <template slot="item" slot-scope="{ item }">
                                            <v-list-tile-content>
                                                <v-list-tile-title v-text="item.coaDescription"></v-list-tile-title>
                                                <v-list-tile-sub-title
                                                    v-text="item.coaAccountNo"></v-list-tile-sub-title>
                                            </v-list-tile-content>
                                        </template>
                                    </v-autocomplete>
                                    <!-- Ac coa -->
                                    <!-- depre corpd -->
                                    <v-text-field class="mt-3" label="DEPRE CORP" v-model="e_deprecorp" hide-details
                                        outline></v-text-field>
                                    <!-- Ac accum depre -->
                                    <v-autocomplete class="mt-3" label="Acc Accum Depre" :items="e_coa_accum_depre_list"
                                        v-model="e_coa_accum_depre" :search-input.sync="e_coa_search_accum_depre"
                                        hide-details auto-select-first no-filter item-text="coaDescription" outline
                                        return-object no-data-text="Pilih Acc Accum Depre">
                                        <template slot="item" slot-scope="{ item }">
                                            <v-list-tile-content>
                                                <v-list-tile-title v-text="item.coaDescription"></v-list-tile-title>
                                                <v-list-tile-sub-title
                                                    v-text="item.coaAccountNo"></v-list-tile-sub-title>
                                            </v-list-tile-content>
                                        </template>
                                    </v-autocomplete>
                                    <!-- Ac accum depre -->
                                    <!-- Accum Note -->
                                    <v-text-field class="mt-3" label="UMUR ASET (BULAN)" v-model="e_age" hide-details
                                        outline></v-text-field>
                                    <v-autocomplete class="mt-3" label="Accum Biaya Depre" :items="e_coa_depre_cost_list"
                                        v-model="e_coa_depre_cost" :search-input.sync="e_coa_search_depre_cost"
                                        hide-details auto-select-first no-filter item-text="coaDescription" outline
                                        return-object no-data-text="Pilih Acc Accum Depre">
                                        <template slot="item" slot-scope="{ item }">
                                            <v-list-tile-content>
                                                <v-list-tile-title v-text="item.coaDescription"></v-list-tile-title>
                                                <v-list-tile-sub-title
                                                    v-text="item.coaAccountNo"></v-list-tile-sub-title>
                                            </v-list-tile-content>
                                        </template>
                                    </v-autocomplete>
                                    <v-textarea class="mt-3" label="NOTE" v-model="e_note" hide-details rows="3"
                                        outline></v-textarea>
                                </v-flex>
                            </v-layout>
                        </v-card-text>
                        <v-card-actions class="pr-3">
                            <v-spacer></v-spacer>
                            <v-btn color="error" flat @click="closeDialogEditCoa()">TUTUP</v-btn>
                            <v-btn color="primary" @click="saveFormEdit()">SIMPAN</v-btn>
                        </v-card-actions>
                    </v-card>
                </v-dialog>
            </v-layout>
        </template>
        <!-- edit form dialog end -->

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

<style scoped>
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;
}

.scroll-container {
    scroll-padding: 50px 0 0 50px;
}
</style>

<script>
module.exports = {
    components: {
        "one-dialog-info": httpVueLoader("../../common/oneDialogInfo.vue"),
        "one-dialog-alert": httpVueLoader("../../common/oneDialogAlert.vue"),
        "one-dialog-error": httpVueLoader("../../common/oneDialogError.vue"),
        "one-dialog-print": httpVueLoader("../../common/oneDialogPrintX.vue"),
    },
    data() {
        return {
            formatreport: "pdf",
            urlprint: "",
            printtitle: "",
            printwidth: "100%",
            page: 1,
            Fa_ClassID: 0,
            Fa_ClassName: "",
            headers: [
                {
                    text: "CLASS NAME",
                    align: "center",
                    sortable: false,
                    value: "date",
                    width: "10%",
                    class: "blue lighten-3 white--text",
                },
                {
                    text: "ACC COA",
                    align: "center",
                    sortable: false,
                    value: "jurnal",
                    width: "20%",
                    class: "blue lighten-3 white--text",
                },
                {
                    text: "DEPRE CORP",
                    align: "right",
                    sortable: false,
                    value: "location",
                    width: "10%",
                    class: "blue lighten-3 white--text",
                },
                {
                    text: "ACC DEPRE ACCUM",
                    align: "center",
                    sortable: false,
                    value: "info",
                    width: "20%",
                    class: "blue lighten-3 white--text",
                },
                {
                    text: "NOTE",
                    align: "left",
                    sortable: false,
                    value: "info",
                    width: "20%",
                    class: "blue lighten-3 white--text",
                },
                {
                    text: "AKSI",
                    align: "center",
                    sortable: false,
                    value: "status",
                    width: "5%",
                    class: "blue lighten-3 white--text",
                },
            ],
            dialogdeletealecoa: false,
            msgalertcoa: "",

            e_coa_search: '',
            e_coa_search_accum_depre: '',
            e_coa_search_depre_cost: ''
        }
    },
    mounted() {
        this.$store.dispatch("faclass/search", {
            current_page: this.$store.state.faclass.a_current_page,
            search: this.$store.state.faclass.a_x_search,
            last_id: -1,
        });
    },
    computed: {
        opendialoginfo: {
            get() {
                return this.$store.state.faclass.a_open_dialog_info;
            },
            set(val) {
                this.$store.commit("faclass/update_a_open_dialog_info", false);
            },
        },
        msginfo: {
            get() {
                return this.$store.state.faclass.a_msg_info;
            },
            set(val) {
                this.$store.commit("faclass/update_a_msg_info", false);
            },
        },
        snackbar: {
            get() {
                return this.$store.state.faclass.a_alert_success;
            },
            set(val) {
                this.$store.commit("faclass/update_a_alert_success", val);
            },
        },
        msgSnackbar() {
            return this.$store.state.faclass.a_msg_success;
        },
        dialog_error: {
            get() {
                return this.$store.state.faclass.a_alert_error;
            },
            set(val) {
                this.$store.commit("faclass/update_a_alert_error", val);
            },
        },
        msgError() {
            return this.$store.state.faclass.a_save_error_message;
        },
        // search table start
        xcoas() {
            return this.$store.state.faclass.a_coas;
        },
        isLoading() {
            return this.$store.state.faclass.a_search_status === 1;
        },
        xsearch: {
            get() {
                return this.$store.state.faclass.a_x_search;
            },
            set(val) {
                this.$store.commit("faclass/update_a_x_search", val);
            },
        },
        curr_page: {
            get() {
                return this.$store.state.faclass.a_current_page;
            },
            set(val) {
                this.$store.commit("faclass/update_a_current_page", val);
                this.$store.commit("faclass/update_a_last_id", -1);
                this.searchCoa();
            },
        },
        xtotal_page: {
            get() {
                return this.$store.state.faclass.a_total_coa;
            },
            set(val) {
                this.$store.commit("faclass/update_a_total_coa", val);
            },
        },
        // search table end

        // dialog add
        dialog_add_coa: {
            get() {
                return this.$store.state.faclass.dialog_add_coa;
            },
            set(val) {
                this.$store.commit("faclass/update_dialog_add_coa", val);
            },
        },

        dialog_edit_coa: {
            get() {
                return this.$store.state.faclass.dialog_edit_coa;
            },
            set(val) {
                this.$store.commit("faclass/update_dialog_edit_coa", val);
            },
        },

        // text classname
        a_classname: {
            get() {
                return this.$store.state.faclass.a_classname;
            },
            set(val) {
                this.$store.commit("faclass/update_a_classname", val);
            },
        },

        e_classname: {
            get() {
                return this.$store.state.faclass.e_classname;
            },
            set(val) {
                this.$store.commit("faclass/update_e_classname", val);
            },
        },

        // ac coa start
        a_coa_list() {
            return this.$store.state.faclass.a_coa_list;
        },
        a_coa: {
            get() {
                return this.$store.state.faclass.a_coa;
            },
            set(val) {
                this.$store.commit("faclass/update_a_coa", val);
            },
        },
        a_loading_coa: {
            get() {
                return this.$store.state.faclass.a_loading_coa;
            },
            set(val) {
                this.$store.commit("faclass/update_a_loading_coa", val);
            },
        },
        a_coa_search: {
            get() {
                return this.$store.state.faclass.a_coa_search
            },

            set(val) {
                this.$store.commit("faclass/update_a_coa_search", val);
                this.aSearchAcCoa(val)
            }
        },

        e_coa_list() {
            return this.$store.state.faclass.e_coa_list;
        },
        e_coa: {
            get() {
                return this.$store.state.faclass.e_coa;
            },
            set(val) {
                this.$store.commit("faclass/update_e_coa", val);
            },
        },
        e_loading_coa: {
            get() {
                return this.$store.state.faclass.e_loading_coa;
            },
            set(val) {
                this.$store.commit("faclass/update_e_loading_coa", val);
            },
        },
        // text accum depre
        a_deprecorp: {
            get() {
                return this.$store.state.faclass.a_deprecorp;
            },
            set(val) {
                this.$store.commit("faclass/update_a_deprecorp", val);
            },
        },
        a_age: {
            get() {
                return this.$store.state.faclass.a_age;
            },
            set(val) {
                this.$store.commit("faclass/update_a_age", val);
            },
        },
        e_age: {
            get() {
                return this.$store.state.faclass.e_age;
            },
            set(val) {
                this.$store.commit("faclass/update_e_age", val);
            },
        },
        e_deprecorp: {
            get() {
                return this.$store.state.faclass.e_deprecorp;
            },
            set(val) {
                this.$store.commit("faclass/update_e_deprecorp", val);
            },
        },

        // ac coa accum depre
        a_coa_accum_depre_list() {
            return this.$store.state.faclass.a_coa_accum_depre_list;
        },
        a_coa_accum_depre: {
            get() {
                return this.$store.state.faclass.a_coa_accum_depre;
            },
            set(val) {
                this.$store.commit("faclass/update_a_coa_accum_depre", val);
            },
        },
        a_loading_coa_accum_depre: {
            get() {
                return this.$store.state.faclass.a_loading_coa_accum_depre;
            },
            set(val) {
                this.$store.commit("faclass/update_a_loading_coa_accum_depre", val);
            },
        },
        a_coa_search_accum_depre: {
            get() {
                return this.$store.state.faclass.a_coa_search_accum_depre
            },

            set(val) {
                this.$store.commit("faclass/update_a_coa_search_accum_depre", val);
                this.aSearchAcCoaAccumDepre(val)
            }
        },
        a_coa_depre_cost_list() {
            return this.$store.state.faclass.a_coa_depre_cost_list;
        },
        a_coa_depre_cost: {
            get() {
                return this.$store.state.faclass.a_coa_depre_cost;
            },
            set(val) {
                this.$store.commit("faclass/update_a_coa_depre_cost", val);
            },
        },
        a_loading_coa_depre_cost: {
            get() {
                return this.$store.state.faclass.a_loading_coa_depre_cost;
            },
            set(val) {
                this.$store.commit("faclass/update_a_loading_coa_depre_cost", val);
            },
        },
        a_coa_search_depre_cost: {
            get() {
                return this.$store.state.faclass.a_coa_search_depre_cost
            },

            set(val) {
                this.$store.commit("faclass/update_a_coa_search_depre_cost", val);
                this.aSearchAcCoaDepreCost(val)
            }
        },
        e_coa_depre_cost_list() {
            return this.$store.state.faclass.e_coa_depre_cost_list;
        },
        e_coa_depre_cost: {
            get() {
                return this.$store.state.faclass.e_coa_depre_cost;
            },
            set(val) {
                this.$store.commit("faclass/update_e_coa_depre_cost", val);
            },
        },
        e_loading_coa_depre_cost: {
            get() {
                return this.$store.state.faclass.e_loading_coa_depre_cost;
            },
            set(val) {
                this.$store.commit("faclass/update_e_loading_coa_depre_cost", val);
            },
        },
        e_coa_search_depre_cost: {
            get() {
                return this.$store.state.faclass.e_coa_search_depre_cost
            },

            set(val) {
                this.$store.commit("faclass/update_e_coa_search_depre_cost", val);
                this.eSearchAcCoaDepreCost(val)
            }
        },
        e_coa_accum_depre_list() {
            return this.$store.state.faclass.e_coa_accum_depre_list;
        },
        e_coa_accum_depre: {
            get() {
                return this.$store.state.faclass.e_coa_accum_depre;
            },
            set(val) {
                this.$store.commit("faclass/update_e_coa_accum_depre", val);
            },
        },
        e_loading_coa_accum_depre: {
            get() {
                return this.$store.state.faclass.e_loading_coa_accum_depre;
            },
            set(val) {
                this.$store.commit("faclass/update_e_loading_coa_accum_depre", val);
            },
        },
        e_coa_depre_cost_list() {
            return this.$store.state.faclass.e_coa_depre_cost_list;
        },
        e_coa_depre_cost: {
            get() {
                return this.$store.state.faclass.e_coa_depre_cost;
            },
            set(val) {
                this.$store.commit("faclass/update_e_coa_depre_cost", val);
            },
        },
        e_loading_coa_depre_cost: {
            get() {
                return this.$store.state.faclass.e_loading_coa_depre_cost;
            },
            set(val) {
                this.$store.commit("faclass/update_e_loading_coa_depre_cost", val);
            },
        },
        // text note
        a_note: {
            get() {
                return this.$store.state.faclass.a_note;
            },
            set(val) {
                this.$store.commit("faclass/update_a_note", val);
            },
        },

        e_note: {
            get() {
                return this.$store.state.faclass.e_note;
            },
            set(val) {
                this.$store.commit("faclass/update_e_note", val);
            },
        },
    },
    methods: {
        searchCoa() {
            this.$store.dispatch("faclass/search", {
                current_page: this.$store.state.faclass.a_current_page,
                search: this.$store.state.faclass.a_x_search,
                last_id: -1,
            });
        },
        isSelected(p) {
            return p.Fa_ClassID == this.$store.state.faclass.a_selected_a_coa.Fa_ClassID;
        },
        selectMe(sc) {
            this.$store.commit("faclass/update_a_selected_a_coa", sc);
        },
        closeDialogAddCoa() {
            this.$store.commit("faclass/update_dialog_add_coa", false);
            this.$store.commit("faclass/update_a_classname", "");
            this.$store.commit("faclass/update_a_coa", {});
            this.$store.commit("faclass/update_a_deprecorp", "");
            this.$store.commit("faclass/update_a_age", "");
            this.$store.commit("faclass/update_a_coa_accum_depre", {});
            this.$store.commit("faclass/update_a_coa_depre_cost", {});
            this.$store.commit("faclass/update_a_note", "");
        },
        async aSearchAcCoa(query) {
            if (!query) return;
            this.a_loading_coa = true;
            await this.$store.dispatch("faclass/open_add_coa", { search: query });
            this.a_loading_coa = false;
        },
        async eSearchAcCoa(query) {
            if (!query) return;
            this.e_loading_coa = true;
            await this.$store.dispatch("faclass/open_edit_coa", { search: query });
            this.e_loading_coa = false;
        },
        async aSearchAcCoaAccumDepre(query) {
            if (!query) return;
            this.a_loading_coa_accum_depre = true;
            await this.$store.dispatch("faclass/open_add_coa_accum_depre", { search: query });
            this.a_loading_coa_accum_depre = false;
        },
        async eSearchAcCoaAccumDepre(query) {
            if (!query) return;
            this.e_loading_coa_accum_depre = true;
            await this.$store.dispatch("faclass/open_edit_coa_accum_depre", { search: query });
            this.e_loading_coa_accum_depre = false;
        },
        async aSearchAcCoaDepreCost(query) {
            if (!query) return;
            this.a_loading_coa_depre_cost = true;
            await this.$store.dispatch("faclass/open_add_coa_depre_cost", { search: query });
            this.a_loading_coa_depre_cost = false;
        },
        async eSearchAcCoaDepreCost(query) {
            if (!query) return;
            this.e_loading_coa_depre_cost = true;
            await this.$store.dispatch("faclass/open_edit_coa_depre_cost", { search: query });
            this.e_loading_coa_depre_cost = false;
        },
        // add data
        openDialogAdd() {
            this.$store.commit("faclass/update_dialog_add_coa", true);
        },
        saveFormAdd() {
            var paramAdd = {
                a_classname_param: this.a_classname,
                a_coa_param: this.a_coa,
                a_deprecorp_param: this.a_deprecorp,
                a_age_param: this.a_age,
                a_coa_accum_depre_param: this.a_coa_accum_depre,
                a_coa_depre_cost_param: this.a_coa_depre_cost,
                a_note_param: this.a_note,
            };

            console.log('param add', paramAdd);

            this.$store.dispatch("faclass/add_data", paramAdd);
        },
        // edit
        closeDialogEditCoa() {
            this.e_coa_search = ""
            this.e_coa_search_accum_depre = ""
            this.e_coa_search_depre_cost = ""

            this.$store.commit("faclass/update_dialog_edit_coa", false);
            this.$store.commit("faclass/update_e_classname", "");
            this.$store.commit("faclass/update_e_coa", {});
            this.$store.commit("faclass/update_e_deprecorp", "");
            this.$store.commit("faclass/update_e_coa_accum_depre", {});
            this.$store.commit("faclass/update_e_coa_depre_cost", {});
            this.$store.commit("faclass/update_e_note", "");
            this.$store.commit("faclass/update_e_age", "");
        },
        saveFormEdit() {
            var paramEdit = {
                Fa_ClassID: this.$store.state.faclass.Fa_ClassID,
                e_classname_param: this.e_classname,
                e_coa_param: this.e_coa,
                e_deprecorp_param: this.e_deprecorp,
                e_coa_accum_depre_param: this.e_coa_accum_depre,
                e_coa_depre_cost_param: this.e_coa_depre_cost,
                e_note_param: this.e_note,
                e_age_param: this.e_age
            };

            console.log('paramEdit', paramEdit);

            this.$store.dispatch("faclass/edit_data", paramEdit);

        },
        // delete data
        openDeleteCoa(val) {
            console.log(val);
            this.Fa_ClassID = val.Fa_ClassID;
            this.Fa_ClassName = val.Fa_ClassName;

            this.msgalertcoa =
                "Yakin, mau hapus data [" +
                val.Fa_ClassName +
                "] ?";
            this.dialogdeletealecoa = true;
        },
        closeDeleteAlertCoa() {
            let prm = {
                Fa_ClassID: this.Fa_ClassID,
                Fa_ClassName: this.Fa_ClassName,
                current_page: this.$store.state.faclass.a_current_page,
                search: this.$store.state.faclass.a_x_search,
                last_id: -1,
            };
            this.dialogdeletealecoa = false;
            this.$store.dispatch("faclass/delete_data", prm);
        },
        // edit data
        openEditFormCoa(val) {
            this.$store.dispatch("faclass/get_by_id", val);
        },
    },
    watch: {
        e_coa_search(val) {
            this.eSearchAcCoa(val)
        },
        e_coa_search_accum_depre(val) {
            this.eSearchAcCoaAccumDepre(val)
        },
        e_coa_search_depre_cost(val) {
            this.eSearchAcCoaDepreCost(val)
        },
    },
};
</script>
