<template>
    <el-table
        v-if='hztjTable.length>=0'
        :header-cell-style='{background:"rgba(245,246,247,1)",fontFamily:"MicrosoftYaHei",color:"rgba(100,108,115,1)",lineHeight:"16px",fontSize:"12px"}'
        v-loading='loading'
        :data='hztjTable'
        style='width: 100%'
        :summary-method='getSummaries'
        show-summary
        border
    >
        <el-table-column label='序号' type='index' width='60'></el-table-column>
        <el-table-column prop label='楼层' :show-overflow-tooltip='true' resizable>
            <template slot-scope='{row}'>{{row.floor||'--'}}</template>
        </el-table-column>
        <el-table-column prop='beforekf' label='总间数'>
            <template slot-scope='{row}'>{{row.beforekf||'--'}}</template>
        </el-table-column>
        <el-table-column prop='area' label='面积（㎡）'>
            <template slot-scope='{row}'>{{row.area||'--'}}</template>
        </el-table-column>
        <el-table-column prop label='记录日期' width='100'>
            <template slot-scope='{row}'>{{row.changedate?formatter(row.changedate):'--'}}</template>
        </el-table-column>
    </el-table>
</template>
<script>
import moment from 'moment'

export default {
    data() {
        return {}
    },
    props: ['hztjTable', 'loading'],
    methods: {
        formatter(date) {
            return moment.unix(date / 1000).format('YYYY.MM.DD')
        },
        getSummaries(param) {
            const { columns, data } = param

            const sums = []
            columns.forEach((column, index) => {
                if (index === 1) {
                    sums[index] = '小计'
                    return
                }
                const values = data.map(item => Number(item[column.property]))
                if (!values.every(value => isNaN(value))) {
                    sums[index] = values.reduce((prev, curr) => {
                        const value = Number(curr)
                        if (!isNaN(value)) {
                            return prev + curr
                        } else {
                            return prev
                        }
                    }, 0)
                    sums[index]
                } else {
                    sums[index] = ''
                }
            })
            return sums
        }
    }
}
</script>
<style lang="less">
</style>