<template>
    <PageHeader :title="title">
        <template #action>
            <Button type="primary" @click="goreport(0, null)">制作测试报告</Button>
        </template>
        <template #content>
            <Space>
                <Input v-model="searchinfo.project" placeholder="请输入项目名" clearable style="width: 260px" />
                <Input v-model="searchinfo.story" placeholder="请输入迭代名" clearable style="width: 260px" />
                <Input v-model="searchinfo.save_remark" placeholder="请输入备注" clearable style="width: 260px" />
                <Button type="primary" @click="getreport()">搜索</Button>
            </Space>
        </template>
    </PageHeader>
    <div style="margin-top: 8px">
        <Table row-key="id" :columns="columns" :data="reports" show-context-menu>
            <template #status="{ row }">
                <p>{{ row.report_status ? '已发送' : '未发送' }}</p>
            </template>
            <template #edit="{ row }">
                <Button size="small" v-if="!row.status" type="info" ghost @click="goreport(1, row.id)">编辑</Button>
                <Button size="small" style="margin-left: 5px;" type="error" ghost @click="delreport(row.id)">删除</Button>
            </template>
        </Table>
        <Page :total="totals" :page-size="searchinfo.page_size" v-model="searchinfo.page_num" @on-change="getreport()"
            show-total style="margin-top: 20px;" />
    </div>
</template>

<script>


export default {
    props: ['isCollapsed',],
    data() {
        return {
            page_id: 22,
            title: "测试报告",
            searchinfo: {
                page_size: 10,
                page_num: 1,
                project: null,
                story: null,
                save_remark: null
            },
            totals: 0,
            reports: [],
            columns: [
                {
                    title: '项目',
                    key: 'project',
                    align: 'center'
                }, {
                    title: '迭代',
                    key: 'story',
                    align: 'center'
                }, {
                    title: '更新时间',
                    key: 'update_time',
                    align: 'center'
                }, {
                    title: '备注',
                    key: 'save_remark',
                    align: 'center'
                },
                {
                    title: '状态',
                    slot: 'status',
                    align: 'center'
                }
                , {
                    title: '编辑',
                    slot: 'edit',
                    align: 'center'
                }
            ],
            elements: []
        }
    },
    methods: {
        getreport() {
            this.$request("get", "/tool/testport/reportlist", this.searchinfo, this, (data) => { this.reports = data.data.rows; this.totals = data.data.total })
        },
        goreport(pagestatus, id) {
            localStorage.setItem('pagestatus', pagestatus)
            localStorage.setItem('reportid', id ? id : 0)
            const a = this.$router.resolve({
                name: 'report'
            })
            window.open(a.href, '_blank')
        },
        delreport(id) {
            this.$request('delete', '/tool/testport/delreport/' + id, null, this, () => { this.getreport() })
        }
    },
    created() {
        this.getreport();
    }
};
</script>

<style>
.vertical-center-modal {
    display: flex;
    align-items: center;
    justify-content: center;
}

.vertical-center-modal .ivu-modal {
    top: 0;
}
</style>