<template>
    <v-layout>
        <v-flex xs12>
            <v-card>
                <v-toolbar color="blue lighten-3" dark height="50px">
                    <v-toolbar-title>DAFTAR RUJUKAN</v-toolbar-title>
                    <v-spacer></v-spacer>
                </v-toolbar>
                <v-snackbar v-model="snackbar" :timeout="5000" :multi-line="false" :vertical="false" :top="true">
                    {{msgsnackbar}}
                    <v-btn flat @click="updateAlert_success(false)">
                        Tutup
                    </v-btn>
                </v-snackbar>
                <v-layout row style="background:#bbdefb;padding-top:3px;">
                <v-flex xs6 class="text-sm-left" pa-2>
                <v-list-tile>
                        <one-date-picker label="Tanggal" :date="init_date" @change="searchDeliveryOrder" :data="null" :max_date="null" class="mr-4"></one-date-picker>                     
                </v-list-tile-content>
                    </v-list-tile>
                </v-flex>
                <v-flex xs6 class="text-sm-left" pa-2>
                       <v-list-tile>
                        <input type="text" v-model="xsearch" class="textinput" label="Nama Station" placeholder="Cari ..." />
                        </v-list-tile-content>
                    </v-list-tile>
                    </v-flex>
                </v-layout>
                <v-divider></v-divider>
                <div>

                    <v-layout row 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="vdeliveryorders" :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)">{{ props.item.M_BranchName}}</td>
                                    <td class="text-xs-left pa-2" v-bind:class="{'amber lighten-4':isSelected(props.item)}" @click="selectMe(props.item)">{{ props.item.incomingRefT_RefDeliveryOrderNumber}}</td>
                                    <td class="text-xs-left pa-2" v-bind:class="{'amber lighten-4':isSelected(props.item)}" @click="selectMe(props.item)">{{ props.item.incomingRefT_RefDeliveryOrderDatex}}</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> -->
                </div>


            </v-card>
        </v-flex>
    </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 = {
        data() {
            return {
                msgalertconfirmation: "Perubahan yang telah dilakukan belum disimpan dong !",
                dialogdeletealert: false,
                msgalert: "",
                valid: false,
                xid: 0,
                search_courier: "",
                items: [],
                xname: "",
                xcode: "",
                name: "",
                isdefault: false,
                xdestination: "",
                xup: "",
                xaddress: "",
                scode: "",                
                page: 1,
                headers: [{
                        text: "CABANG ASAL",
                        align: "left",
                        sortable: false,
                        value: "mr",
                        width: "30%",
                        class: "pa-2 blue lighten-3 white--text"
                    },
                    {
                        text: "NO. SURAT JALAN",
                        align: "left",
                        sortable: false,
                        value: "mr",
                        width: "30%",
                        class: "pa-2 blue lighten-3 white--text"
                    },
                    {
                        text: "TANGGAL",
                        align: "left",
                        sortable: false,
                        value: "mr",
                        width: "30%",
                        class: "pa-2 blue lighten-3 white--text"
                    }
                ],
                pagination: {
                    descending: true,
                    page: 1,
                    rowsPerPage: 100,
                    sortBy: 'id DESC',
                    totalItems: this.$store.state.deliveryorder.total_filter_deliveryorders
                }
            };
        },
        components: {
            'one-date-picker': httpVueLoader('./oneDatePicker2.vue')
        },
        async mounted() {
            await this.$store.dispatch("deliveryorder/lookup", {
                deliveryorder: this.init_date,
                search: this.xsearch,
                current_page: 1,
                lastid: -1
            })
            /*
            this.$store.dispatch("deliveryorderdetail/lookup", {
                current_page: 1,
             id: this.$store.state.deliveryorder.selected_deliveryorder.id
            })
            this.$store.dispatch("deliveryorder/searchsample", this.search_sample)
            */
        },
        computed: {
            xact() {
                return this.$store.state.deliveryorder.act
            },
            xerrors() {
                return this.$store.state.deliveryorder.errors
            },
            xshowall() {
                return this.$store.state.deliveryorder.show_all
            },
            vdeliveryorders() {
                return this.$store.state.deliveryorder.deliveryorders
            },
            xtotaldeliveryorders() {
                return this.$store.state.deliveryorder.total_deliveryorders
            },
            xtotalfilterdeliveryorders() {
                return this.$store.state.deliveryorder.total_filter_deliveryorders
            },
            init_date: {
                get() {
                    return this.$store.state.deliveryorder.init_date
                },
                set(val) {
                    this.$store.commit("deliveryorder/update_init_date", val)
                }
            },
            xsearch: {
                get() {
                    return this.$store.state.deliveryorder.x_search
                },
                set(val) {
                    this.$store.commit("deliveryorder/update_x_search", val)
                }
            },
            curr_page: {
                get() {
                    return this.$store.state.deliveryorder.current_page
                },
                set(val) {
                    this.$store.commit("deliveryorder/update_current_page", val)
                    this.$store.dispatch("deliveryorder/lookup", {
                        deliveryorder: this.init_date,
                        search: this.xsearch,
                        current_page: val,
                        lastid: -1
                    })
                }
            },
            xtotal_page: {
                get() {
                    return this.$store.state.deliveryorder.total_deliveryorders
                },
                set(val) {
                    this.$store.commit("deliveryorder/update_total_deliveryorders", val)
                }
            },
            dialogdeliveryorder() {
                return this.$store.state.deliveryorder.dialog_form_deliveryorder
            },
            snackbar: {
                get() {
                    return this.$store.state.deliveryorder.alert_success
                },
                set(val) {
                    this.$store.commit("deliveryorder/update_alert_success", val)
                }
            },
            msgsnackbar() {
                return this.$store.state.deliveryorder.msg_success
            },
            lookupstatus() {
                return this.$store.state.deliveryorder.lookup_deliveryorder
            },
            xstartdate: {
                get() {
                    return this.$store.state.deliveryorder.startdate
                },
                set(val) {
                    this.$store.commit("deliveryorder/update_startdate", val)
                }
            },
            isexternal: {
                get() {
                    return this.$store.state.deliveryorder.isexternal
                },
                set(val) {
                    this.$store.commit("deliveryorder/update_isexternal", val)
                    this.$store.dispatch("deliveryorder/searchdestination",{
                    search: this.search_destination,
                    tipe: val === true ? 'External' : 'Internal'
                })
                }
            },
            xdeliveryordertypes() {
                return this.$store.state.deliveryorder.deliveryordertypes
            },
            xdeliveryordertype: {
                get() {
                    return this.$store.state.deliveryorder.deliveryordertype
                },
                set(val) {
                    this.$store.commit("deliveryorder/update_deliveryordertype", val)
                }

            },
            isLoading() {
                return this.$store.state.deliveryorder.loading
            },
        },
        methods: {
            updateShowAll(val) {
                this.$store.commit("deliveryorder/update_show_all", val)
                this.$store.dispatch("deliveryorder/lookup", {
                    deliveryorder: this.init_date,
                    search: this.xsearch,
                    current_page: 1,
                    lastid: -1
                })
            },
            searchDeliveryOrder(prm) {
                this.$store.dispatch("deliveryorder/lookup", {
                    deliveryorder: prm.new_date,
                    search: this.xsearch,
                    current_page: 1,
                    lastid: -1
                })
                this.init_date = prm.new_date
            },
            isSelected(p) {
                return p.id == this.$store.state.deliveryorder.selected_deliveryorder.id 
            },
            selectMe(sc) {
                this.$store.commit("deliveryorder/update_selected_deliveryorder", sc)
                this.$store.commit("deliveryorder/update_xcek", 0)
                this.$store.dispatch("sample/selected", {
                    id: this.$store.state.deliveryorder.selected_deliveryorder.id
                })
                this.$store.dispatch("deliveryorderdetail/lookup", {
                    current_page: 1,
                    id: this.$store.state.deliveryorder.selected_deliveryorder.id
                })
            },
            thr_search: _.debounce(function () {
                this.$store.dispatch("deliveryorder/lookup", {
                    deliveryorder: this.init_date,
                    search: this.xsearch,
                    current_page: 1,
                    lastid: -1
                })
            }, 1000)
        },
        watch: {xsearch(val, old) {
                console.log(val)
                this.xsearch = val
                this.thr_search()

            }
            
        }
    }
</script>
