<template>
    <v-dialog v-model="dialog_receive_aset" persistent width="70vw">
        <v-card>
            <v-card-title class="headline grey lighten-2">FORM TERIMA ASET</v-card-title>
            <v-card-text style="max-height: 80vh; overflow-y: auto;">
                <v-layout row wrap>
                    <v-flex xs4>
                        <v-menu offset-y lazy min-width="290px" transition="scale-transition" max-width="290px"
                            v-model="menuROdate" full-width :nudge-right="40" :close-on-content-click="false">
                            <template v-slot:activator="{ on }">
                                <v-text-field label="Tanggal RO" hide-details readonly v-on="on" outline
                                    v-model="formattedRODate"></v-text-field>
                            </template>
                            <v-date-picker no-title @input="menuROdate = false"
                                v-model="form_receive.date"></v-date-picker>
                        </v-menu>
                    </v-flex>
                    <v-flex xs4 pl-2>
                        <v-autocomplete :items="[]" hide-details outline label="Vendor" v-model="form_receive.supplier"
                            item-text="SupplierName" item-value="SupplierID" @input=""></v-autocomplete>
                    </v-flex>
                    <v-flex xs4 pl-2>
                        <v-text-field hide-details outline placeholder="Nomor Delivery / Supplier Invoice"
                            v-model="form_receive.reference" label="Referensi"></v-text-field>
                    </v-flex>
                </v-layout>

                <v-layout row wrap class="mt-2">
                    <v-flex xs2>
                        <v-text-field hide-details outline label="No PO" placeholder="nomor po"
                            v-model="form_receive.ponumber" readonly></v-text-field>
                    </v-flex>
                    <v-flex xs2 pl-2>
                        <v-text-field hide-details outline label="Total Tagihan" placeholder="0"
                            v-model="form_receive.totalbill" readonly></v-text-field>
                    </v-flex>
                    <v-flex xs2 pl-2>
                        <v-text-field hide-details outline label="Uang Muka" placeholder="0"
                            v-model="form_receive.downpayment" readonly></v-text-field>
                    </v-flex>
                    <v-flex xs2 pl-2>
                        <v-text-field hide-details outline label="Cicilan" placeholder="0"
                            v-model="form_receive.cicilan" readonly></v-text-field>
                    </v-flex>
                    <v-flex xs2 pl-2>
                        <v-text-field hide-details outline label="Lama Kontrak (bulan)" placeholder="0"
                            v-model="form_receive.contractlength" readonly></v-text-field>
                    </v-flex>
                    <v-flex xs2 pl-2>
                        <v-text-field hide-details outline label="Tanggal Bayar" placeholder="0"
                            v-model="form_receive.datepayment" readonly></v-text-field>
                    </v-flex>
                </v-layout>

                <v-layout row wrap class="mt-2">
                    <v-flex xs12>
                        <v-textarea auto-grow rows="1" outline label="Catatan" hide-details
                            v-model="form_receive.catatan"></v-textarea>
                    </v-flex>
                    <v-flex xs3 mt-2>
                        <!-- :disabled="form_receive.supplier == ''" -->
                         <v-btn block color="info" @click="pickKontrakAset()">
                            PILIH KONTRAK
                        </v-btn>
                    </v-flex>
                </v-layout>

                <v-layout row wrap class="mt-3">
                    <!-- <v-flex xs12 v-if="item_receive.length > 0"> -->
                    <v-flex xs12>
                        <v-data-table :headers="headers" :items="[]" class="elevation-1" hide-actions>
                            <template v-slot:items="props">
                                <tr>
                                    <td></td>
                                </tr>
                            </template>
                        </v-data-table>
                    </v-flex>
                </v-layout>
            </v-card-text>
            <v-card-actions>
                <v-spacer></v-spacer>
                <v-btn @click="dialog_receive_aset = false" color="error" class="white--text">Batal</v-btn>
                <v-btn color="primary" class="white--text">Simpan</v-btn>
            </v-card-actions>
        </v-card>
    </v-dialog>
</template>

<script>
module.exports = {
    data() {
        return {
            menuROdate: false,
            headers: [
                {
                    text: "ITEM", align: "center", sortable: false,
                    value: "nopo", width: "40%", class: "pa-1 blue lighten-3 white--text",
                },
                {
                    text: "QTY", align: "center", sortable: false,
                    value: "type", width: "10%", class: "pa-1 blue lighten-3 white--text",
                },
                {
                    text: "UNIT ITEM", align: "center", sortable: false,
                    value: "item", width: "15%", class: "pa-1 blue lighten-3 white--text",
                },
                {
                    text: "INSPEKSI", align: "center", sortable: false,
                    value: "inspec", width: "20%", class: "pa-1 blue lighten-3 white--text",
                },
                {
                    text: "AKSI", align: "center", sortable: false,
                    value: "act", width: "15%", class: "pa-1 blue lighten-3 white--text",
                },
            ]
        }
    },
    computed: {
        dialog_receive_aset: {
            get() {
                return this.$store.state.roasset.dialog_receive_aset
            },
            set(val) {
                this.$store.commit("roasset/update_dialog_receive_aset", val)
            }
        },
        form_receive: {
            get() {
                return this.$store.state.roasset.form_receive
            },
            set(val) {
                this.$store.commit("roasset/update_form_receive", val)
            }
        },
        item_receive: {
            get() {
                return this.$store.state.roasset.item_receive
            },
            set(val) {
                this.$store.commit("roasset/update_item_receive", val)
            }
        },
        formattedRODate() {
            return this.formatDate(this.form_receive.date)
        }
    },
    methods: {
        formatDate(date) {
            if (!date) return null;
            const [year, month, day] = date.split('-');
            return `${day}-${month}-${year}`;
        },
        pickKontrakAset() {
            this.$store.commit("roasset/update_dialog_pick_contract", true);
        }
    }
}
</script>
