<template>
	<view class="page">
		<u-navbar title="店铺详情" :border-bottom="false" :background="bgc" title-color='#000' back-icon-color="#000" title-size='36' height='50'></u-navbar>
        <view class="box">
        	<view class="shopname">
                {{listobj.name}}        		
        	</view>
			<view class="shoplist">
				<view class="tit">
					基本信息
				</view>
				<view class="jiben">
					<text class="qian">设备数量：</text> <text class="shen">{{listobj.cabinetCount}}</text>
				</view>
				<view class="jiben">
					<text class="qian">营业时间：</text> <text class="shen">{{listobj.businessTimeStart}}~{{listobj.businessTimeEnd}}</text>
				</view>
				<view class="jiben">
					<text class="qian">详细地址：</text> <text class="shen">{{listobj.address}}</text>
				</view>
				<view class="jiben">
					<text class="qian">创建时间：</text> <text class="shen">{{listobj.createTime}}</text>
				</view>
			</view>
			<view class="icons">
				<image v-if="flag" src="https://api.ccttiot.com/smartmeter/img/static/uZEG6wcsyjAlik8iKnBZ" mode="" @click="btnpag(1)"></image>
				<image v-if="flag" src="https://api.ccttiot.com/smartmeter/img/static/u3GbElGkYzgolFDVMcRF" mode="" @click="btnpag(2)"></image>
				<image v-if="flag" src="https://api.ccttiot.com/smartmeter/img/static/umSzDeyl29aEeJDXY3lT" mode="" @click="btnpag(3)"></image>
				<image v-if="flag" src="https://api.ccttiot.com/smartmeter/img/static/u54XmWWxo1l0yY1mZtcG" mode="" @click="btnpag(4)"></image>
				<image v-if="flags" src="https://api.ccttiot.com/smartmeter/img/static/urIxP74GyW2Puz4uqfN9" style="width: 54rpx;" mode="" @click="btnpag(5)"></image>
			</view>
        </view>
		
	</view>
</template>

<script>
	export default {
		data() {
			return {
				show: false,
				storeId:'',
				listobj:{},
				flag:false,
				flags:false,
				cabinetSn:''
			}
		},
		onLoad(option) {
			this.storeId = option.storeId
			let userdata  = uni.getStorageSync('userdata').permissions
	        if (Array.isArray(userdata) && userdata.includes('agent:store:operation')) {  
	            this.flag = true
	        } else {  
	            this.flag = false
	        }  
			if (Array.isArray(userdata) && userdata.includes('agent:device:show')) {
			    this.flags = true
			} else {  
			    this.flags = false
			}  
			this.getdetail()
		},
		methods: {
			getdetail(){
				this.$u.get(`/agent/store/${this.storeId}`).then(res => {
					if (res.code == 200) {
						this.listobj = res.data[0]
					}
				})
			},
			
			
			btnpag(num){
				if(num == 1){
					uni.navigateTo({
						url:'/page_user/jifei?storeId=' + this.listobj.storeId 
					})
				}else if(num == 2){
					uni.navigateTo({
						url:'/page_user/shopedit?obj=' + JSON.stringify(this.listobj)
					})
				}else if(num == 3){
					let vm = this
					uni.showModal({  
					    title: '提示',  
					    content: '你确定要注销这个店铺吗？',  
					    success: function (res) {  
					        if (res.confirm) {  
								vm.$u.delete(`/agent/store/${vm.storeId}`).then(res => {
									if (res.code == 200) {
										uni.showToast({
											title: '注销成功',
											icon: 'success',
											duration: 1000
										})
										setTimeout(()=>{
											uni.navigateBack()
										},1500)
									}else if(res.code == 500){
										uni.showToast({
											title: res.msg,
											icon: 'none',
											duration: 1000
										})
									}
								})
					        } else if (res.cancel) {  
					            console.log('用户点击了取消');  
					        }  
					    }  
					});
				}else if(num == 4){
					uni.scanCode({
						onlyFromCamera: true,
						scanType: ['qrCode'],
						success: res => {
							console.log('扫描结果：', res);
							this.cabinetSn = res.result
							this.$u.put(`/agent/cabinet/${this.cabinetSn}/bind/${this.storeId}`).then(res => {
								if(res.code == 200){
									uni.showToast({
										title: '绑定成功',
										icon: 'success',
										duration:2000
									});
								}
							})
						},
						fail: err => {
							console.error('扫描失败：', err);
							uni.showToast({
								title: '扫描失败',
								icon: 'none'
							});
						}
					});
				}else if(num == 5){
					uni.navigateTo({
						url:'/pages/agentpages/devicemanagement/chargepallist/index?storeId=' + this.storeId
					})
				}
			},
			
             confirm(e) {
             	let type = e[0].value
             	if (type == '1') {
             		this.scanQRCode()
             	} else if (type == '2') {
             		uni.navigateTo({
             			url: '/page_fenbao/device/index'
             		})
             	}
             },
			 scanQRCode() {
			 	uni.scanCode({
			 		onlyFromCamera: true,
			 		scanType: ['qrCode'],
			 		success: res => {
			 			console.log('扫描结果：', res);
			 			this.qrResult = res.result; // 将扫描结果存储在数据中
			 		},
			 		fail: err => {
			 			console.error('扫描失败：', err);
			 			uni.showToast({
			 				title: '扫描失败',
			 				icon: 'none'
			 			});
			 		}
			 	});
			 },
			 
		}
	}
</script>

<style lang="scss">
	/deep/ .u-title,
	/deep/ .uicon-nav-back {
		padding-bottom: 22rpx;
	}
	
	page {
		background: linear-gradient(180deg, #54DAA1 0%, rgba(255, 255, 255, 0) 100%);
	}

	.page {
		width: 750rpx;
		position: fixed;
		top: 0;
		left: 0;
		.box{
			width: 750rpx;
			height: 1440rpx;
			background: #F4F5F7;
			border-radius: 0rpx 0rpx 0rpx 0rpx;
			padding: 22rpx 36rpx;
			box-sizing: border-box;
			.shopname{
				width: 680rpx;
				height: 102rpx;
				background: #FFFFFF;
				border-radius: 24rpx 24rpx 24rpx 24rpx;
				margin: auto;
				padding-left: 30rpx;
				padding-top: 30rpx;
				font-weight: 600;
				font-size: 32rpx;
				color: #3D3D3D;
			}
			.shoplist{
				padding: 30rpx;
				box-sizing: border-box;
				width: 680rpx;
				height: 376rpx;
				background: #FFFFFF;
				border-radius: 24rpx 24rpx 24rpx 24rpx;
				margin-top: 24rpx;
				.tit{
					font-weight: 600;
					font-size: 28rpx;
					color: #3D3D3D;
				}
				.jiben{
					margin-top: 16rpx;
					display: flex;
					justify-content: space-between;
					.qian{
						font-size: 24rpx;
						color: #808080;
						width: 40%;
						// margin-right: 20rpx;
					}
					.shen{
						font-size: 24rpx;
						color: #3D3D3D;
					}
				}
			}
			.icons{
				padding-top: 30rpx;
				padding-left: 50rpx;
				padding-right: 50rpx;
				box-sizing: border-box;
				flex-wrap: wrap;
				width: 680rpx;
				height: 170rpx;
				background: #FFFFFF;
				border-radius: 24rpx 24rpx 24rpx 24rpx;
				margin: auto;
				display: flex;
				justify-content: space-between;
				margin-top: 26rpx;
				image{
					width: 96rpx;
					height: 96rpx;
				}
			}
		}
	}
</style>