<template>
    <div>
      <el-card class="el-card">
            <el-form  :model="query"  size="mini" label-width="100px" v-if="showSearch">
              <el-row>
                <el-col :span="6">
                    <el-form-item label="往来单位编码:">
                        <el-input v-model="filterQuery.erpId" style="width: 90%" placeholder="请输入往来单位编码"></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="往来单位编码" prop="erpId" show-overflow-tooltip width="100"></el-table-column>
                <el-table-column label="名称" prop="name" show-overflow-tooltip></el-table-column>
                <el-table-column label="简写" prop="spell" show-overflow-tooltip></el-table-column>
                <el-table-column label="社会信用号" prop="creditNo" show-overflow-tooltip></el-table-column>
                <el-table-column label="地址" prop="addr" 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.importStatus)">{{ status[scope.row.importStatus] }}</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"
          :page.sync="filterQuery.page"
          :limit.sync="filterQuery.limit"
          @pagination="handleCurrentChange"

        ></pagination>

        </el-card>
    </div>
</template>

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

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

        },
        data() {
            return {
                showSearch: true,
                filterQuery: {
                    erpId:null,
                    status:null,
                    page: 1,
                    limit: 10,
                },
                list: [],
                detailList: [],
                total: 0,
                status: {
                    0: "未处理",
                    2: "已完成",
                    1: "异常"
                },
            };
        },

        methods: {
            onReset() {
                this.$router.push({
                    path: "",
                });
                this.filterQuery = {
                    genKey: null,
                    udiCode:null,
                    status:null,
                    page: 1,
                    limit: 10,
                };
                this.getList();
            },
            hideSearch() {
              this.showSearch = !this.showSearch;
            },
            getList() {
                this.loading = true;
                console.log(" this.genKeyFk = "+ 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;
                    });
            },
            statusFilterType(status) {
                const statusMap = {
                    0: "warning",
                    1: "danger",
                    2: "success",
                };
                return statusMap[status];
            },
            handleCurrentChange(val) {
                this.filterQuery.page = val;
                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>
