<template>
    <div class="custom-table">
        <el-table
                :data="tableData"
                border
                style="width: 100%"
                v-loading="loading">
            <el-table-column type="index" align="center" label="序号" width="80"/>
            <el-table-column prop="comment_content" show-overflow-tooltip label="评论内容" align="center"/>
            <el-table-column prop="org_name" show-overflow-tooltip label="机构" align="center"/>
<!--            序号、内容、机构、姓名、电话、时间-->
            <el-table-column prop="update_user_name" show-overflow-tooltip label="姓名" align="center"/>
            <el-table-column prop="phone_number" show-overflow-tooltip label="电话" align="center"/>
            <el-table-column prop="update_time" show-overflow-tooltip label="时间" align="center">
                <template slot-scope="scope">{{ formatDate(scope.row.update_time, true) }}</template>
            </el-table-column>

        </el-table>
        <div class="custom-pagination">
            <div class="info">
                <span>共 {{ total }} 条记录</span>
                <span>第 {{ query.page }} / {{ pageTotal }} 页</span>
            </div>
            <el-pagination
                    background
                    class="custom-page"
                    layout="prev, pager, next, sizes"
                    :page-sizes="[10, 20, 50, 100]"
                    :current-page="query.page"
                    :page-size="query.size"
                    :total="total"
                    @size-change="handleSizeChange"
                    @current-change="handleCurrentChange">
            </el-pagination>
        </div>
    </div>
</template>

<script>
    import {getComment} from '@/api/check'
    import {jobMixin} from '@/mixin/job'
    import {resourceMixin} from '@/mixin/resource'
    import {formatDate} from '@/utils/tool'

    export default {
        computed: {
            pageTotal() {
                const page = Math.ceil(this.total / this.query.size)
                return page > 0 ? page : 1
            }
        },
        props: {
            template_item: {
                type: Object,
                required: true
            }
        },
        mixins: [jobMixin, resourceMixin],
        data() {
            return {
                loading: false,
                formData: {
                    job_status: '',
                    org: '',
                    account: '',
                    checkDate: '',
                    company: '',
                    limit: '',
                    createDate: '',
                    result: '',
                },
                query: {
                    page: 1,
                    size: 10
                },
                total: 0,
                tableData: []
            }
        },
        mounted() {
            this.handleQuery()
        },
        methods: {
            formatDate,
            handleSizeChange(val) {
                this.query.size = val
                this.handleQuery()
            },
            handleCurrentChange(val) {
                this.query.page = val
                this.handleQuery()
            },
            handleQuery() {
                this.loading = true
                let query = this.query.query || '';
                query = "template_item_id==" + this.template_item.id+";comment_type=='CRITICISM'";
                this.query.query = query;
                getComment(this.query).then(res => {
                    if (res) {
                        this.total = res.total || 0
                        const list = res.data || []
                        list.map(item => {
                            item.start_time = formatDate(item.start_time, true)
                        })
                        this.tableData = list
                    }
                    this.loading = false
                })
            }
        }
    }
</script>