<template>
	<!-- 拼团商家详情页 -->
	<view class="page1">
		<view class="title">
			<view class="title-sreach">
				<view class="back-btn" @tap="back" :style="{'top': menuButtonInfo.top +'px'}">
					<uni-icons type="left" size="28"></uni-icons>
				</view>
				<view class="title-name" :style="{'padding-top': menuButtonInfo.top +'px'}">
					商家详情
				</view>
			</view>
		</view>
		<view class="content">
			<view class="box1" style="display: flex;">
				<view class="left">
					<view style="display: flex;">
						<img src="https://jewel-shop.oss-cn-beijing.aliyuncs.com/3721d2aa18ac4700aa7ac4dfeb272b09.png" alt="" style="width: 48rpx;height: 48rpx;"/>
						<text style="height: 48rpx;line-height: 48rpx;font-size: 28rpx;font-weight: 700;margin-left: 10rpx;">{{shopItem.shopName || ''}}</text>
					</view>
					<view style="line-height: 60rpx;height: 60rpx;color: #777;">
						<uni-icons type="location" size="13"></uni-icons>
						<text style="padding-left: 10rpx;">{{shopItem.shopAddress || '暂无地址'}}</text>
					</view>
					<view style="line-height: 60rpx;height: 60rpx;color: #777;">
						<uni-icons type="loop" size="13"></uni-icons>
						<text style="padding-left: 10rpx;">{{businessTimeText}}</text>
					</view>
				</view>
				<view class="right">
					<img @tap="makeCall(shopItem.contactPhone)" src="https://jewel-shop.oss-cn-beijing.aliyuncs.com/869a7af6a1c24bf3a0d523c4a18b55c6.png" alt=""  style="width: 60rpx;height: 60rpx;position: absolute;top: 64rpx;right: 60rpx;"/>
				</view>
			</view>
			<view class="box1">
				<view style="display: flex;">
					<img src="https://jewel-shop.oss-cn-beijing.aliyuncs.com/86004fa6b60e477ea1622fc0bf4c99de.png" alt="" style="width: 48rpx;height: 48rpx;" />
					<text style="height: 48rpx;line-height: 48rpx;font-size: 28rpx;font-weight: 700;margin-left: 10rpx;">
						商家资质
					</text>
				</view>
				<view style="display: flex;margin-top: 20rpx;">
					<img @tap="largeImg(item)" :src="item" v-for="(item,index) in shopImages" :key="index" alt="" style="width: 156rpx;height: 48rpx;margin-right: 40rpx;" />
					<text v-if="shopImages.length == 0" style="color: #777;">暂无资质图片</text>
				</view>
			</view>
			<view class="box1">
				<view style="display: flex;">
					<img src="https://jewel-shop.oss-cn-beijing.aliyuncs.com/00b1f011787c4549bbea650d95a4eb39.png" alt="" style="width: 48rpx;height: 48rpx;" />
					<text style="height: 48rpx;line-height: 48rpx;font-size: 28rpx;font-weight: 700;margin-left: 10rpx;">商家公告</text>
				</view>
				<view style="color: #777;line-height: 48rpx;margin-top: 20rpx;">
					公告：{{shopItem.remark || '暂无公告'}}
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				menuButtonInfo: {},
				isPintuan:true,
				shopItem:{},
				shopImages:[]
			}
		},
		computed: {
			businessTimeText() {
				const takeaway = this.shopItem.shopTakeaway || {};
				if (!takeaway.businessHourBegin || !takeaway.businessHourEnd) return '营业时间暂无';
				return '周一到周日 ' + takeaway.businessHourBegin + '-' + takeaway.businessHourEnd;
			}
		},
		components: {
	
		},
		onLoad(option) {
			this.initShopItem(option)
		},
		onShow() {
			this.menuButtonInfo = uni.getMenuButtonBoundingClientRect()
		},
		methods: {
			initShopItem(option) {
				const cacheItem = uni.getStorageSync('groupShopDetail');
				if (cacheItem) {
					this.shopItem = cacheItem;
				} else if (option.item) {
					this.shopItem = this.parseRouteItem(option.item) || {};
				}
				this.setShopImages();
				if (option.id || this.shopItem.id) {
					this.getShopDetail(option.id || this.shopItem.id);
				}
			},
			parseRouteItem(item) {
				if (item == null || item === '') return null;
				try {
					return JSON.parse(decodeURIComponent(item));
				} catch (e) {
					try {
						return JSON.parse(item);
					} catch (err) {
						return null;
					}
				}
			},
			setShopImages() {
				if (!this.shopItem.shopImages) {
					this.shopImages = [];
					return;
				}
				this.shopImages = this.shopItem.shopImages.split('@@').filter(item => item && item !== 'undefined' && item !== 'null');
			},
			getShopDetail(id) {
				this.tui.request("/app/shop/getShopInfoById", "POST", {
					id: id,
					regionId: JSON.parse(uni.getStorageSync('area')).id
				}, false, false).then((res) => {
					if (res.code == 200 && res.result) {
						this.shopItem = res.result;
						uni.setStorageSync('groupShopDetail', res.result);
						this.setShopImages();
					}
					uni.hideLoading();
				}).catch(() => {});
			},
			//查看大图
			largeImg(img) {
				if (!img) return;
				uni.previewImage({
					current: img,
					urls: this.shopImages
				})
			},
			//拨打电话
			makeCall(phone) {
				uni.makePhoneCall({
					phoneNumber: phone
				});
			},
			back() {
				uni.navigateBack()
			}
		}
	
	}
</script>

<style lang="scss">
	page {
		width: 100%;
		height: 100%;
		font-size: 24rpx;
		background: #F5F8F5;
		color: #00231C;
	}
	
	.page1 {
		width: 100%;
		height: 100%;
		font-size: 24rpx;
		position: relative;
	}
	
	.title{
		background: url('https://jewel-shop.oss-cn-beijing.aliyuncs.com/8bc15960c2dc40268e295d6dd23aecce.png') no-repeat;
		width: 100%;
		height: 54%;
	}
	
	.content{
		position: absolute;
		top: 200rpx;
		width: 95%;
		margin-left: 2.5%;
	}
	
	.title-sreach{
		width: 100%;
		display: flex;
		height: 200rpx;
		position: relative;
	}
	
	.back-btn{
		position: absolute;
		bottom: 0;
		left: 20rpx;
	}
	.title-name{
		padding-top: 110rpx;
		font-size: 36rpx;
		font-weight: 700;
		flex: 1;
		text-align: center;
	}
	.box1{
		width: 95%;
		margin: 0 auto 20rpx;
		background: #fff;
		border-radius: 20rpx;
		    padding: 20rpx;
	}
	.left{
		width: 80%;
	}
	.right{
		width: 20%;
		height: 160rpx;
	}
</style>