<template>
	<view class="container safe-area-inset-bottom">
		<MessageNotification />
		<view class="card">
			<image src="/static/empty/yhq.png" mode=""></image>
			<view class="store">
				<view class="name">
					<text>当前门店</text>
					{{infoList.store.name}}
				</view>
				<view class="info" v-if="infoList.store">
					<text class="iconfont icon-icon-"></text>
					营业时间 ：
					{{infoList.store.start_time }}-{{infoList.store.end_time  }}
				</view>
				<view class="info">
					<text class="iconfont icon-tel"></text>
					联系电话：
					{{infoList.store.mobile}}
				</view>
				<view class="info">
					<text class="iconfont icon-shouhuodizhi"></text>
					地址 ：&nbsp;&nbsp;
					{{infoList.store.position}}
				</view>
			</view>
		</view>

		<!-- 其他门店 -->
		<view class="list">
			<view class="title">
				其他门店
			</view>


			<!-- 空页 -->
			<view class="empty" v-if="storeinfo.length<=0">
				<image src="/static/empty/orders.png" mode="aspectFit"></image>
				<text>暂无门店信息</text>
			</view>


			<view class="item" @click="toChang(item.store.id)" v-for="(item,index) in storeinfo" :key="item.id">
				<view class="name">
					{{item.store.name}}
				</view>
				<view class="timer" v-if="item.store">
					营业时间：{{item.store.start_time  }}-{{item.store.end_time  }}
					&nbsp;</view>
				<view class="timer">地址：{{item.store.position}}</view>
			</view>
		</view>

	</view>
</template>

<script>
	import {
		storeChange,
		storeInfo,
		storeList
	} from '../../request/api/api'
	export default {
		data() {
			return {
				isshow: false,
				storeinfo: [],
				infoList: [],
				headerTitle: "", // 标题
			}
		},
		onLoad() {
			// this.getStore();
		},
		created() {
			this.getStore();
			this.getInfo();
		},
		onReady() {
			this.getStore();
			uni.setNavigationBarTitle({
				title: this.headerTitle,
				success() {
					console.log('success');
				}
			});
			uni.setNavigationBarColor({
				frontColor: '#000000', //前景颜色值，包括按钮、标题、状态栏的颜色，仅支持 #ffffff 和 #000000
			})
		},
		methods: {
			// 切换门店
			toChang(e) {
				// console.log(e, 'id');
				storeChange({
					method: "post",
					data: {
						store_id: e
					}
				}).then((res) => {
					if (res.data.errcode == 0) {
            uni.setStorageSync('store_id', e)
            uni.setStorageSync('stores_id', e)
						uni.showToast({
							title: '切换成功',
							duration: 2000,
							icon: "success"
						});
						// uni.removeStorageSync('stores_id')
						// setTimeout(() => {
						// 	uni.switchTab({
						// 		url: '/pages/home/home'
						// 	})
						// }, 2000)

            uni.switchTab({
              url: '/pages/home/home'
            })
					}
				})

				this.getStore();
			},

			// 门店列表
			getStore() {
				storeList({
					method: "post",
					data: {
						store_id: 11001
					}
				}).then((res) => {
					// console.log(res, 'list');
					if (res.data.errcode == 0) {
						this.storeinfo = res.data.data.list
					}
				})
			},

			// 门店信息
			getInfo() {
				storeInfo({
					method: "post",
					data: {
						store_id: uni.getStorageSync('store_id') || '11001',
					}
				}).then((res) => {
					// console.log(res, 'info');
					if (res.data.errcode == 0) {
						this.infoList = res.data.data
						this.headerTitle = this.infoList.store['name']
						uni.setNavigationBarTitle({
							title: this.headerTitle,
							success() {
								console.log(3333);
							}
						});
						uni.setNavigationBarColor({
							frontColor: '#000000', //前景颜色值，包括按钮、标题、状态栏的颜色，仅支持 #ffffff 和 #000000
						})
					}
				})
			},
		},
		mounted() {
			// this.getStore();
		},
		onShow() {
			// this.getStore();
		},
		onUnload() {
			// uni.removeStorageSync('store_id')
		},
		filters: {
			//过滤器 用于格式化时间
			dateFormat: function(value) {
				var date = new Date(value * 1000); //时间戳为10位需*1000，时间戳为13位的话不需乘1000
				var year = date.getFullYear();
				var month = ("0" + (date.getMonth() + 1)).slice(-2);
				var sdate = ("0" + date.getDate()).slice(-2);
				var hour = ("0" + date.getHours()).slice(-2);
				var minute = ("0" + date.getMinutes()).slice(-2);
				var second = ("0" + date.getSeconds()).slice(-2);
				// 拼接
				var result = hour + ":" + minute //+ ":" + second;
				// 返回
				return result;
			},
		},
	}
</script>

<style lang="scss" scoped>
	.container {
		width: 750rpx;
		max-height: 100%;
		min-height: 100vh;
		padding-bottom: env(safe-area-inset-bottom);
		background: #F5F5F5;

		.card {
			width: 750rpx;
			height: 310rpx;
			background: #FFFFFF;
			display: flex;
			align-items: center;
			padding: 40rpx 20rpx;

			image {
				width: 172rpx;
				height: 188rpx;
				vertical-align: middle;
				margin-right: 36rpx;
			}

			.store {
				font-family: PingFang SC-Regular, PingFang SC;

				.name {
					font-size: 28rpx;
					font-weight: 400;
					color: #000000;

					text {
						font-size: 24rpx;
						font-weight: 400;
						color: #666666;
						margin-right: 10rpx;
					}
				}

				.info {
					font-size: 24rpx;
					font-weight: 400;
					color: #666666;
					margin: 12rpx 0;

					.iconfont {
						font-size: 26rpx;
						color: #4175EE;
						margin-right: 16rpx;
					}

				}
			}
		}


		.list {
			width: 750rpx;
			padding: 34rpx;
			margin: 30rpx auto;
			border-radius: 20rpx;

			.item {
				width: 688rpx;
				font-family: PingFang SC-Bold, PingFang SC;
				padding: 20rpx 32rpx;
				background: #FFFFFF;
				margin: 40rpx auto 20rpx;
				border-radius: 20rpx;

				.name {
					font-size: 28rpx;
					font-weight: bold;
					color: #000000;
					margin-top: 8rpx;
				}

				.timer {
					font-size: 24rpx;
					font-weight: 400;
					color: #666666;
					margin-top: 12rpx;
				}
			}

			.title {
				font-size: 28rpx;
				font-family: PingFang SC-Regular, PingFang SC;
				font-weight: 400;
				color: #232323;
				border-bottom: 1rpx solid #DDDDDD;
				padding: 0 0 20rpx 0;
			}

			.empty {
				width: 490rpx;
				height: 498rpx;
				margin: 40rpx auto;
				display: flex;
				flex-direction: column;
				justify-content: center;
				align-items: center;

				image {
					width: 370rpx;
					height: 278rpx;
					z-index: 10;
					margin-bottom: 20rpx;
				}

				text {
					font-size: 28rpx;
					font-family: PingFang SC-Regular, PingFang SC;
					font-weight: 400;
					color: #232323;
				}
			}
		}
	}
</style>