<template>
    <div class="list-view">
        <el-table
            :data="tableData"
            row-key="id"
            ref="table"
            header-row-class-name="table-header-row"
            header-cell-class-name="table-header-cell"
            row-class-name="table-row"
            cell-class-name="table-cell"
            :height="tableHeight"
        >
            <el-table-column v-if="multipleMode" align="center" type="selection" width="50"> </el-table-column>
            <!-- <el-table-column prop="id" label="ID" width="100"> </el-table-column> -->
            <!-- <el-table-column prop="patentId" label="专利id"> </el-table-column> -->
            <el-table-column prop="attachmentName" min-width="120px" show-overflow-tooltip label="附件名称">
            </el-table-column>
            <el-table-column prop="fileName" min-width="120px" show-overflow-tooltip label="上传文件名称">
            </el-table-column>
            <el-table-column prop="remark" show-overflow-tooltip label="备注"> </el-table-column>
            <el-table-column prop="size" label="大小"> </el-table-column>
            <el-table-column prop="createdAt" show-overflow-tooltip label="上传时间"></el-table-column>
            <el-table-column prop="userId" label="上传人" width="100px"> </el-table-column>
            <el-table-column prop="version" label="版本" width="80px"> </el-table-column>
            <el-table-column label="操作" align="center" fixed="right">
                <template slot-scope="{ row }">
                    <el-button @click="downLoad(row)" type="primary" size="mini" plain>下载</el-button>
                </template>
            </el-table-column>
        </el-table>
    </div>
</template>
<script>
import pageableTable from '@/mixins/pageableTable';

export default {
    name: 'AttachmentList',
    mixins: [pageableTable],
    props: {
        logoPatentInfo: {
            type: Object,
            default: () => {
                return {};
            }
        }
    },
    data() {
        return {
            multipleMode: true,
            search: '',
            url: '/attachment/all',
            downloading: false,
            pageSize: 100
        };
    },
    computed: {
        selection() {
            return this.$refs.table.selection.map(i => i.id);
        }
    },
    methods: {
        beforeGetData() {
            return {
                query: {
                    patentId: this.logoPatentInfo.id
                }
            };
        },
        toggleMultipleMode(multipleMode) {
            this.multipleMode = multipleMode;
            if (!multipleMode) {
                this.$refs.table.clearSelection();
            }
        },
        editRow(row) {
            this.$router.push({
                path: '/attachmentEdit',
                query: {
                    id: row.id
                }
            });
        },
        downLoad(row) {
            window.open(row.url);
        }
    }
};
</script>
<style lang="less" scoped>
.list-view {
    flex-grow: 1;
    padding: 20px 0;
}
</style>
