<template>
    <div class="manage-container">
        <div class="manage-wrap">
            <div class="manage-header">
                <div class="header-left"></div>
                <div class="header-right">
                    <el-button type="primary" @click="addControl">新增</el-button>
                </div>
            </div>
            <div class="manage-content" v-loading="loading">
                <common-table
                    :autoHeight="true"
                    :maxRows="10"
                    :data="tableData"
                    :columns="tableColumns"
                    :total="total"
                    :current-page="currentPage"
                    :page-size="pageSize"
                    :index="true"
                    :indexLabel="'序号'"
                    title=""
                    :border="true"
                    @size-change="handleSizeChange"
                    @current-page-change="handleCurrentPageChange"
                >
                    <template #operations="{ row, index }">
                        <el-button link type="primary" size="small" @click="previewControl(row)">查看</el-button>
                        <el-button link type="primary" size="small" @click="editControl(row)">编辑</el-button>
                    </template>
                </common-table>
            </div>
        </div>
    </div>
</template>
<script setup>
    import { ref, onMounted, getCurrentInstance } from "vue";
    import { useRouter } from "vue-router";
    import CommonTable from "@/components/common/commonTable.vue";

    const router = useRouter();
    const { proxy } = getCurrentInstance();

    let tableData = ref([]);
    let tableColumns = ref([
        {
            prop: "projectName",
            label: "项目名称",
            showOverflowTooltip: true
        },
        {
            prop: "projectCode",
            label: "项目编号",
            showOverflowTooltip: true
        },
        {
            prop: "operations",
            label: "操作",
            width: 170,
            slot: "operations",
            fixed: "right",
            align: "center"
        }
    ]);
    let loading = ref(false);
    let total = ref(0);
    let currentPage = ref(1);
    let pageSize = ref(10);
    // 获取列表数据
    const getControlData = () => {
        loading.value = true;
        proxy.$post({
            url: "/api/project/getTzmbzrsList",
            data: {
                page: currentPage.value,
                pagesize: pageSize.value
            },
            callback: (data) => {
                tableData.value = data.rows;
                total.value = data.count;
                loading.value = false;
            }
        })
    };
    // 分页
    const handleSizeChange = (size) => {
        pageSize.value = size;
        currentPage.value = 1;
        getControlData();
    }
    const handleCurrentPageChange = (page) => {
        currentPage.value = page;
        getControlData();
    }
    const addControl = () => {
        router.push("/addControl");
    };
    const editControl = (item) => {
        router.push({
            name: "addControl",
            query: {
                projectId: item.id
            }
        });
    };
    const previewControl = (item) => {
        router.push({
            name: "addControl",
            query: {
                isPreview: true,
                projectId: item.id
            }
        })
    }
    onMounted(() => {
        getControlData();
    })
</script>
<style scoped lang="less">
    @import "@/styles/manage.less";
</style>