//调节记录
<style lang="less">
page {
    height: 100%;
    background-color: #f3f3f3;
}
.page-container {
    width: 100%;
    height: 100%;
    box-sizing: border-box;
    position: relative;
    font-family: PingFang SC;
    .energyHead {
        padding: 34rpx 44rpx 32rpx;
        font-size: 40rpx;
        color: #000;
    }
    .eachMonth {
        background: #fff;
        padding-left: 44rpx;
        .dateTitle {
            padding: 50rpx 0 40rpx 0;
        }
        .eachItem {
            display: flex;
            flex-wrap: nowrap;
            // justify-content: flex-start;
            align-items: center;
            height: 50px;
            // padding-top: 10rpx;
            // padding-bottom: 20rpx;
            padding-right: 38rpx;
            // width: 100%;
            box-sizing: border-box;
            border-bottom: 1px solid #e6e6e6;
            white-space: nowrap;
            // line-height: 58rpx;
            .leftCont {
                color: #c4c4c4;
                font-size: 22rpx;
                width: 160rpx;
                // flex-shrink: 0;
                .date {
                }
                .time {
                    padding-left: 5rpx;
                }
            }
            .spanceName {
                flex: 1;
                padding-left: 20rpx;
                box-sizing: border-box;
                color: #000;
                font-size: 28rpx;
                white-space: nowrap;
                text-overflow: ellipsis;
                overflow: hidden;
            }
            .secondLine {
                width: 240rpx;
                padding-left: 37rpx;
                box-sizing: border-box;
                color: #c4c4c4;
                font-size: 24rpx;
                white-space: nowrap;
            }
        }
    }
    .nodata {
        text-align: center;
        color: #c4c4c4;
        position: absolute;
        top: 50%;
        left: 0;
        width: 100%;
        transform: translate(0px, -100px);
        .nodataImg {
            width: 100%;
            image {
                width: 96px;
                height: 96px;
            }
        }
        .firstTitle {
            font-size: 34rpx;
        }
        .secondTitle {
            margin-top: 6px;
            font-size: 26rpx;
        }
    }
    .bottomCont {
        height: 80rpx;
    }
    .logo-text {
        display: flex;
        justify-content: center;
        width: 100%;
        height: 24rpx;
        padding: 98rpx 0 80rpx;
        margin-top: 80rpx;
    }
}
</style>

<template>
    <div class="page-container">
        <div
            class="energyHead"
            v-if="!listNoData"
        >
            调节记录
        </div>
        <div
            class="eachMonth"
            v-for="monthItem in ajustList"
            v-if="!listNoData"
        >
            <div class="dateTitle">{{monthItem.date}}</div>
            <div
                class="eachItem"
                v-for="item in monthItem.dataArr"
            >
                <div class="leftCont">
                    <span class="date">{{item.showDate?item.showDate:'--'}}</span>
                    <span class="time">{{item.showTime?item.showTime:'--'}}</span>
                </div>
                <div class="spanceName">{{item.spaceName?item.spaceName:'--'}}</div>
                <div class="secondLine">{{item.details?item.details:'--'}}</div>

            </div>
        </div>
        <div v-show="totalGet">
            <image
                class="logo-text"
                src="{{h5StaticPath}}/page-home/tenatslink.svg"
            ></image>
        </div>
        <div
            class="nodata"
            v-show="listNoData"
        >
            <div class="nodataImg">
                <image
                    :src="h5StaticPath+'/page-portrait/nodata.png'"
                    mode="widthFix"
                />
            </div>
            <div class="firstTitle">您还没有调节记录</div>
        </div>
    </div>
</template>

<script>
import wepy from '@wepy/core';
import store from '@/store';
import config from '@/config';
import { mapState } from '@wepy/x';
import moment from 'moment';
import { tempFeedbackQuery, lightFeedbackQuery } from '@/packagesEnv/api/portrait';

wepy.page({
    store,
    data: {
        totalPoints: '',
        ajustList: [],
        page: 1,
        pageCount: 14,
        totalPage: 0,
        totalGet: false,
        listNoData: false,
        from: '',
        h5StaticPath: config.h5StaticPath,
    },
    computed: {
        ...mapState({ token: state => state.user.token })
    },
    onLoad(routeParams) {
        var from = routeParams.from;
        this.from = from;
        console.log('from', from);
        this.getFeedbackQuery();
    },
    onReady() { },
    onReachBottom() {
        // wx.showToast({
        //     title: this.page+','+this.totalPage,
        //     icon: 'none',
        //     duration: 5000
        // })
        if (this.page == this.totalPage) return;
        this.page++;
        wx.showLoading({
            title: '加载中',
        })
        this.getFeedbackQuery();

    },
    methods: {
        getFeedbackQuery() {//按照分页  获取所有的积分记录
            var _this = this;
            var param = {
                "orders": [
                    {
                        "column": "createTime",
                        "asc": false
                    }
                ],
                "page": _this.page,
                "size": _this.pageCount
            };
            var queryFunction = null;
            if (this.from == 'temp') {
                Object.assign(param, {
                    criteria: {
                        "itemId": {
                            "$in": [
                                1,
                                2,
                                3,
                                4,
                                5,
                                6,
                                10,
                                12
                            ]
                        }
                    }
                });
                queryFunction = tempFeedbackQuery;
                console.log('param2', param);
                console.log('queryFunction2', tempFeedbackQuery);

            } else {
                queryFunction = lightFeedbackQuery;
            }

            queryFunction(param).then((res) => {
                console.log('queryAllIntegral2', res);
                var allRes = res.content || [];
                _this.totalPage = Math.ceil((res.count || 0) / _this.pageCount);
                _this.totalGet = _this.totalPage == _this.page ? true : false;
                //var ajustList=this.ajustList;
                allRes.forEach(function (item) {
                    item.showDate = moment(item.createTime).format('MM月DD日');

                    item.showTime = moment(item.createTime).format('HH:mm');
                    if (_this.from == 'temp') {
                        // item.details = (item.itemId == 1 || item.itemId == 2) ? '空调温度调高一次' : '空调温度调低一次';
                        switch (item.itemId) {
                            case 1:
                            case 2:
                                item.details = '空调温度调高';
                                break;
                            case 3:
                            case 4:
                                item.details = '空调温度调低';
                                break;
                            case 5:
                                item.details = '空调风量调小';
                                break;
                            case 6:
                                item.details = '空调风量调大';
                                break;
                            case 10:
                                item.details = '关闭空调';
                                break;
                            case 12:
                                item.details = '开启空调';
                                break;
                        }
                    } else {
                        item.details = item.onOff ? '照明开启' : '照明关闭';
                    }

                    var datestr = moment(item.createTime).format('YYYY年MM月');

                    var lastMonthObj = _this.ajustList[_this.ajustList.length - 1] || {};
                    if (lastMonthObj.date == datestr) {
                        lastMonthObj.dataArr.push(item);
                    } else {
                        var newMonthObj = {
                            date: datestr,
                            dataArr: []
                        };
                        newMonthObj.dataArr.push(item);
                        _this.ajustList.push(newMonthObj);
                    }
                });
                _this.listNoData = _this.ajustList.length == 0 ? true : false;
                wx.hideLoading();
            })
        },
        showPointExplain() {
 
            console.log('fsd');
            wx.navigateTo({
                url: './pointExplain'
            });
        }
    }
});
</script>

<config>
{
    'navigationBarBackgroundColor': '#f3f3f3',
    'navigationBarTextStyle':'black',
    'backgroundColor': '#f3f3f3',
    'onReachBottomDistance':30,
    'navigationBarTitleText': '',
        usingComponents: {
      
    }

}
</config>
