<template>
	<view class="billall">
		<view class="u-listdata">
			<view style="padding: 16rpx 0 16rpx 32rpx">
				共有 <span style="color: red">{{ totalnumber }}</span>条记录
			</view>

			<u-list @scrolltolower="scrolltolower" :pagingEnabled="true">
				<u-list-item v-for="(item, index) in indexList" :key="index">
					<view class="companylist">
						<h3>{{ item.name }}</h3>
						<view class="Currentamount"> 设备编号:{{ item.deviceId }} </view>
						<view class="Callfee">
							<span @click="kaimen(item)">开门记录</span>
							<span @click="Remotedooropening(item)">远程开门</span>
							<span @click="confirmPwd(item.deviceId)">临时密码</span>
							<span @click="seedetail(item)">查看租户</span>
						</view>
					</view>
				</u-list-item>
			</u-list>
		</view>
		<!-- 门锁信息 -->
		<!-- <u-modal :show="showms" @confirm="confirmPwd" title="临时密码设置" :showCancelButton="true" @cancel="showms = false">
			<view class="slot-content">
				<u--input placeholder="请输入临时密码" v-model="lsmima"></u--input>
			</view>
		</u-modal> -->
		<u-notify ref="uNotify" message=""></u-notify>
	</view>
</template>

<script>
	export default {
		components: {},
		data() {
			return {
				showms: false,
				totalnumber: 0,
				setyesno: true,
				lsmima: "",
				indexList: [],
				dataList: [],
				dataForm: {
					currentPage: 1,
					deviceId: "",
					pageSize: 10,
					roomId: "",
					tempPwd: "",
					tenantsId: "",
					userName: "",
				},
				showtype: false,
				showdct: false,
				mytitle: "",
				alldata: [],
				showfloor: false,
				loading: false,
				columns: [],
				pd: true,
				columnData: [],
				myday: "",
				mytype: "全部",
				showPicker: false,
			};
		},
		//监听页面加载，其参数为上个页面传递的数据，参数类型为 Object（用于页面传参
		onLoad() {
			this.getalldata();
		},
		//监听页面初次渲染完成。注意如果渲染速度快，会在页面进入动画完成前触发
		onReady() {
			// 微信小程序需要用此写法
		},
		//监听页面隐藏
		onHide() {},
		//监听窗口尺寸变化
		onResize() {},
		//监听页面卸载
		onUnload() {},
		//监听用户下拉动作，一般用于下拉刷新
		onPullDownRefresh() {},

		methods: {
			Remotedooropening(e) {
				let postdata = {
					cmdType: "RemoteOpenDoor",
					roomId: e.roomid,
				};
				this.$api.post("/lock/issuedCmd", postdata).then((res) => {
					if (res.data.code == 0) {
						this.$refs.uNotify.success(res.data.data);
					} else {
						this.$refs.uNotify.error(res.data.msg);
					}
				});
			},

			seedetail(e) {
				uni.navigateTo({
					url: `/pages/Workorder/Intelligentdoorlock/Tenantdetails/Tenantdetails?companyOrgId=${e.roomid}`,
				});
			},
			kaimen(e) {
				uni.navigateTo({
					url: `/pages/Workorder/Intelligentdoorlock/Dooropeningrecord/Dooropeningrecord?companyOrgId=${e.roomid}`,
				});
			},
			// setPwd(deviceId) {
			// 	this.showms = true;
			// 	this.dataForm.deviceId = deviceId;
			// },
			confirmPwd(deviceId) {
				this.$api
					.post("/lock/getTempPwd", {
						tempPwd: '123456',
						deviceId: deviceId,
					})
					.then((res) => {
						if (res.data.code == 0) {
							this.showms = false;
							this.$refs.uNotify.success(res.data.msg);
						} else {
							this.$refs.uNotify.error(res.data.msg);
						}
					});
			},
			closems() {
				this.showms = false;
			},
			scrolltolower() {
				if (this.pd) {
					this.getalldata();
				} else {
					return;
				}
			},
			getalldata() {
				this.$api.post("/lock/page", this.dataForm).then((res) => {
					this.totalnumber = res.data.data.total;
					if (res.data.data.list.length != 0) {
						this.indexList.push(...res.data.data.list);
						this.dataForm.currentPage = this.dataForm.currentPage + 1;
						this.pd = true;
					} else {
						uni.showToast({
							title: "暂无更多数据了",
							icon: "none",
							duration: 1500,
						});
						this.pd = false;
					}
				});
			},
		},
	};
</script>

<style lang="scss">
	.Callfee{
		width: 100%;
		border-top: 1px solid #eee;
		padding: 20rpx 0;
		margin-top: 24rpx;
		display: flex;
		justify-content: flex-end;
		span{
			padding: 10rpx 16rpx;
			border: 1px solid #2E69EB;
			border-radius: 8rpx;
			font-size: 24rpx;
			color: #2E69EB;
			margin-right: 24rpx;
		}
	}

	.companylist {
		margin: 24rpx 32rpx 0;
		background: #fff;
		padding: 24rpx 32rpx 0;
		border-radius: 8rpx;
		position: relative;

		h3 {
			margin-bottom: 24rpx;
		}

		.Currentamount {
			margin-bottom: 4rpx;
			color: #999;

			span {
				color: #FA5555;
				padding-left: 9rpx;
			}
		}
	}
</style>