<template>
    <div class="checkOperation">
        <div class="topMenu">
            <a-select v-if="listData[0]"
                      :default-value="selectName"
                      style="width:160px;margin-right:25px"
                      @change="handleChange"
                      class="select-roadway">
                <a-select-option v-for="i in listData" :key="i.name" :value="i.id">
                    {{i.name}}
                </a-select-option>
            </a-select>

            <a-select
                @change="handleTypeChange"
                style="width: 160px;margin-right:25px"
                :value="selectType">
                <a-select-option value="left">
                    左货架
                </a-select-option>
                <a-select-option value="right">
                    右货架
                </a-select-option>
            </a-select>
            <a-select default-value="c" style="width: 160px" v-if="!checkObj.shelveId">
                <a-select-option value="c">
                    外
                </a-select-option>
                <a-select-option value="d">
                    内
                </a-select-option>
            </a-select>
        </div>
        <div v-for="(key,value) in checkList" :key="value">

            <div v-if="checkObj.shelveId == value">
                <!--{{value}}{{key}}-->
                <div v-for="(columnItem,index) in key" :key="index">
                    <div class="carousel-page"
                         v-if="columnItem.row == checkObj.row && columnItem.column == checkObj.column">
                        <p class="carousel-page-title">工单号：{{checkObj.orderNum}}</p>
                        <div class="carousel-page-content">
                            <div class="img-box">
                                <img
                                    src="https://ss1.bdstatic.com/70cFuXSh_Q1YnxGkpoWK1HF6hhy/it/u=1931813381,2486401072&fm=26&gp=0.jpg"
                                    alt="">
                                <p>操作前照片</p>
                            </div>
                            <div class="img-box">
                                <img
                                    src="https://ss1.bdstatic.com/70cFuXSh_Q1YnxGkpoWK1HF6hhy/it/u=3139679339,2066283298&fm=26&gp=0.jpg"
                                    alt="">
                                <p>操作后照片</p>
                            </div>
                        </div>
                        <div class="carousel-page-footer">
                            <div class="info-box">
                                <p>系统登记品规：{{checkObj.category}}</p>
                                <p>系统登记数量：{{checkObj.count}}</p>
                            </div>
                            <div class="status" v-if="checkObj.status == 0">
                                未核对
                            </div>
                            <div class="status" v-if="checkObj.status == 1">
                                已核对：<span style="color: #d81e06;">核对错误</span>
                            </div>
                            <div class="status" v-if="checkObj.status == 2">
                                已核对：<span style="color: #1afa29;">核对正确</span>
                            </div>
                            <div class="status-btn" v-if="checkObj.status == 0">
                                <a-button class="btn"
                                          type="danger"
                                          @click="showModel(checkObj,index)"
                                >人工复核
                                </a-button>
                                <a-button class="btn"
                                          type="primary"
                                          style="background:#29c12b;border-color:#29c12b;"
                                          @click="checkSure(checkObj.row,checkObj.column,checkObj.shelveId,index)"
                                >核对正确
                                </a-button>
                            </div>
                            <div class="status-btn" v-if="checkObj.status == 1 ||checkObj.status == 2">
                                <a-button class="btn"
                                          type="danger"
                                          @click="showModel(checkObj,index)"
                                >核对错误
                                </a-button>
                                <a-button class="btn"
                                          type="primary"
                                          style="background:#29c12b;border-color:#29c12b;"
                                          @click="checkSure(checkObj.row,checkObj.column,checkObj.shelveId,index)"
                                >核对正确
                                </a-button>
                            </div>
                        </div>
                    </div>

                    <div class="bottom-btn"
                         v-if="columnItem.row == checkObj.row && columnItem.column == checkObj.column">
                        <a-button class="btn" @click="prev(index > 0 ? index : 0)">＜上一个</a-button>
                        <p>{{checkObj.row}}行{{checkObj.column}}列</p>
                        <a-button class="btn" @click="next(index<=key.length ? index :index=key.length-1)">下一个＞
                        </a-button>
                    </div>
                </div>
            </div>
        </div>
        <Model
            :visible.sync="visible"
            :modelData.sync="modelData"
            :index="index"
            @sure="submit"
            @close="closeModel"
        />
    </div>
</template>
<script>
    import Model from "./model.vue"
export default {
    data() {
        return {
            listData: [],
            checkObj: {},
            streetDetail: {},
            checkList: [],
            id: 0,
            selectName: '',
            shelveId: '',
            selectType: '',
            visible: false,
            category: '',
            count: 0,
            modelData: {},
            index: 0
        }
    },
    created() {
        this.checkObj = this.$route.query.checkObj
        this.streetDetail = this.$route.query.item
        this.id = this.$route.query.item.id
        this.selectName = this.$route.query.item.name
        console.log(this.checkObj)
        if (this.checkObj.shelveId == this.streetDetail.leftShelveId) {
            this.selectType = 'left'
        } else {
            this.selectType = 'right'
        }
    },
    mounted() {
        this.getStreetList()
    },
    components: {
        Model
    },
    methods: {
        //获取巷道列表
        getStreetList(id) {
            this.$api.httpApi.getStreetList({
                data: {
                    pageNum: 1,
                    pageSize: 50,
                }
            }).then(res => {
                this.listData = res.data.list;
                console.log(this.listData)
                this.select = this.id
                this.getStreetDetail(this.id)
                this.getStockList(this.id)
            }).catch(err => {

            });
        },
        //获取巷道详情
        getStreetDetail(id) {
            this.$axios.get('/street/' + id, {
                data: {}
            }).then(res => {
                this.streetDetail = res.data
                console.log(this.streetDetail)

            }).catch(err => {

            })
        },
        //获取盘点列表
        getStockList(streetId) {
            this.$api.httpApi.getStockList({
                params: {
                    streetId: streetId,
                }
            }).then(res => {
                this.checkList = res.data
            }).catch(err => {

            });
        },
        //获取复核页面的核对信息
        getStockInfo(row, column, shelveId) {
            this.$api.httpApi.getStockInfo({
                data: {
                    row: Number(row),
                    column: Number(column),
                    shelveId: shelveId,
                }
            }).then(res => {
                this.checkObj = res.data
                this.shelveId = res.data.shelveId
            }).catch(err => {

            });
        },
        handleChange(value) {
            console.log(value)
            this.select = value
            this.id = value
            this.getStreetList()
            for (var i = 0; i < this.listData.length; i++) {
                console.log(this.listData[i])
                if (this.listData[i].id == value) {
                    this.shelveId = this.listData[i].leftShelveId
                }
            }
            this.selectType = 'left'
            this.getStockInfo(1, 1, this.shelveId)
        },
        handleTypeChange(value) {
            console.log(this.streetDetail.leftShelveId)
            console.log(value)
            this.selectType = value
            if (value == 'left') {
                this.getStockInfo(1, 1, this.streetDetail.leftShelveId)
            } else if (value == 'right') {
                this.getStockInfo(1, 1, this.streetDetail.rightShelveId)
            }

        },
        prev(index) {
            index--
            console.log(index)
            for (let x in this.checkList) {
                if (this.checkObj.shelveId == this.checkList[x][index].shelveId) {
                    console.log(this.checkList[x][index].row)
                    console.log(this.checkList[x][index].column)
                    console.log(this.checkList[x][index].shelveId)
                    this.getStockInfo(this.checkList[x][index].row, this.checkList[x][index].column, this.checkList[x][index].shelveId)
                }
            }
        },
        next(index) {
            index++
            console.log(index)
            for (let x in this.checkList) {
                if (this.checkObj.shelveId == this.checkList[x][index].shelveId) {
                    console.log(this.checkList[x][index].row)
                    console.log(this.checkList[x][index].column)
                    console.log(this.checkList[x][index].shelveId)
                    this.getStockInfo(this.checkList[x][index].row, this.checkList[x][index].column, this.checkList[x][index].shelveId)
                }
            }
        },
        checkSure(row, column, shelveId, index) {
            this.$api.httpApi.stockCheckCorrect({
                data: {
                    row: Number(row),
                    column: Number(column),
                    shelveId: shelveId,
                }
            }).then(res => {
                this.next(index)
            }).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)
        },
        closeModel(visible, data, index) {
            this.visible = visible
            this.modelData = data
        },
    }
}
</script>
<style lang="scss">
    .ant-carousel .slick-slide {
        color: #000000;
    }

    .checkOperation {
            .carousel-page {
                width: 900px;
                /*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;
                        width: 400px;

                        img {
                            width: 100%;
                            height: calc(100% - 25px)
                        }

                        p {
                            height: 25px;
                        }
                    }
                }

                &-footer {
                    .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: center;
                        justify-content: center;

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

        .bottom-btn {
            width: 900px;
            display: flex;
            align-items: center;
            justify-content: center;

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

            .btn {
                margin: 25px;
            }
        }
    }

</style>
