<template>
    <div class="app-container">
        <div class="head-container">
            <div class="filter_wrap">
                <el-date-picker v-model="query.createdAt" type="daterange" range-separator="至" start-placeholder="开始日期"
                    end-placeholder="结束日期" value-format="yyyy-MM-dd" @change="getTableData">
                </el-date-picker>
                <el-button type="primary" @click="getTableData">查询</el-button>
                <el-button @click="resetHandle">重置</el-button>
            </div>
        </div>
        <div class="head-container">
            <el-table :data="tableData.list" v-loading="tableData.loading">
                <el-table-column label="类型" prop="type">
                    <template v-slot="scope">
                        {{ scope.row.type }}
                    </template>
                </el-table-column>
                <el-table-column label="供应商名称" prop="purveyorName"></el-table-column>
                <el-table-column label="商品数量" prop="totalAmount">
                    <template v-slot="scope">
                        {{ scope.row.stockSnap && scope.row.stockSnap.length }}
                    </template>
                </el-table-column>
                <el-table-column label="备注" prop="remark"></el-table-column>
                <el-table-column label="操作人" prop="status">
                    <template v-slot="scope">
                        {{ scope.row.operatorSnap.account }}
                    </template>
                </el-table-column>
                <el-table-column label="创建时间" prop="updatedAt">
                    <template v-slot="scope">
                        {{ dayjs(scope.row.stockTime).format('YYYY-MM-DD HH:mm:ss') }}
                    </template>
                </el-table-column>
                <el-table-column label="操作" width="80">
                    <template v-slot="scope">
                        <el-button type="text" size="mini" @click="$refs.operatingDetail.show(scope.row)">
                            详情
                        </el-button>
                        <!-- <el-button type="text" size="mini" @click="$refs.operatingDetail.show(scope.row.id)">
                            作废
                        </el-button> -->
                    </template>
                </el-table-column>
            </el-table>
        </div>
        <el-pagination :total="tableData.total" :current-page="tableData.page + 1" :page-size="tableData.size"
            @current-change="paginationChange"
            @size-change="e => { tableData.size = e; tableData.page = 0; getTableData() }"
            layout="total, sizes, prev, pager, next, jumper"></el-pagination>
        <operatingDetail ref="operatingDetail" />
    </div>
</template>

<script>
import dayjs from 'dayjs'
import { tbProductStockOperateList } from '@/api/invoicing'
import operatingDetail from './components/operatingDetail'
export default {
    components: {
        operatingDetail
    },
    data() {
        return {
            dayjs,
            query: {
                createdAt: []
            },
            tableData: {
                page: 0,
                size: 10,
                total: 0,
                sort: 'id',
                loading: false,
                list: []
            }
        }
    },
    mounted() {
        this.getTableData()
    },
    methods: {
        async getTableData() {
            this.tableData.loading = true
            let arr = []
            console.log(this.query, 'tiaoshi1')
            if (this.query.createdAt.length) {
                arr = [this.query.createdAt[0] + ' 00:00:00', this.query.createdAt[1] + ' 23:59:59']
            } else {
                arr = []
            }
            try {
                const res = await tbProductStockOperateList({
                    page: this.tableData.page,
                    size: this.tableData.size,
                    shopId: localStorage.getItem('shopId'),
                    createdAt: arr
                })
                this.tableData.loading = false
                this.tableData.list = res.content
                this.tableData.total = res.totalElements
            } catch (error) {
                console.log(error);
            }
        },
        // 重置查询
        resetHandle() {
            this.query.createdAt = []
            this.tableData.page = 0;
            this.getTableData()
        },
        // 分页回调
        paginationChange(e) {
            this.tableData.page = e - 1
            this.getTableData()
        }
    }
}
</script>
<style lang="scss" scoped>
.box {
    width: 100%;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0px 90px 20px 90px;

    .boxitem {
        display: flex;
        justify-content: center;
        align-items: center;
        padding: 10px 24px;
        background: rgba(244, 249, 255, 0.5);
        border-radius: 10px;

        .boxitem_s {
            display: flex;
            flex-direction: column;
            justify-content: center;
            align-items: flex-start;

            .boxitem_ses {
                margin-top: 10px;
                display: flex;
                justify-content: flex-start;
                align-items: center;

                .es {
                    border-left: 2px solid #DDDFE6;
                    padding: 0 10px;
                    display: flex;
                    justify-content: flex-start;
                    align-items: center;

                    .e {
                        font-family: Source Han Sans CN, Source Han Sans CN;
                        font-weight: 400;
                        font-size: 12px;
                        color: #666666;
                    }

                    .s {
                        margin-left: 10px;
                        font-family: Source Han Sans CN, Source Han Sans CN;
                        font-weight: 500;
                        font-size: 15px;
                        color: #3F9EFF;
                    }
                }

                .es:nth-child(1) {
                    margin-top: 0;
                    border-left: none;
                }
            }

            .boxitem_ses:nth-child(1) {
                margin-top: 0;
            }
        }
    }
}
</style>