<template>
    <div class="checkOperation">

        <div>
            <div class="carousel-page">
                <div class="carousel-page-content">
                    <div class="img-box">
                        <ul>
                            <li>
                                 <span class="img-box-title">
                                    位置:
                                </span>
                                <span class="img-box-value">
                                    {{checkObj.streetName}}-{{checkObj.direction }}-{{checkObj.column}}列-{{checkObj.row}}层
                                </span>
                            </li>
                            <li>
                                <span class="img-box-title">
                                    核对状态:
                                </span>
                                <span class="img-box-value">
                                    {{ statusMap[checkObj.status] }}
                                </span>
                            </li>
                            <li v-for="item in params" :key="item.label">
                
                                <span class="img-box-title">
                                    {{ item.label }}:
                                </span>
                                <span class="img-box-value">
                                    {{ checkObj[item.key] }}
                                </span>
                            </li>
                        </ul>
                    </div>
                    <div class="img-box">
                            <viewer v-if="checkObj.checkPic" style="height: 300px">
                                <img :src="imgUrl+checkObj.checkPic"/>
                            </viewer>
                        <div
                            v-else
                            style="display: flex;align-items: center;justify-content: center;width:100px;height:300px;">
                            暂无图片
                        </div>
                        <p>盘点图1</p>
                    </div>
                    <div class="img-box">
                            <viewer v-if="checkObj.checkPic" style="height: 300px">
                                <img :src="imgUrl+checkObj.checkPic2"/>
                            </viewer>
                        <div
                            v-else
                            style="display: flex;align-items: center;justify-content: center;width:100px;height:300px;">
                            暂无图片
                        </div>
                        <p>盘点图2</p>
                    </div>
                    <!-- <div class="img-box">
                        <viewer v-if="checkObj.preoperationPic" style="height:300px;">
                            <img  :src="imgUrl+checkObj.preoperationPic"/>
                        </viewer>
                        
                        <div v-else  style="display: flex;align-items: center;justify-content: center;width:100px;height:300px;">
                            暂无图片
                        </div>
                        <p>操作前照片</p>
                    </div>
                    <div class="img-box">
                        <viewer v-if="checkObj.overoperationPic" style="width:100%;height:300px;">
                            
                            <img  :src="imgUrl+checkObj.overoperationPic"/>
                        </viewer>
                        
                        <div
                            v-else
                            style="display: flex;align-items: center;justify-content: center;width:100px;height:300px;">
                            暂无图片
                        </div>
                        <p>操作后照片</p>
                    </div> -->
                </div>
            </div>
            <div class="bottom-btn" >
                <a-button class="btn"
                        type="primary"
                        style="background:#29c12b;border-color:#29c12b;"
                        @click="checkSure(checkObj.row,checkObj.column,checkObj.shelveId,index)"
                >核对正确
                </a-button>
                <a-button class="btn"
                        type="primary"
                        style="background:#ff0000;border-color:#ff0000;"
                        @click="checkfalse(checkObj.row,checkObj.column,checkObj.shelveId,index)"
                >核对错误
                </a-button>
		<a-button class="btn"
                        type="primary"
                        style="background:#29c12b;border-color:#29c12b;"
                        @click="nextOne(checkObj.id)">
                        下一个盘点
                </a-button>
            </div>
            
        </div>
       

        <Model
            :visible.sync="visible"
            :modelData.sync="modelData"
            :index="index"
            @sure="submit"
            @close="closeModel"
        />
    </div>
</template>
<script>
import Model from "./model.vue"
import {imgUrl} from "@/api/importExcel";
import { message } from 'ant-design-vue';
export default {
    data() {
        return {
           
            checkObj: {},
            row: 1,
            column: 1,
            streetName: '',
            visible: false,
            category: '',
            count: 0,
            modelData: {},
            index: 0,
            imgUrl: '',
            params:[
                // {
                //     label:'盘点批次号',
                //     key: 'lotnum'
                // },
                
                {
                    label:'盘点任务号',
                    key: 'checkNum'
                },
                {
                    label:'托盘码',
                    key: 'wmsCode'
                },
                {
                    label:'托盘码描述',
                    key: 'wmsCategory'
                },
                {
                    label:'盘点时间',
                    key: 'exportTime'
                },
                
            ],
            statusMap: {0:"未盘点",1:"盘点异常",2:"核对正确",3:"人工核对正确"}
            
        }
    },
    beforeRouteLeave(to ,form, next) {
        // 修复第二次进入界面不执行created
        this.$destroy();
        if (to.name == 'checkManage') {
            to.meta.isUseCache = true;    
        }else{
            to.meta.isUseCache = false;
        }   
        next();
    },
    created() {
        this.imgUrl = imgUrl
        
        //this.getStreetList();
        if (this.$route.query.row && this.$route.query.column && this.$route.query.direction && this.$route.query.side && this.$route.query.streetId) {
            this.id = this.$route.query.id
            this.row = this.$route.query.row
            this.column = this.$route.query.column
            this.direction = this.$route.query.direction
            this.side = this.$route.query.side
            this.streetId = this.$route.query.streetId
            this.streetName = this.$route.query.name
            
            this.getStockInfo(this.row, this.column);
        }
    },
    mounted() {
        
    },
    destroyed () {
        
    },
    components: {
        Model
    },
    methods: {
       
        //获取复核页面的核对信息
        getStockInfo(row, column) {
            this.$api.httpApi.getStockInfo({
                data: {
                    row: Number(row),
                    column: Number(column),
                    direction: this.direction,
                    side: this.side,
                    streetId: this.streetId,
                }
            }).then(res => {
                if (res.data) {
                    this.checkObj = res.data;
                    this.checkObj.checkPic2 = this.checkObj.checkPic + ".jpg"
                    //this.shelveId = res.data.shelveId;
                    //this.getScanAndCheck();
                }
            }).catch(err => {
                console.log(err)
            });
        },
        handleChange(value) {
            
            this.select = value
            this.id = value
            this.row = 1
            this.column = 1
            this.getStockInfo(1, 1)
        },
        
        checkSure(row, column, shelveId, index) {
            this.$api.httpApi.stockCheckCorrect({
                data: {
                    row: Number(row),
                    column: Number(column),
                    side: Number(this.side),
                    streetId: Number(this.streetId),
                    direction: Number(this.direction),
                    ok: 1
                }
            }).then(res => {
                if (res.code == 200) {
                    this.$message.success('操作成功');
                    this.getStockInfo(this.row,this.column)
                }

            }).catch(err => {

            });
        },
        checkfalse(row, column, shelveId, index) {
            this.$api.httpApi.stockCheckCorrect({
                data: {
                    row: Number(row),
                    column: Number(column),
                    side: Number(this.side),
                    streetId: Number(this.streetId),
                    direction: Number(this.direction),
                    ok: 0
                }
            }).then(res => {
                if (res.code == 200) {
                    this.$message.success('操作成功');
                    this.getStockInfo(this.row,this.column)
                }

            }).catch(err => {

            });
        },
        showModel(checkObj, index) {
            this.visible = true
            this.modelData = checkObj
            this.index = index;
        },
        submit(visible, index) {
            
            this.visible = visible
            console.log(index)
            // this.next(index);
            this.checkObj.status = 1;
        },
        closeModel(visible, data) {
            this.visible = visible
            this.modelData = data
        },
        nextOne(id){
            this.$api.httpApi.nextOne({
                data: {
                    id:Number(id)
                }
            }).then(res => {
                if (res.data && res.data != null) {
                    console.log(res.data)
                    this.checkObj = res.data;
                    this.id = res.data.id
                    this.row = res.data.row
                    this.column = res.data.column
                    this.direction = res.data.direction
                    this.side = res.data.side
                    this.streetId = res.data.streetId
                    this.streetName = res.data.streetName
                    this.checkObj.checkPic2 = this.checkObj.checkPic + ".jpg"
            
                }else{
                    message.info('全部盘点已完成')
                }
            }).catch(err => {
                console.log(err)
            });
        }
       
    }
}
</script>
<style lang="scss">
    .ant-carousel .slick-slide {
        color: #000000;
    }

    .checkOperation {
            .carousel-page {
                width: 100%;
                /*border: solid 1px blue;*/
                &-title {
                    color: #009FE3;
                    font-size: 16px;
                    margin: 0;
                    padding: 15px 0 10px 25px;
                }

                &-content {
                    display: flex;
                    align-items: center;
                    justify-content: space-between;
                    padding-left: 25px;

                    .img-box {
                        display: flex;
                        align-items: center;
                        justify-content: center;
                        flex-direction: column;
                        font-size: 17px;
                        height: 400px;
                        margin-right: 10px;
                        img {
                            height: 100%
                        }

                        p {
                            height: 25px;
                        }
                        ul {
                            width: 100% / 4;
                            height: 100%;
                            margin-bottom: 0;
                            padding-inline-start: 0;
                            li {
                                background-color: #ffaf11;
                                margin: 10px 0;
                                padding: 5px;
                                font-size: 16px;
                                font-weight: 600;
                                color: #494e52;
                                .img-box-title {
                                    width: 130px;
                                    display: inline-block;
                                }
                                .img-box-value {
                                    display: inline-block;
                                    width: calc(100% - 130px);
                                    overflow: hidden;
                                    position: relative;
                                    top: 5px;
                                }
                            }
                        }
                    }
                }

                &-footer {
                    width: calc(100% - 380px);
                    .info-box {
                        color: #000000;
                        display: flex;
                        align-items: center;
                        justify-content: center;

                        p {
                            padding: 0 20px;
                            font-size: 18px;
                        }
                    }

                    .status {
                        text-align: center;
                        font-size: 21px;
                    }

                    .status-btn {
                        display: flex;
                        align-items: flex-start;
                        justify-content: flex-start;

                        .btn {
                            padding: 50px;
                            font-size: 20px;
                            display: flex;
                            align-items: center;
                            justify-content: center;
                            line-height: 0;
                            margin: 15px 45px;
                        }
                    }
                }
            }

        .bottom-btn {
            width: 100%;
            display: flex;
            align-items: right;
            justify-content: center;

            p {
                font-size: 18px;
                padding: 0;
                margin: 0;
            }

            .btn {
                margin: 25px;
            }
        }
    }
    .historyImg {
        width: 180px;
        height:auto;
    }

</style>
