<template>
    <div>
        <el-card>
            <el-form  :model="query" size="mini" label-width="100px" v-show="showSearch">
                <el-row>
                  <el-col :span="6">
                    <el-form-item label="UDI编码:">
                        <el-input v-model="filterQuery.udiCode" style="width: 90%" placeholder="请输入UDI编码"></el-input>
                    </el-form-item>
                  </el-col>
                  <el-col :span="6">
                    <el-form-item label="处理状态:">
                        <el-select v-model="filterQuery.status" style="width: 90%" placeholder="请选择处理状态">
                            <el-option label="全部" value=""></el-option>
                            <el-option label="未处理" value="0"></el-option>
                            <el-option label="已完成" value="1"></el-option>
                            <el-option label="异常" value="2"></el-option>
                        </el-select>
                    </el-form-item>
                  </el-col>
                </el-row>
            </el-form>

          <div class="top-right-btn">
            <el-button-group style="display:flex;">
              <el-button icon="el-icon-view" type="primary" @click="hideSearch">显示/隐藏搜索栏</el-button>
              <el-button type="primary" icon="el-icon-refresh" @click="onReset">重置</el-button>
              <el-button type="primary" icon="el-icon-search" @click="getList">查询</el-button>
            </el-button-group>
          </div>

          <el-divider style="margin: 15px"></el-divider>

            <el-table v-loading="loading" :data="list" style="width: 100%" @selection-change="handleSelectionChange" border highlight-current-row>
                <el-table-column label="序号" type="index"></el-table-column>
                <el-table-column label="UDI编码" prop="udiCode" show-overflow-tooltip></el-table-column>
                <el-table-column label="产品ID1" prop="thirdId" show-overflow-tooltip></el-table-column>
                <el-table-column label="产品ID2" prop="thirdId1" show-overflow-tooltip></el-table-column>
                <el-table-column label="产品ID3" prop="thirdId2" show-overflow-tooltip></el-table-column>
                <el-table-column label="产品ID4" prop="thirdId3" show-overflow-tooltip></el-table-column>
                <el-table-column label="产品ID5" prop="thirdId4" show-overflow-tooltip></el-table-column>
                <el-table-column label="医保编码" width="100" prop="ybbm" show-overflow-tooltip></el-table-column>
                <el-table-column label="商品条码" prop="sptm" show-overflow-tooltip></el-table-column>
                <el-table-column width="160" label="是否以使用单元入库" prop="isUseDy" show-overflow-tooltip></el-table-column>
                <el-table-column label="状态" prop="status" show-overflow-tooltip>
                    <template slot-scope="scope">
                        <el-tag :type="statusFilterType(scope.row.status)">{{ status[scope.row.status] }}</el-tag>
                    </template>
                </el-table-column>
                <el-table-column label="备注" prop="remark" show-overflow-tooltip></el-table-column>
            </el-table>

          <pagination
            v-show="total>0"
            :total="total"
            :limit.sync="filterQuery.limit"
            :page.sync="filterQuery.page"
            @pagination="handleCurrentChange"
          ></pagination>
        </el-card>
    </div>
</template>

<script>
import {
    filterDetail,
} from "@/api/basic/udiinfoImport";

export default {
    name: "udiImportDetail",
    props: {
        currentRow: {
            type: Object,
            required: true,
        },

    },
    data() {
        return {
            showSearch: true,
            filterQuery: {
                genKey: null,
                udiCode: null,
                status: null,
                page: 1,
                limit: 10,
            },
            list: [],
            detailList: [],
            total: 0,
            status: {
                0: "未处理",
                1: "处理失败",
                2: "处理成功"
            },
        };
    },

    methods: {
        onReset() {
            this.$router.push({
                path: "",
            });
            this.filterQuery = {
                genKey: null,
                udiCode: null,
                status: null,
                page: 1,
                limit: 10,
            };
            this.getList();
        },
        getList() {
            this.loading = true;
            console.log(" this.genKey = " + this.currentRow.genKey)
            this.filterQuery.genKey = this.currentRow.genKey;
            filterDetail(this.filterQuery)
                .then((response) => {
                    this.loading = false;
                    this.list = response.data.list || [];
                    this.total = response.data.total || 0;
                })
                .catch(() => {
                    this.loading = false;
                    this.list = [];
                    this.total = 0;
                });
        },
        hideSearch() {
          this.showSearch = !this.showSearch;
        },
        statusFilterType(status) {
            const statusMap = {
                0: "warning",
                1: "danger",
                2: "success",
            };
            return statusMap[status];
        },
        handleCurrentChange(val) {
            this.filterQuery.page = val.page;
            this.getList();
        },

    },
    mounted() {
    },
    created() {
        this.getList();
    },
    filters: {},
};
</script>
<style scoped>
.itemTag {
    float: left;
    text-align: left;
    margin-top: 10px;
    width: 100px;
}

.text {
    font-size: 13px;
    font-family: "Microsoft YaHei";
}

.el-row {
    display: flex;
    flex-wrap: wrap;

}

.el-col {
    border-radius: 4px;
    flex-wrap: wrap;
}
</style>
