<template>
    <div class="component-vote-table">
        <Table border size='small' ref="selection" :columns="columns" :data="tableData" stripe></Table>
    </div>
</template>
<script>
    export default {
        props: {
            tableDatas: {
                type: Array,
                default:[]
            }
        },
        data(vm) {
            return {
                setScoreModal: false,
                downloadModal: false,
                mutualEvaluationModal: false,
                isSaveComment: false,
                currentUsedComment: null,
                userInfo: this.$store.state.userInfo,
                isScoreLoading: false,
                currentStudent: null,
                currentHw: null,
                currentScore: 100,
                currentComment: '',
                currentFileList: [],
                currentRateValue: 0,
                downloadList: [],
                usedCommentList: [],
                columns: [
                    {
                        title: vm.$t('vote.option'),
                        key: 'option',
                        render: (h, params) => {
                            return h('span', params.row.option === 'Null' ? vm.$t('vote.noVote') : params.row.option)
                        },
                    },
                    {
                        title: vm.$t('vote.rate'),
                        render: (h, params) => {
                            return h('Progress', {
                                props: {
                                    percent: parseInt(((params.row.result.length / this.studentsNum) * 100).toFixed(2)),
                                    strokeWidth: 18,
                                    textInside:true
                                }
                            })
                        }
                    },
                    {
                        title: '数量',
                        render: (h, params) => {
                            return h('span', params.row.result.length)
                        },
                    }
                ],
                tableData: [],
                commentList: [],
                studentsNum:0
            }
        },
        methods: {

            /**
             * 全选操作
             * @param status
             */
            handleSelectAll(status) {
                this.$refs.selection.selectAll(status);
            },

        },


        mounted() {
           
        },
        watch: {
            tableDatas: {
                handler(newValue) {
                    /** 编辑回显 */
                    console.log(newValue)
                    if (Array.isArray(newValue) && newValue.length) {
                        this.tableData = newValue

                        let sum = 0
                        newValue.forEach(item => {
                            sum += item.result.length
                        })

                        this.studentsNum = sum
                    } else {
                        this.tableData = []
                    }
                },
                deep: true
            }
        }
    }
</script>

<style lang="less">
    @import "./BaseVoteTable.less";
</style>