<template>
	<view class="device-detail">
		<app-top-push-notice />
		<!-- 顶部导航 -->
        <view class="tabback">
            <view class="rtjt" @click="btnback" style="font-size: 50rpx;">←</view>
            <view class="name">{{ getSecurityCompanyText() }}</view>
			<view style="width: 36rpx;"></view>
		</view>
		<view class="" style="color: #757575;padding-left: 32rpx;margin-top: 20rpx;margin-bottom: 20rpx;">
			{{ getCompanyListText() }}
		</view>
		<scroll-view class="guanli" scroll-y @scrolltolower="handqixing">
			<view class="hezi" style="border-bottom: 1px solid #D8D8D8;" v-for="(item,index) in anbaolist" :key="index" @click="btnitem(item)">
				<view class="lt">
					<image :src="item.logo" mode="aspectFill"></image>
					{{item.name}}
				</view>
				<image style="width: 48rpx;height: 48rpx;" src="https://api.ccttiot.com/smartmeter/img/static/uGFlq3Y6VPGsCUv6lfid" mode=""></image>
			</view>
		</scroll-view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
                anbaolist:[],
				pageNum:1,
				total:0,
				spaceId: ''
			}
		},
		onLoad(option) {
			this.spaceId = option.spaceId || ''
            this.getxq()
		},
		mounted() {
			// 监听语言变化事件
			uni.$on('languageChanged', this.handleLanguageChange)
		},
		beforeDestroy() {
			// 移除事件监听
			uni.$off('languageChanged', this.handleLanguageChange)
		},
		methods: {
			// 处理语言变化
			handleLanguageChange(lang) {
				console.log('安全公司页面语言切换事件:', lang)
				this.$forceUpdate()
			},
			// 获取安全公司文本
			getSecurityCompanyText() {
				// 添加容错处理
				const t = this.$i18n && this.$i18n.t ? this.$i18n.t.bind(this.$i18n) : (key) => key
				return t('securityCompany') || '安全公司'
			},
			// 获取公司列表文本
			getCompanyListText() {
				// 添加容错处理
				const t = this.$i18n && this.$i18n.t ? this.$i18n.t.bind(this.$i18n) : (key) => key
				return t('companyList') || '公司列表'
			},
			// 请求列表信息
			getxq(){
				this.$http.get(`/app/company/list?pageNum=${this.pageNum}&pageSize=10&type=2`).then(res =>{
					if(res.code == 200){
						this.total = res.total
						if(this.pageNum == 1){
							this.anbaolist = res.rows
							this.pageNum++
						}else{
							this.anbaolist = this.anbaolist.concat(res.rows)
							this.pageNum++
						}
					}
				})
			},
			handqixing(){
				console.log(11);
				if(this.total > this.anbaolist.length){
					this.getxq()
				}
			},
			// 点击跳转到详情
			btnitem(item){
				uni.navigateTo({
					url: '/pages/kongjian/anquanxq?id=' + item.id + '&spaceId=' + encodeURIComponent(this.spaceId || '')
				})
			},
			// 点击返回上一级
			btnback(){
				uni.navigateBack()
			}
		}
	}
</script>

<style scoped lang="less">
	.guanli{
		background-color: #fff;
		height: 83vh;
		.hezi{
			display: flex;
			justify-content: space-between;
			height: 122rpx;
			align-items: center;
			padding: 0 32rpx;
			.lt{
				font-size: 30rpx;
				color: #3D3D3D;
				display: flex;
				align-items: center;
				image{
					width: 92rpx;
					height: 92rpx;
					background: #D8D8D8;
					border-radius: 6rpx 6rpx 6rpx 6rpx;
					margin-right: 50rpx;
				}
			}
			.rt{
				
			}
		}
	}
	.device-detail{
		background-color: #F3F5F6;
	}
	.tabback {
		display: flex;
		align-items: center;
		justify-content: space-between;
		width: 100%;
		height: 100rpx;
		padding: 0 20rpx;
		box-sizing: border-box;
		background-color: #fff;
		margin-top: 80rpx;
		box-shadow: 0rpx 0rpx 0rpx 0rpx;
		.rtjt {
			font-size: 36rpx;
			color: #333;
		}
		.name {
			font-size: 36rpx;
			font-weight: bold;
			color: #333;
		}
	}

	.device-detail {
		height: 93vh;
	}

</style>