var comment = {
    props: {
        list: {
            type: Array,
            default: function () {
                return []
            }
        }
    },
    template: '<div class="comment">' +
                    '<textarea class="textarea" placeholder="发表自己的观点"></textarea>' +
                    '<div class="send">发送</div>' +
                    '<div class="wrapper">' +
                        '<div class="list" v-for="item in list" :key="item.id">' +
                            '<div class="item">' +
                                '<p class="sender">' +
                                    '<img class="head" :src="item.commentMemHear" alt="">' +
                                    '<span class="nickname">{{ item.commentMemName }}</span>' +
                                '</p>' +
                                '<p class="text">{{ item.content }}</p>' +
                                '<p class="date">{{ item.oprTime | date }}</p>' +
                            '</div>' +
                        '</div>' +
                    '</div>' +
                '</div>',
    filters:{
        date(time){
            let oldDate = new Date(time)
            let newDate = new Date()
            var dayNum = "";
            var getTime = (newDate.getTime() - oldDate.getTime())/1000;

            if(getTime < 60*5){
                dayNum = "刚刚";
            }else if(getTime >= 60*5 && getTime < 60*60){
                dayNum = parseInt(getTime / 60) + "分钟前";
            }else if(getTime >= 3600 && getTime < 3600*24){
                dayNum = parseInt(getTime / 3600) + "小时前";
            }else if(getTime >= 3600 * 24 && getTime < 3600 * 24 * 30){
                dayNum = parseInt(getTime / 3600 / 24 ) + "天前";
            }
            if (dayNum != "") {
                return dayNum;
            }
            let year   = oldDate.getFullYear();
            let month  = oldDate.getMonth()+1;
            let day    = oldDate.getDate();
            let hour   = oldDate.getHours();
            let minute = oldDate.getMinutes();
            let second = oldDate.getSeconds();
            return year+"-"+month+"-"+day+" "+hour+":"+minute+":"+second;
        }
    },
}
Vue.component("comment", comment);