<template>
    <v-dialog v-model="dialog_confirm" persistent width="40vw">
        <v-card>
            <v-card-title class="headline grey lighten-2">KONFIRMASI RECEIVE ORDER ASSET</v-card-title>
            <v-card-text>
                <v-layout row wrap>
                    <v-flex xs3 class="pr-2"><strong>Tanggal</strong></v-flex>
                    <v-flex xs9>: {{ selected_roasset.ReceiveOrderPoIDate }}</v-flex>

                    <v-flex xs3 class="pr-2"><strong>Nomor</strong></v-flex>
                    <v-flex xs9>: {{ selected_roasset.ReceiveOrderPoNumber }}</v-flex>

                    <v-flex xs3 class="pr-2"><strong>Nomor Referensi</strong></v-flex>
                    <v-flex xs9>: {{ selected_roasset.ReceiveOrderPoRefNumber }}</v-flex>

                    <v-flex xs3 class="pr-2"><strong>Supplier</strong></v-flex>
                    <v-flex xs9>: {{ selected_roasset.SupplierName }}</v-flex>

                    <v-flex xs3 class="pr-2"><strong>Catatan</strong></v-flex>
                    <v-flex xs9>: {{ selected_roasset.ReceiveOrderPoNote }}</v-flex>
                </v-layout>
            </v-card-text>
            <v-card-actions>
                <v-spacer></v-spacer>
                <v-btn @click="batal()" color="error" class="white--text">Batal</v-btn>
                <v-btn @click="confirmOrder()" color="primary" class="white--text">Konfirmasi</v-btn>
            </v-card-actions>
        </v-card>
    </v-dialog>
</template>


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

        }
    },
    computed: {
        dialog_confirm: {
            get() {
                return this.$store.state.roasset.dialog_confirm;
            },
            set(val) {
                this.$store.commit("roasset/update_dialog_confirm", val);
            }
        },
        selected_roasset: {
            get() {
                return this.$store.state.roasset.selected_roasset;
            },
            set(val) {
                this.$store.commit("roasset/update_selected_roasset", val);
            }
        },
        loading_process() {
            return this.$store.state.roasset.loading_process;
        },
        preview_attachment() {
            return this.$store.state.roasset.preview_attachment
        }
    },
    methods: {
        batal() {
            this.selected_roasset = {}
            this.dialog_confirm = false
        },
        confirmOrder() {
            if (this.preview_attachment.length < 1) {
                const msg = "Belum upload bukti terima";
                const snac = { color: 'error', msg: msg, state: false };
                this.$store.commit("roasset/update_snackbar", snac);
                return;
            }

            if (!this.loading_process) {
                const received = this.selected_roasset;
                this.$store.dispatch("roasset/confirmReceiveOrder", received.ReceiveOrderPoID);
            } else {
                const msg = "Masih terdapat proses lain yang berjalan";
                const snac = { color: 'error', msg: msg, state: false };
                this.$store.commit("roasset/update_snackbar", snac);
            }
        }
    },
    watch: {}
}
</script>
