<template>
    <view class="box">
        <template v-if="failDetaiList.length > 0">
            <view
                class="meauList"
                v-for="item in failDetaiList"
                :key="item.devId"
            >
                <view class="menu-item">
                    <view class="meanLeft">
                        <text>设备名称</text>
                    </view>
                    <view class="meanRight">
                        <text>{{ devInfo.devName }}</text></view
                    >
                </view>
                <view class="menu-item">
                    <view class="meanLeft">
                        <text>设备序列号</text>
                    </view>
                    <view class="meanRight">
                        <text>{{ devInfo.clientId }}</text></view
                    >
                </view>
                <view class="menu-item">
                    <view class="meanLeft">
                        <text>设备ID</text>
                    </view>
                    <view class="meanRight">
                        <text>{{ item.devId }}</text></view
                    >
                </view>
                <view class="menu-item">
                    <view class="meanLeft">
                        <text>事件类型</text>
                    </view>
                    <view class="meanRight"> <text>确认跌倒</text></view>
                </view>

                <view class="menu-item">
                    <view class="meanLeft">
                        <text>跌倒时间</text>
                    </view>
                    <view class="meanRight">
                        <text>{{ item.createTime }}</text></view
                    >
                </view>
            </view>
        </template>
        <template v-else>
            <view class="noEvent">暂无跌倒事件</view>
        </template>
    </view>
</template>

<script>
export default {
    data() {
        return {
            status: null,
            devInfo: "",
            failDetaiList: [],
            pageNo: 1,
            onReachJudge: true,
        };
    },
    methods: {
        getFailDetaiList() {
            if (!this.onReachJudge) return;
            this.$http
                .post(
                    "wap/stats/fallQuery",
                    {
                        pageNo: 1,
                        pageSize: 10,
                        devId: this.devInfo.devId,
                    },
                    {
                        header: {
                            "Content-Type": "application/json;charset=UTF-8",
                            token: uni.getStorageSync("tokenValue") || "",
                        },
                    }
                )
                .then((res) => {
                    if (res.data.data) {
                        if (res.data.data.rows.length > 0) {
                            this.failDetaiList = this.failDetaiList.concat(
                                res.data.data.rows
                            );
                        }
                        if (this.failDetaiList.length == res.data.data.total) {
                            this.onReachJudge = false;
                        }
                    }
                });
        },
        searchFailDetail() {
            this.pageNo = 1;
            this.failDetaiList = [];
            this.getFailDetaiList();
        },
    },
    onShow() {},
    onLoad(options) {
        this.devInfo = JSON.parse(options.devInfo);
        this.searchFailDetail();
    },
    onPullDownRefresh() {
        this.getFailDetaiList();
        setTimeout(() => {
            uni.stopPullDownRefresh();
        }, 1000);
    },
    onReachBottom() {
        this.pageNo += 1;
        this.getFailDetaiList();
    },
};
</script>

<style lang="less" scoped>
// Main Styles
.box {
    padding: 10rpx 18rpx;
    width: 100vw;
    height: 100vh;
    background: linear-gradient(180deg, #faede2 0%, #f4f4f4 100%);
    box-sizing: border-box;
    .meauList {
        width: 710rpx;
        margin: 18rpx auto;
        background: #fff;
        border-radius: 16rpx;
        box-shadow: 0 4rpx 16rpx rgba(0, 0, 0, 0.08);
        overflow: hidden;
        transition: all 0.3s ease;

        .menu-item {
            display: flex;
            align-items: center;
            justify-content: space-between;
            margin: 0 32rpx;
            padding: 32rpx 0;
            border-bottom: 1rpx solid #f0f0f0;

            &:last-of-type {
                border-bottom: none;
            }

            .meanLeft {
                flex: 1;
                color: #666;
                font-size: 28rpx;
                font-weight: 400;
            }

            .meanRight {
                flex: 1;
                text-align: right;
                color: #333;
                font-size: 28rpx;
                font-weight: 500;
                padding-left: 20rpx;
            }
        }

        .menu-bottom {
            display: flex;
            padding: 24rpx 32rpx;
            border-top: 1rpx solid #f0f0f0;

            .meanLeft,
            .meanRight {
                flex: 1;
                height: 80rpx;
                display: flex;
                align-items: center;
                justify-content: center;
                border-radius: 8rpx;
                font-size: 30rpx;
                font-weight: 500;
                transition: all 0.2s;

                &:active {
                    opacity: 0.8;
                }
            }

            .meanLeft {
                background: #7b5245;
                color: white;
                margin-right: 16rpx;
            }

            .meanRight {
                background: fade(#ff4d4f, 10%);
                color: #ff4d4f;
                border: 1rpx solid fade(#ff4d4f, 30%);
            }
        }
    }
    .noEvent {
        text-align: center;
        font-size: 28rpx;
        color: #999;
        padding: 20rpx 0;
    }
}
</style>
