<template>
    <div class="system-user-container layout-padding">
        <el-card shadow="hover" class="layout-padding-auto">
            <div class="system-user-search mb15">
                <el-select v-model="state.type" size="default" class="m-2" placeholder="请选择类型">
                    <el-option label="全部" value="" />
                    <el-option v-for="item in state.typelist" :label="item.label" :value="item.value" />
                </el-select>
                <el-select size="default" style="margin: 0 10px;" v-model="state.businessState" class="m-2"
                    placeholder="请选择状态">
                    <el-option label="全部" value="" />
                    <el-option v-for="item in state.buslist" :label="item.label" :value="item.value" />
                </el-select>
                <el-button @click="getTableData" size="default" type="primary" class="ml10">
                    <el-icon>
                        <ele-Search />
                    </el-icon>
                    查询
                </el-button>
                <el-button size="default" @click="upshow" type="primary" class="ml10">新增报表</el-button>
            </div>
            <el-table :data="state.tableData.data" v-loading="state.tableData.loading" style="width: 100%" border stripe
                :cell-style="{ textAlign: 'center' }" :header-cell-style="{ 'text-align': 'center' }">
                <el-table-column prop="areaName" label="区县名称"></el-table-column>
                <el-table-column prop="date" label="报表日期">
                    <template #default="scope">
                        {{ scope.row.date }}
                    </template>
                </el-table-column>
                <el-table-column prop="type" label="报表类型">
                    <template #default="scope">
                        {{ filtername(scope.row.type) }}
                    </template>
                </el-table-column>
                <el-table-column prop="businessState" label="报表状态">
                    <template #default="scope">
                        <div :class="scope.row.businessState == 1 ? 'green' : 'red'">
                            {{ filterstate(scope.row.businessState) }}
                        </div>
                    </template>
                </el-table-column>
                <el-table-column prop="remark" label="退回备注" show-overflow-tooltip> </el-table-column>
                <el-table-column prop="createTime" label="添加时间">
                    <template #default="scope">
                        {{ proxy?.$method.formatDate(scope.row.createTime) }}
                    </template>
                </el-table-column>
                <el-table-column prop="updateTime" label="最后修改时间">
                    <template #default="scope">
                        {{ proxy?.$method.formatDate(scope.row.updateTime) }}
                    </template>
                </el-table-column>
                <el-table-column label="操作" show-overflow-tooltip width="100" fixed="right">
                    <template #default="scope">
                        <el-button size="small" @click="godetail(scope.row)" text type="warning">查看</el-button>
                        <el-button size="small" v-if="scope.row.businessState != 1" @click="editshow(scope.row)" text
                            type="primary">修改</el-button>
                    </template>
                </el-table-column>
            </el-table>
            <el-pagination @size-change="onHandleSizeChange" @current-change="onHandleCurrentChange" class="mt15"
                :pager-count="5" :page-sizes="[10, 20, 30]" v-model:current-page="state.tableData.param.pageNum" background
                v-model:page-size="state.tableData.param.pageSize" layout="total, sizes, prev, pager, next, jumper"
                :total="state.tableData.total">
            </el-pagination>
        </el-card>
    </div>
</template>
  
<script setup lang="ts" name="reportrundata">
import { defineAsyncComponent, reactive, onMounted, ref } from "vue";
import { ElMessageBox, ElMessage, ElNotification } from "element-plus";
import { getApi } from "/@/api/district/index";
import { useCurrentInstance } from "/@/method/get";
const { proxy } = useCurrentInstance();
import { useRouter } from "vue-router";
const router = useRouter();

// 定义变量内容
// 定义变量内容
const state = reactive<any>({
    date: undefined,
    businessState: '',
    type: '',
    tableData: {
        data: [],
        total: 0,
        loading: false,
        param: {
            pageNum: 1,
            pageSize: 10,
        },
    },
    typelist: [],
    buslist: []
});

function filtername(name: string | number) {
    const tylist = state.typelist
    let names = tylist.filter((res: any) => {
        return name == res.value
    })
    if (names.length != 0) {
        return names[0].label
    }
}

function filterstate(name: string | number) {
    const tylist = state.buslist
    let names = tylist.filter((res: any) => {
        return name == res.value
    })
    if (names.length != 0) {
        return names[0].label
    }
}

function upshow() {
    router.push({
        path: '/district/addandedit',
        query: {
            id: '',
            type: 0,
            tagsViewName: '新增'
        }
    });
    // disDialogRef.value.openDialog();
}
function editshow(e: any) {
    if (e.businessState != 2) return ElMessage.error('只有已退回才可修改')
    router.push({
        path: '/district/addandedit',
        query: {
            id: e.id,
            form: JSON.stringify(e),
            type: 1,
            tagsViewName: '修改'
        }
    });
}

function godetail(row: any) {
    let name = ""
    if (row.type == 1) name = '日报'
    if (row.type == 2) name = '月报'
    if (row.type == 3) name = '建设部报表'
    if (row.type == 4) name = '省厅月报'
    router.push({
        path: '/district/detail',
        query: {
            id: row.id,
            type: row.type,
            tagsViewName: name + "详情"
        }
    });
}


// 初始化表格数据
const getTableData = async () => {
    state.tableData.loading = true;
    // 获取type
    const item = await getApi().gettype();
    state.typelist = item.data;
    // 获取状态
    const items = await getApi().getbus();
    state.buslist = items.data;

    // 项目
    const data = await getApi().listApi({
        page: state.tableData.param.pageNum,
        limit: state.tableData.param.pageSize,
        businessState: state.businessState,
        type: state.type
    });
    state.tableData.data = data.data;
    state.tableData.total = data.count;
    state.tableData.loading = false;
};
// 分页改变
const onHandleSizeChange = (val: number) => {
    state.tableData.param.pageSize = val;
    getTableData();
};

// 分页改变
const onHandleCurrentChange = (val: number) => {
    state.tableData.param.pageNum = val;
    getTableData();
};
// 页面加载时
onMounted(() => {
    getTableData();
});
</script>
  
<style scoped lang="scss">
.wgt {
    font-weight: bold;
}

.green {
    color: #02bc34;
}

.red {
    color: #e30f0f;
}

.system-user-container {
    :deep(.el-card__body) {
        display: flex;
        flex-direction: column;
        flex: 1;
        overflow: auto;

        .el-table {
            flex: 1;
        }
    }
}
</style>
  