<template>
    <div>
        <el-form :inline="true" :model="query" class="query-form" size="mini">
            <el-form-item class="query-form-item">
                <el-input v-model="query.code" placeholder="条码查询" style="width: 500px"></el-input>
            </el-form-item>

            <el-form-item>
                <el-button-group>
                    <el-button type="primary" icon="search" @click="getCodeList"
                    >查询
                    </el-button
                    >
                </el-button-group>
            </el-form-item>
        </el-form>
        <el-table v-loading="loading" :data="codeArry" style="width: 100%">
            <el-table-column label="序号" type="index"></el-table-column>
            <el-table-column
                label="条码"
                prop="code"
                show-overflow-tooltip
            ></el-table-column>
            <!-- <el-table-column label="业务类型" prop="action" width="80%">
              <template slot-scope="scope">
                <span>{{ wareHouseMap[scope.row.action] }}</span>
              </template>
            </el-table-column> -->
            <el-table-column
                label="扫码数量"
                prop="count"
                width="180"
                show-overflow-tooltip
            ></el-table-column>
            <el-table-column label="创建时间" prop="actDate" width="220" show-overflow-tooltip>
                <template slot-scope="scope">
                    <i class="el-icon-time"></i>
                    <span>{{ scope.row.actDate }}</span>
                </template>
            </el-table-column>
            <el-table-column label="操作员" prop="actor" width="180"></el-table-column>
        </el-table>

        <el-pagination
            :page-size="query.limit"
            @current-change="handleCurrentChange"
            layout="prev, pager, next,total"
            :total="total"
        >
        </el-pagination>
    </div>
</template>

<script>
    import {orderList, codeList} from "../../api/warehouse/order";
    import draggable from "vuedraggable";
    import {saveAs} from "file-saver";
    import {getBusType} from "../../api/warehouse/BusRole";
    export default {
        name: "idQuery",
        props: {
            idQuery: {
                type: Object,
                required: true,
            },
        },
        data() {
            return {
                query: {
                    code: "",
                    orderId: "",
                    page: 1,
                    limit: 20,
                },
                codeArry: [],
                busTypes: [],
                total: 0,
                loading: true,
                index: null,
                formLoading: false,
                formVisible: false,
                deleteLoading: false,
                orderNo: null,
            };
        },
        components: {
            draggable,
        },
        methods: {
            onReset() {
                this.$router.push({
                    path: "",
                });
                this.query = {
                    code: "",
                    orderId: "",
                    page: 1,
                    limit: 20,
                };
                this.getCodeList();
            },
            onSubmit() {
                this.$router.push({
                    path: "",
                    query: this.query,
                });
                this.getCodeList();
            },
            handleSizeChange(val) {
                this.query.limit = val;
                this.getCodeList();
            },
            handleCurrentChange(val) {
                this.query.page = val;
                this.getCodeList();
            },

            getCodeList() {
                this.loading = true;
                this.query.orderId = this.idQuery.id;
                codeList(this.query) //查找该单号下的所有条码
                    .then((response) => {
                        this.loading = false;
                        this.codeArry = response.data.list || [];
                        this.total = response.data.total || 0;
                    })
                    .catch(() => {
                        this.loading = false;
                        this.list = [];
                        this.total = 0;
                    });
            },
            intentBack() {
                //  this.$router.push({path:'../readme/detail',query:{id:row.corpOrderId}});
                this.$router.go(-1);
            },
            geActionName(action) {
                for (let i = 0; i < this.busTypes.length; i++) {
                    if (this.busTypes[i].action === action) {
                        return this.busTypes[i].name;
                    }
                }
            },
            getBusType() {
                let query = {};
                getBusType(query)
                    .then((response) => {
                        this.busTypes = response.data.list || [];
                    })
                    .catch(() => {
                    });
            },
        },
        filters: {},
        mounted() {
            document.body.ondrop = function (event) {
                event.preventDefault();
                event.stopPropagation();
            };
        },
        created() {
            this.getBusType();
            let query = this.$route.query;
            this.orderNo = query.id;

            this.query = Object.assign(this.query, query);
            this.query.limit = parseInt(this.query.limit);
            this.query.orderId = query.orderId;

            // 加载表格数据
            this.getCodeList();
        },
    };
</script>



