﻿<template>
    <div class="container-fluid">
        <template>
            <v-btn @click.prevent='fast_signup'>快速報名</v-btn>
        </template>
        <v-data-table v-model="detail_table.selected"
                      :items="detail_table.list"
                      :search-props="search"
                      item-key="order_no"
                      :options.sync="options"
                      :headers="detail_table.header"
                      :footer-props="detail_table.footer"
                      :server-items-length="detail_table.count"
                      :loading="detail_table.loading"
                      :single-select="detail_table.singleSelect"
                      show-select
                      hide-default-footer
                      :page.sync="detail_table.page"
                      :items-per-page.sync="detail_table.pageSize"
                      class="elevation-1">
            <template #item.slot_btn="{ item }">
                <a :href="'reg.aspx?order_no='+item.order_no" class="btn btn-outline-secondary btn-sm"><i class="mdi mdi-pencil-box-outline"></i>修改</a>
                <a @click="$root.currentView='step-three';$root.selected_order=item.order_no" class="btn btn-outline-secondary btn-sm">明細</a>
                <a @click="deleteItem(item)" class="btn btn-outline-secondary btn-sm"><i class="mdi mdi-trash-can"></i>刪除</a>
            </template>
        </v-data-table>
        <v-container>
            <v-row class="align-baseline" wrap>
                <v-col cols="12" md="9">
                    <v-pagination v-model="detail_table.page"
                                  :length="pageCount">
                    </v-pagination>
                </v-col>
                <v-col class="text-truncate text-right" cols="12" md="2">
                    共 {{ detail_table.count }} 筆, 頁數:
                </v-col>
                <v-col cols="6" md="1">
                    <v-text-field v-model="detail_table.page"
                                  type="number"
                                  hide-details
                                  dense
                                  min="1"
                                  :max="pageCount"
                                  @input="detail_table.page = parseInt($event, 10)"></v-text-field>
                </v-col>
            </v-row>
        </v-container>
    </div>
</template>

<script>
    module.exports = {
        props: {
            num: {
                type: Number }
        },
        activated() {
            console.log("yes ,go go", this.num);
            this.getDetail();
        },

        mounted() {
            console.log("yes ,go go", this.num);
            this.getDetail();
        },
        data() {
            return {
                options: { multiSort: false },
                search_options: { multiSort: false },
                detail_table: {
                    loading: true,
                    list: [],
                    selected: [],
                    singleSelect: false,
                    count: 0,
                    page: 1,
                    pageSize: 10,
                    header: [
                        { text: '單號', value: 'order_no' },
                        { text: '姓名', value: 'u_name' },
                        { text: '報名日期', value: 'up_time' },
                        { text: '單據狀態', value: 'keyin1_txt', align: 'start' },
                        { text: '', value: 'slot_btn', sortable: false, align: 'end' }
                    ],
                    footer: {
                        showFirstLastPage: true,
                        itemsPerPageOptions: [5, 10, 20, 30],
                    },
                },
                search: {
                    keyin1: '',
                    order_no: '',
                    subject: '',
                    u_name: '',
                    up_time1: '',
                    up_time2: '',
                    actItemTxt: '',
                    introducerTxt: '',
                    activity_num: '',
                    country: '',
                    country2: '',
                    hasPrice: '',
                }
            };
        },
        watch: {
            options: {
                handler() {
                    this.getDetail()
                },
                deep: true,
            },

        },
        methods: {
            fast_signup() {
                this.$emit('custom-event', { action: 'add', item: null });
            },
            getDetail() {
                const { sortBy, sortDesc, page, itemsPerPage } = this.options
                const params = {
                    //sortBy: sortBy == undefined ? "order_no" : sortBy[0],
                    //sortDesc: sortDesc == undefined ? "" : sortDesc[0],
                    //page: clearpage ? '1' : page, pageSize: itemsPerPage,
                    page: '1', pageSize: 10,

                };
                this.search = { activity_num: this.num }
                this.detail_table.loading = true
                sessionStorage.setItem('orderpage', '1');// clearpage ? '1' : page
                axios
                    .post(HTTP_HOST + 'api/order/GetList', this.search, { params: params })
                    .then(response => {
                        this.detail_table.list = response.data.list
                        this.detail_table.count = response.data.count;
                        this.detail_table.loading = false
                    })
                    .catch(error => console.log(error))
            },
        },
        computed: {
            pageCount() {
                return Math.ceil(this.detail_table.count / this.detail_table.pageSize)
            },
        }
    }
</script>