<template>
	<view :class="$isEmpty(deviceList) ? 'bg-white':''">
		<mescroll-body ref="mescrollRef" @init="mescrollInit" @down="downCallback" @up="upCallback" :down="downOption"
			:up="upOption">
			<device-card :list="deviceList"></device-card>
		</mescroll-body>
		<view class="footer-fixed" v-if="$isNotEmpty(deviceList)">
			<view class="margin">
				<u-button type="primary" shape="circle" @click="subscribeMessage">订阅设备告警通知</u-button>
			</view>
		</view>
	</view>
</template>

<script>
	var app = getApp();
	import MescrollMixin from "@/comps/mescroll-body/mescroll-mixins.js";
	import DeviceCard from "@/comps/device-card.vue";
	import DtEmpty from '@/comps/dt_empty.vue';
	export default {
		mixins: [MescrollMixin], // 使用mixin
		components: {
			DeviceCard,
			DtEmpty
		},
		data() {
			return {
				deviceList: [],
			}
		},
		onLoad() {

		},
		methods: {
			//订阅消息通知
			subscribeMessage() {
				this.$util.subscribe(["nSBYQTAe7wtQFPyHLXkacYF3IxwkYKjzWxsiVMzx-xM"]);
			},
			downCallback(mescroll) {
				setTimeout(() => {
					this.mescroll.resetUpScroll()
				}, 200)
			},
			upCallback(mescroll) {
				let residentialId=uni.getStorageSync("residentialId")
				if (this.$isEmpty(this.vuex_member)||this.$isEmpty(residentialId)) {
					this.mescroll.endErr()
					return
				}
				let that = this;
				let params = {
					memberId: this.vuex_member.id,
					residentialId
				}
				try {
					that.$http.iotDeviceList(params).then(res => {
						let data = res.data.iotDevices;
						mescroll.endSuccess(data.length);
						if (mescroll.num == 1) {
							that.deviceList = []; //如果是第一页需手动制空列表
						}
						that.deviceList = that.deviceList.concat(data); //追加新数据
					});

				} catch (e) {
					this.mescroll.endErr()
				}
			}
		}
	}
</script>

<style lang="scss" scoped>

</style>
