<template>
    <div>
        <el-table
            :data="tableData"
            border
            style="width: 100%">
            <el-table-column
                label="选择"
                width="180"
                align="center">
                <template slot-scope="scope">
                    <div>
                        <el-radio v-model="templateId" @input="getTemplateId(scope.row.id)"></el-radio>
                    </div>
                </template>
            </el-table-column>
            <el-table-column
                prop="templateName"
                label="模板名称"
                width="180"
                align="center">
            </el-table-column>
            <el-table-column
                prop="reportType"
                label="所属报告类型"
                width="180"
                align="center">
                <template slot-scope="scope">
                    <div>
                        {{dictMessage[scope.row.reportType]}}
                    </div>
                </template>
            </el-table-column>
            <el-table-column
                prop="personName"
                label="创建人"
                align="center">
            </el-table-column>
            <el-table-column
                prop="createTime"
                label="创建日期"
                align="center">
            </el-table-column>
        </el-table>
        <div class="pagination">
            <el-pagination :current-page.sync="queryParams.current" :page-size="queryParams.size" :total="total" @current-change="handleCurrentChange" layout="total, prev, pager, next, jumper" background></el-pagination>
          </div>
    </div>
</template>

<script>
export default {
    props:['reportType'],
    data() {
        return {
            templateId:'',
            tableData:[],
            queryParams:{
                size:10,
                current:1,
                reportType:this.reportType
            },
            total:0
        }
    },
    watch:{
        reportType(val){
            if(val == ''){
                this.templateId = ''
            }else{
                this.queryParams.reportType = val
                this.getList()
            }
            
        }
    },
    computed:{
        dictMessage() {
            var a = this.$store.state.dictMessage.dictMessage.REPORT_TYPE
            var b = []
            a.forEach(item => {
                b[item.dictChildValue] = item.dictChildLabel
            });
            // console.log(b)
            return b
        },
    },
    mounted() {
        this.getList()
    },
    methods: {
        getList(){
            this.$api.getTemplateByType(this.queryParams).then(response=>{
                if(response.code == 200){
                    console.log(response.data)
                    this.tableData = response.data.records
                    this.total = response.data.total
                }
            })
        },
        handleCurrentChange(val) {//分页
            this.queryParams.current = val
            this.getList()
        },
        getTemplateId(val){
            console.log(val)
            this.$emit('getReportTemplateId',val)
        },
    },
}
</script>