<template>
    <div class="history bg-white">
        

        <a-table
            :columns="columns"
            :row-key="record => record.id"
            :data-source="data"
            :pagination="pagination"
            @change="handleGetHistoryList"
        >
          
        <span slot="status" slot-scope="text">
               {{text.flag}}
          </span>
          <span slot="pic" slot-scope="text" style="width:auto">

            <template>
                <span style="height:100%;">
                    <happy-scroll color="rgba(100,100,100,0.5)" size="8" class="scroll-box" style="width:320px;height:90px;">
                        
                        <viewer >
                            <img class="historyImg"  :src="'http://'+text.path"
                                :key="'http://'+text.path"/>
                        </viewer>
                    </happy-scroll>
                </span>
                
            </template>

          </span> 
          
          <span slot="operate" slot-scope="text" style="width:auto">

<template>
    <span style="height:100%;">
        
    </span>
    
</template>

</span> 
        </a-table>
        
    </div>
</template>
<script>
import {imgUrl} from "@/api/importExcel";
import moment from 'moment';
export default {
    name: "historyCheck",
    data() {
        return {
            statusMap: {0:"未盘点",1:"盘点异常",2:"核对正确",3:"人工核对正确"},
            queryParam: {
                lotnum: '',
                side : -1,
                leftRight : -1
            },
            listData:[],
            time:[],
            pageNum: 1,
            pageSize: 10,
            data: [],
          
            select: '',
            pagination:{
                total: 0,
                defaultPageSize: 10, // 默认每页显示数量
                showTotal: total => `共 ${total} 条数据`,// 显示总数
                showSizeChanger: true, // 显示可改变每页数量
                pageSizeOptions: ['10', '20', '30'],
                onShowSizeChange: (current, pageSize) => this.pageSize = pageSize // 改变每页数量时更新显示
            },
            imgUrl: imgUrl,
            columns: [
                
                {
                    title: "条码",
                    dataIndex: "code",
                },
                {
                    title: "品规",
                    dataIndex: "categoryName",
                },
                {
                    title: "数量",
                    dataIndex: "count",
                },
                {
                    title: "上位条码",
                    dataIndex: "wmsCode",
                },
                {
                    title: "上位数量",
                    dataIndex: "wmsCount",
                },
                {
                    title: "状态",
                    dataIndex:  "flagString",
                },
                {
                    title: "照片",
                    scopedSlots: {customRender: 'pic'},
                    width:320,
                },
                {
                    title: "时间",
                    dataIndex: "createTime",
                },
                {
                    title: "操作",
                    scopedSlots: {customRender: 'operate'},
                },
                
            ],
        }
    },
    mounted() {
        //this.getStreetList();
        this.handleSearch();
    },
    methods: {
        moment,
        //获取巷道列表
        getStreetList() {
            this.$api.httpApi.getAllStreet({
            }).then(res => {
                this.listData = res.data; 
            }).catch(err => {
                console.error(err);
            });
        },
        //获取巷道详情
        getStreetDetail(id) {
            this.$axios.get('/street/' + id, {
                data: {}
            }).then(res => {
                this.streetDetail = res.data
                this.select = this.streetDetail.name;
                this.queryParam.streetId = this.streetDetail.id;
            }).catch(err => {

            })
        },
        handleChange(value) {
            this.getStreetDetail(value)
            this.queryParam.leftRight = -1
            this.queryParam.side = -1
            
        },
        // 左右货架切换
        leftRightChange(value) {
            if (value == 1) {
                //单伸
                if(this.streetDetail.leftType == 0){
                    this.queryParam.side = -1
                }else{
                    this.queryParam.side = 0
                }
            } else if (value == 2) {
                if(this.streetDetail.rightType == 0){
                    this.queryParam.side = -1
                }else{
                    this.queryParam.side = 0
                    
                }
            } else{
                this.queryParam.side = -1
            }
        },
        handleSearch() {
            console.log(this.queryParam)
            this.pageNum = 1
            this.request()
        },
        handleGetHistoryList(pagination) {
            console.log(pagination)
            if(pagination){
                this.pagination.current = pagination.current;
                this.pagination.pageSize = pagination.pageSize;
                this.pageNum = pagination.current;
                this.pageSize = pagination.pageSize;
            }
            this.request();
        },
        request() {
            this.$api.httpApi.KuKouControllerlist({
                data: {
                    pageNum: this.pageNum,
                    pageSize: this.pageSize,
                    ...this.queryParam
                }
            }).then(res => {
                console.log(res.data)
                const pagination = {...this.pagination};
                pagination.total = res.data.total;
                this.pagination = pagination;
                this.data = res.data.list
            }).catch(err => {

            });
        },
        onTimeChange(date, dateString) {
            this.handleReset()
            console.log(date)
            console.log(dateString)
            console.log(date[0].format('YYYY-MM-DD HH:mm'))
            this.pageNum = 1
            
            this.queryParam.startTimestamp = date[0].format('YYYY-MM-DD HH:mm:ss')
            this.queryParam.endTimestamp = date[1].format('YYYY-MM-DD HH:mm:ss')
        },
        handleReset() {
            this.queryParam.startTimestamp = ""
            this.queryParam.endTimestamp = ""
            this.pageNum = 1
            
        },
        reset() {
            this.queryParam.startTimestamp = ""
            this.queryParam.endTimestamp = ""
            this.queryParam.lotnum = ""
            this.queryParam.side = -1
            this.queryParam.leftRight = -1
            this.queryParam.streetId = 0

            this.select = null;
            this.time = []
            this.pageNum = 1
            this.pageSize = 10
            this.queryParam.row = null
            this.queryParam.column = null
            this.request()
        },
    },
};
</script>

<style lang="scss" scoped>
.history {
    padding: 24px;
}
.ant-drawer-content-wrapper {
    height: auto !important;
}

.ant-drawer-body {
    text-align: center;
}

.ant-advanced-search-form .ant-form-item {
    display: flex;
    width: 100%;
}

.historyImg {
    width: 80px;
    height:auto;
    margin: 5px;
}
</style>
