<template>
    <headerTop @search="searchFn" @reset="resetFn" @export="exportFn"></headerTop>
    <addCom ref="addComRef"></addCom>
    <el-card shadow="always" class="content_body_row">
        <el-table :data="tableListInfo.list" border style="width: 100%" show-overflow-tooltip
            :max-height="'calc(100vh - 72px - 48px - 65px - 12px - 60px - 48px)'"
            :height="'calc(100vh - 72px - 48px - 65px - 12px - 60px  - 48px)'"
            :header-cell-style="{ background: '#F2F3F5' }">
            <el-table-column type="index" width="72" label="序号" />
            <el-table-column prop="companyName" label="企业名称" min-width="150" />
            <el-table-column prop="creditCode" label="统一社会信用代码" min-width="160">

            </el-table-column>
            <el-table-column prop="legalPerson" label="法定代表人" min-width="160">

            </el-table-column>
            <el-table-column prop="authPerson" label="被授权人姓名" min-width="160">

            </el-table-column>
            <el-table-column prop="userName" label="用户名" min-width="160">

            </el-table-column>
            <el-table-column prop="createTime" label="申请时间" min-width="160">

            </el-table-column>
            <el-table-column label="状态" min-width="120">
                <template #default="scope">
                    <div class="todo_status_c" v-if="scope.row.status == '0'">
                        待审批
                    </div>
                    <div class="pass_status_c" v-else-if="scope.row.status == '1'">
                        已通过
                    </div>
                    <div class="reject_status_c" v-else-if="scope.row.status == '2'">
                        已驳回
                    </div>
                    <div class="reject_status_c" v-else-if="scope.row.status == '3'">
                        已下架
                    </div>
                    <div class="reject_status_c" v-else-if="scope.row.status == '4'">
                        已注销
                    </div>
                </template>
            </el-table-column>
            <el-table-column label="操作" align="center" width="160">

                <template #default="scope">
                    <el-button type="primary" size="small" @click.prevent="auditFn(scope.row)">
                        审批
                    </el-button>
                    <el-button type="plain" size="small" @click.prevent="showRowFn(scope.row)">
                        查看
                    </el-button>
                </template>
            </el-table-column>
        </el-table>
        <div class="paination_out">
            <Pagination :currentPage="paginationInfo.pageNum" :pageSize="paginationInfo.pageSize" @sendPage="getPageFn">
            </Pagination>
        </div>
    </el-card>
</template>

<script lang="ts" setup>
import headerTop from "./com/headerTop.vue"
import addCom from "./com/addCom.vue"
import { apiGetCompanyInfoSelectList, apiCompanyExportExcel } from "http/api/enterprise"
import moment from "moment";
import { ElMessage } from "element-plus"
import {exportBlob} from "utils/index"
const router = useRouter()
const addComRef = ref()
const paginationInfo = reactive({
    pageNum: 1,
    pageSize: 15
})
let total = ref(0)


let tableListInfo: any = reactive({
    list: []
})

const auditFn = (row: any) => {

    router.push({
        name: 'entryAuditDetails',
        query: {
            type: 'settleIn',
            subType: 'edit',
            id: row.companyId
        }
    })
}
const showRowFn = (row: any) => {
    router.push({
        name: 'entryAuditDetails',
        query: {
            type: 'settleIn',
            subType: 'show',
            id: row.companyId
        }
    })
}

let searchParams: any = {}
const searchFn = (params: any) => {
    searchParams = params
    console.log("searchParams", params)
    searchParams.beginTime = moment(params.dataRange[0]).format('yyyy-MM-DD')
    searchParams.endTime = moment(params.dataRange[1]).format('yyyy-MM-DD')
    initTableList()
}

const resetFn =(params: any) => {
    searchParams = params
    console.log("searchParams", params)
    searchParams.beginTime = moment(params.dataRange[0]).format('yyyy-MM-DD')
    searchParams.endTime = moment(params.dataRange[1]).format('yyyy-MM-DD')
    initTableList()
}

const exportFn = async () => {

    const res: any = await apiCompanyExportExcel({})
    // console.log("res-apiCompanyExportExcel", res)

    const data = res.data.body
    console.log("res-apiCompanyExportExcel", data)

    exportBlob(data)
    ElMessage({
        type: 'success',
        message: "导出成功"
    })


}
const getPageFn = (val: any) => {
    paginationInfo.pageNum = val.pageNum
    paginationInfo.pageSize = val.pageSize
    initTableList()
}

const initTableList = async () => {
    const params = {
        ...searchParams,
        ...paginationInfo
    }
    const res: any = await apiGetCompanyInfoSelectList(params)
    console.log("apiGetCompanyInfoSelectList", res)
    tableListInfo.list = res.rows
    // tableListInfo.list = 
    total.value = res.total
}
onMounted(() => {
    initTableList()
})
</script>

<style scoped lang="scss"></style>
