<template>
    <div>
        <el-card class="el-card">
            <div>
                <el-form
                    :inline="true"
                    :model="query"
                    style="display: flex"
                    label-width="480px"
                    size="mini"
                    @submit.native.prevent
                >
                    <el-form-item class="query-form-item" label-width="100px">
                        <el-input
                            v-model="query.code"
                            placeholder="UDI码"
                            style="width: 500px"
                            @keyup.enter.native="keyup_submit($event)"
                        ></el-input>
                    </el-form-item>

                    <el-form-item style="display: flex">
                        <el-button type="primary" icon="search" @click="getList"
                        >查询
                        </el-button
                        >
                    </el-form-item>
                </el-form>

                <el-table
                    :data="list"
                    style="width: 100%"
                    :highlight-current-row="true"
                    v-loading="erpLloading"
                >
                    <el-table-column label="序号" type="index"></el-table-column>
                    <el-table-column
                        label="单据日期"
                        prop="actDate"
                        width="200"
                        show-overflow-tooltip
                    ></el-table-column>
                    <el-table-column
                        label="订单号"
                        prop="orderId"
                        width="150"
                        show-overflow-tooltip
                    ></el-table-column>

                    <el-table-column label="业务类型" prop="action">
                        <template slot-scope="scope">
                            <span>{{ geActionName(scope.row.action) }}</span>
                        </template>
                    </el-table-column>
                    <el-table-column
                        label="往来单位"
                        prop="fromCorp"
                        width="200"
                        show-overflow-tooltip
                    ></el-table-column>
                    <el-table-column
                        label="医疗器械注册人"
                        show-overflow-tooltip
                        width="200"
                        prop="ylqxzcrbarmc"
                    ></el-table-column>
                    <el-table-column
                        label="产品名称"
                        prop="cpmctymc"
                        width="200"
                        show-overflow-tooltip
                    ></el-table-column>
                    <el-table-column
                        label="规格型号"
                        prop="ggxh"
                        width="200"
                        show-overflow-tooltip
                    ></el-table-column>
                    <el-table-column
                        label="批次号"
                        width="100"
                        prop="batchNo"
                        show-overflow-tooltip
                    ></el-table-column>
                    <el-table-column
                        label="生产日期"
                        prop="produceDate"
                        width="120"
                        show-overflow-tooltip
                    ></el-table-column>
                    <el-table-column
                        label="失效日期"
                        prop="expireDate"
                        width="120"
                        show-overflow-tooltip
                    ></el-table-column>
                    <el-table-column
                        label="数量"
                        prop="count"
                        width="100"
                        show-overflow-tooltip
                    ></el-table-column>
                </el-table>
                <el-pagination
                    :page-size="query.limit"
                    @current-change="handleCurrentChange"
                    layout="prev, pager, next"
                    :total="pageTotal"
                ></el-pagination>
            </div>
        </el-card>
    </div>
</template>

<script>
    import {getTrace} from "../../api/warehouse/udiTrace";
    import {getBusType} from "../../api/warehouse/BusRole";
    export default {
        data() {
            return {
                query: {
                    code: null,

                    page: 1,
                    limit: 10,
                },

                list: [],
                pageTotal: 1,
                total: 1,
                busTypes: [],
                currentRow: null,
                loading: false,
                erpLloading: false,
                multipleUdiSelection: [],
            };
        },
        methods: {
            getList() {
                if (this.query.code == null || this.query.code == "") {
                    this.$message.warning("请输入条码查询！");
                    return;
                }
                this.loading = true;
                getTrace(this.query)
                    .then((response) => {
                        if (response.code == 20000) {
                            this.loading = false;
                            this.list = response.data.list || [];
                            this.total = response.data.total || 0;
                        } else {
                            this.$message.error(response.message);
                        }
                    })
                    .catch(() => {
                        this.loading = false;
                        this.list = [];
                        this.total = 0;
                    });
            },

            checkSelectable(row, index) {
                return !row.check;
            },
            handleCurrentChange(val) {
                this.query.page = val;
                this.getList();
            },

            intentDetail(row) {
                this.$emit("productInfo", row);
                this.closeDialog();
            },

            keyup_submit(event) {
                console.log("全选----");
                this.getList();
                event.target.select();
            },
            getBusType() {
                let query = {};
                getBusType(query)
                    .then((response) => {
                        this.busTypes = response.data.list || [];
                    })
                    .catch(() => {
                    });
            },
            geActionName(action) {
                for (let i = 0; i < this.busTypes.length; i++) {
                    if (this.busTypes[i].action === action) {
                        return this.busTypes[i].name;
                    }
                }
            },

        },
        created() {
            this.getBusType();
        }
    };
</script>

<style scoped>
    .checkitemTag {
        float: left;
        text-align: left;
        margin-top: 5px;
        width: 100%;
    }
</style>
