<template>

	<view class="equipment-home">
		<view class="top-bg">
			<view class="status_bar">

			</view>
			<view class="title">
				<view class="arrow" @click="backPage()">
					<image src="../../static/image/white-left.png" mode=""></image>
				</view>
				氢予健康
			</view>
		</view>
		<view class="top">
			<view class="name">
				<image src="../../static/image/name1.png" mode="" class="icon"></image>
				站点名称：{{siteDetail.name}}
			</view>
			<view class="name">
				<image src="../../static/image/address1.png" mode="" class="icon"></image>
				详细地址：{{siteDetail.address}}
			</view>
			<view class="name">
				<image src="../../static/image/guanliyuan.png" mode="" class="icon"></image>
				站长：{{siteDetail.contact_name}}
			</view>
			<view class="name">
				<image src="../../static/image/phone1.png" mode="" class="icon"></image>
				服务电话：{{siteDetail.contact_mobile}}
			</view>
		</view>
		<view class="residue-time" v-if="sytime!==0">
			吸氢卡剩余时长<text class="surplus-time">{{sytime}}</text>分钟<text style="float: right;" @click="lookDetail">查看详情></text>
		</view>
		<view class="title1">
			<view class="title1-left" @click="changeTab(1)">
				<view :class="currentTab==1 ? 'title-active' : 'title-active1'">
					设备列表
				</view>

			</view>
			<view class="title1-right" @click="changeTab(2)">
				<view :class="currentTab==2 ? 'title-active' : 'title-active1'">
					优惠套餐
				</view>

			</view>
		</view>

		<!-- 设备列表 -->
		<view class="" v-if="currentTab==1">
			<view class="list" v-for="(item,index) in equipmentList" :key='index' @click="equipmentDetail(item.id)">
				<view class="list-title">
					设备编号：<text style="color: #ff9c45;">{{item.no ? item.no : '--'}}</text>
					<text class="iconfont icon-iconfontjiantou2"></text>
				</view>
				<view class="list-text">
					<view class="left">
						<image src="../../static/image/name.png" mode=""></image>
						<!-- 	<view class="text">
						水位：{{item.water_level_warning_text}}
					</view> -->
					</view>
					<view class="right" v-if="!item.type || item.type==0">
						<view class="right-text">
							<view class="name">
								工作状态
							</view>
							<view class="status">
								{{item.a_test ? item.a_test : '--'}}
							</view>
						</view>
						<view class="right-text">
							<view class="name">
								设备状态
							</view>
							<view class="status">
								{{item.is_line_text ? item.is_line_text : '--'}}
							</view>
						</view>
					</view>
					<view class="right" v-else>
						<view class="right-text">
							<view class="name">
								A端口
							</view>
							<view class="status">
								{{item.a_test ? item.a_test : '--'}}
							</view>
						</view>
						<view class="right-text">
							<view class="name">
								B端口
							</view>
							<view class="status">
								{{item.b_test ? item.b_test : '--'}}
							</view>
						</view>
						<view class="right-text">
							<view class="name">
								状态
							</view>
							<view class="status">
								{{item.is_line_text ? item.is_line_text : '--'}}
							</view>
						</view>
					</view>

				</view>
			</view>
			<view class="none" v-if="equipmentList.length==0">
				<image src="../../static/image/null.png"></image>
				<text>暂无设备列表</text>
			</view>
		</view>
		<!-- 优惠套餐 -->
		<view class="" v-if="currentTab==2">
			<view class="box">
				<view class="card" v-for="(item,index) in cardList" :key='index'>
					<view :class="card_id==item.id ? 'active' : 'card-list-item'" @click="changeCard(item.id)">
						<view class="right-tips" v-if="item.discount!==0">限时{{item.discount/10}}折</view>
						<view class="card-title">
							<!-- <text>30次/5天</text> -->
							<!-- <text>7天不限次</text> -->
							<text>{{item.time}}分钟时长卡</text>
						</view>
						<view class="card-money">
							<text class="money-num">{{item.price}}</text>元
							<text class="yuanjia">{{item.money}}元</text>
						</view>
					</view>
				</view>
				<view class="buy-buttom" @click="buyButtom">购买</view>
				<view class="none" v-if="cardList.length==0">
					<image src="../../static/image/null.png"></image>
					<text>暂无优惠套餐</text>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	var app = getApp()
	export default {
		data() {
			return {
				shop_id: '',
				siteDetail: '',
				equipmentList: [1, 2, 1, 1, 1, 3],
				currentTab: 1,
				cardList: [], //卡券列表
				card_id: 1,
				sytime: 0
			}
		},
		onLoad(options) {
			uni.showLoading()
			console.log(options, '0-0-0-0-0-0-0-0-0-0-0-0-')
			let params = {
				id: options.id
			}
			this.shop_id = options.id
			this.getSiteDetail(params)
			this.getCardsList(params)
			this.getEquipmentList(options.id)
			this.getSurplusTime(options.id)
		},
		methods: {
			//站点详细信息
			getSiteDetail: function(params) {
				uni.showLoading()
				app.request('/shops/' + params.id, '', 'get').then(res => {
					console.log(res)
					this.siteDetail = res.data.data.data
					app.globalData.a_minute_money = res.data.data.data.a_minute_money
					app.globalData.b_minute_money = res.data.data.data.b_minute_money
					app.globalData.ab_minute_money = res.data.data.data.ab_minute_money
					uni.hideLoading()
				})
			},
			//卡券列表
			getCardsList: function(params) {
				let data = {
					shop_id: params.id
				}
				app.request('/shop/cards', data, 'get').then(res => {
					console.log(res, 'cardlist')
					this.cardList = res.data.data.data
				})
			},
			//剩余时长
			getSurplusTime: function(id) {

				app.request('/shop/me-card?shop_id=' + id, '', 'get').then(res => {
					console.log(res.data.data.time, 'shengyushichang ')

					this.sytime = res.data.data.time
					console.log(this.sytime, 'pppppp')
				})
			},
			//设备列表
			getEquipmentList: function(e) {
				uni.showLoading()
				let params = {
					shop_id: e
				}
				app.request('/devices', params, 'get').then(res => {
					this.equipmentList = res.data.data.data
					uni.hideLoading()
					console.log(this.equipmentList, '设备列表')
				})
			},
			//设备详情
			equipmentDetail: function(e) {
				uni.navigateTo({
					url: './service?id=' + e
				})
			},
			//tab切换
			changeTab: function(e) {
				this.currentTab = e

			},
			//选择优惠券
			changeCard: function(e) {
				console.log(e, '选择优惠券')
				this.card_id = e
			},
			//购买优惠券
			buyButtom: function(e) {
				let data = {
					shop_id: this.shop_id,
					card_id: this.card_id
				}
				app.request('/shop/card', data, 'post').then(res => {
					console.log(res.data.data, '下单')
					let data = res.data.data
					if (res.statusCode == 200) {
						uni.requestPayment({
							provider: data.provider,
							timeStamp: data.timeStamp,
							nonceStr: data.nonceStr,
							package: data.package,
							signType: 'MD5',
							paySign: data.paySign,
							success: function(res) {
								console.log('success:' + JSON.stringify(res));
								uni.reLaunch({
									url: '../mine/pay_success'
								})
							},
							fail: function(err) {
								console.log('fail:' + JSON.stringify(err));
							}
						})
					}
				})
			},
			//查看订单吸氢时长
			lookDetail: function() {
				uni.navigateTo({
					url: '../mine/card_use?shop_id=' + this.shop_id
				})
			},
			backPage: function() {
				uni.navigateBack()
			}
		}
	}
</script>

<style lang="scss" scoped>
	.equipment-home {
		width: 100%;

		.top-bg {
			// background-color: #ff964a;
			background-color: $mine-background-color;
			border-radius: 0 0 40upx 40upx;
			height: 350upx;

			.status_bar {
				height: var(--status-bar-height);
				width: 100%;
			}

			.title {
				text-align: center;
				line-height: 100upx;
				height: 100upx;
				font-size: 38upx;
				color: #FFFFFF;
				position: relative;

				.arrow {
					position: absolute;
					width: 100upx;
					height: 100upx;
					left: 10upx;
					top: 25upx;

					image {
						float: left;
						height: 50upx;
						width: 50upx;

					}
				}


			}
		}

		.top {
			margin: 30upx;
			margin-top: -130upx;
			padding: 30upx;
			background-color: #FFFFFF;
			border-radius: 12upx;

			.name {
				// height: 50upx;
				line-height: 50upx;
				font-size: 30upx;
				color: #555555;

				image {
					height: 30upx;
					width: 30upx;
					margin-right: 20upx;
					display: inline-block;
					vertical-align: top;
					margin-top: 10upx;
				}
			}
		}

		.residue-time {
			padding: 20rpx 30rpx;
			margin: 0 30rpx;
			color: #FFFFFF;
			font-size: 28rpx;
			// color: #f0d84d;
			background-image: linear-gradient(to right, #F0AD4E, #f0d84d);
			border-radius: 12rpx;
		}

		.surplus-time {
			font-size: 34rpx;
			font-weight: 600;
			display: inline-block;
			margin: 0 5rpx;
		}

		.title1 {
			height: 100upx;
			// line-height: 70upx;
			font-size: 30upx;
			font-weight: bold;
			color: #555555;
			margin: 50upx 30upx 30upx;
			padding-left: 20upx;
			background-color: #FFFFFF;
			text-align: center;
			display: flex;

			.title1-left {
				flex: 1;
			}

			.title-active {
				margin: 0 auto;
				margin-top: 10rpx;
				height: 80;
				line-height: 80rpx;
				width: 80%;
				background-color: #027675;
				border-radius: 50rpx;
				color: #FFFFFF;
			}

			.title-active1 {
				margin: 0 auto;
				margin-top: 20rpx;
				height: 60rpx;
				line-height: 60rpx;
				width: 70%;
				// background-color: #16DAD8;
				border-radius: 20rpx;
			}

			.title1-right {
				flex: 1;
			}
		}

		.list {
			margin: 30upx;
			background-color: #FFFFFF;
			padding: 30upx;
			border-radius: 12upx;

			.list-title {
				border-bottom: solid 1upx #F1F1F1;
				color: #555555;
				font-size: 26upx;
				font-weight: bold;
				height: 70upx;
				line-height: 70upx;

				.icon-iconfontjiantou2 {
					float: right;
				}
			}

			.list-text {
				display: flex;
				padding: 30upx 0;

				.left {
					flex: 0 0 150upx;
					text-align: center;
					margin-right: 30upx;

					.text {
						font-size: 24upx;
						text-align: center;
						height: 50upx;
						line-height: 50upx;
					}

					image {
						margin-top: 20upx;
						height: 100upx;
						width: 100upx;
					}
				}

				.right {
					flex: 1;
					display: flex;

					.right-text {
						flex: 1;
						vertical-align: top;

						text-align: center;

						.name {
							font-size: 30upx;
							color: #808080;
							height: 70upx;
							line-height: 70upx;
						}

						.status {
							height: 90upx;
							line-height: 90upx;
							font-size: 32upx;
							font-weight: bold;
						}
					}
				}
			}

		}

		// 优惠套餐
		.box {
			/* width: 100%; */
			/* height: 100%; */
			/* display: flex;
	  flex-direction: column;
	  align-items: center; */
			padding-bottom: 20upx;
		}

		.card {
			margin: 30upx;
		}

		.card-list1 {
			position: relative;
			border: solid 5upx #eceaea;
			background-color: #fff;
			padding: 30upx;
			/* background: #ffe98f;
	  border: solid 5upx var(--globleColor); */
			border-radius: 20upx;

		}

		.active {
			position: relative;
			padding: 30upx;
			border-radius: 20upx;
			color: #FFFFFF;
			background-image: linear-gradient(to right, #3bba91, #027675);
			border: solid 5upx var(--globleColor);
		}

		.card-title {
			font-size: 30upx;
			font-weight: 500;
		}

		.card-tips {
			font-size: 26upx;
			margin-top: 10upx;
		}

		.card-money {
			font-size: 26upx;
			margin-top: 30upx;
		}

		.money-num {
			font-size: 50upx;
			font-weight: bold;
		}

		.yuanjia {
			color: #2c2c6c;
			display: inline-block;
			margin-left: 10upx;
			text-decoration: line-through;
		}

		.card-list {
			display: flex;
			flex-wrap: wrap;
			justify-content: space-between;
			flex-direction: row;
		}

		.card-content {
			margin: 30upx;
		}

		.card-list-item {
			position: relative;
			flex: 0 0 45%;
			border: solid 5upx #eceaea;
			padding: 20upx;
			border-radius: 30upx;
			background-color: #fff;
			margin-top: 30upx;
		}

		.active1 {
			position: relative;
			flex: 0 0 45%;
			padding: 20upx 0;
			border-radius: 30upx;
			margin-top: 30upx;
			background: #3bba91;
			border: solid 5upx $mine-background-color
		}

		.right-tips {
			position: absolute;
			height: 40upx;
			padding: 0 30upx;
			font-size: 22upx;
			line-height: 40upx;
			color: #ffffff;
			font-weight: bold;
			background-color: rgb(235, 58, 4);
			border-radius: 0 20upx;
			top: 0;
			right: 0;
		}

		.item-money {
			margin-top: 10upx;
		}

		.buy-buttom {
			height: 100upx;
			width: 80%;
			margin: 0 auto;
			margin-top: 50upx;
			background-color: #027675;
			color: #FFFFFF;
			text-align: center;
			border-radius: 50upx;
			line-height: 100upx;
			font-size: 32upx;
			font-weight: bold;
		}


		.box .hot {
			/* padding-top: ; */
			width: 690upx;
			padding: 30upx 0;
			/* height:296upx; */
			background: rgba(255, 255, 255, 1);
			border-radius: 20upx;
			background-size: 100% 100%;
			display: flex;
			flex-direction: column;
			justify-content: center;
			box-sizing: border-box;
			padding-left: 47upx;
			margin-top: 30upx;
		}

		.box .hot .title {
			font-size: 38upx;
			font-family: PingFang SC;
			font-weight: bold;
			color: rgba(42, 42, 42, 1);
		}

		.box .hot .frequency {
			font-size: 32upx;
			font-family: PingFang SC;
			color: rgba(153, 153, 153, 1);
		}

		.box .hot .info {
			display: flex;
			align-items: flex-end;
			padding: 19upx 0upx;
		}

		.box .hot .info text:nth-of-type(1) {
			font-size: 46upx;
			font-family: PingFang SC;
			font-weight: bold;
			color: rgba(42, 42, 42, 1);
		}

		.box .hot .info text:nth-of-type(2) {
			font-size: 26upx;
			font-family: PingFang SC;
			color: rgba(153, 153, 153, 1);
			padding-left: 19upx;
			padding-bottom: 6upx;
			text-decoration: line-through;
		}

		.box .hot .buy {
			width: 160upx;
			height: 70upx;
			margin-bottom: 20upx;
			background: #5E5D5D;
			/* background:var(--globleColor); */
			border-radius: 40upx;
			display: flex;
			/* margin-left: 20upx; */
			align-items: center;
			justify-content: center;
			font-size: 32upx;
			font-family: PingFang SC;
			color: rgba(255, 255, 255, 1);
		}

		.box .hot .info .buy text {
			font-size: 26upx;
			color: #ffffff;
		}

		.none {
			display: flex;
			flex-direction: column;
			align-items: center;
			justify-content: center;
			width: 100%;
			margin-top: 30%;
			height: 90%;
		}

		.none image {
			height: 200upx;
			width: 200upx;
		}

		.none text {
			/* padding-right: 70upx; */
			padding-top: 50upx;
		}

	}
</style>
