<template>
	<view class="listAll">
		<view class="nodata" v-if="list.length == 0">
			<view>暂无记录</view>
		</view>
		<view class="list" v-else>
			<view class="item" v-for="(item,index) in list" :key="index">
				<view class="hot">
					<image src="/static/identify/hot.png" mode="" />
				</view>
				<view class="itemL">
					<!-- <view class="hot" v-if="item.nB3 == 1"> -->

					<view class="img">
						<image :src="$globalData.publicUrl + item.js.cPortrait" />
					</view>
					<!-- <view class="new" v-if="item.nB2 == 1">
								new
							</view> -->
					<!-- <view class="status">{{item.nStatus ===1?'服务中' :'可服务'}}</view> -->
				</view>
				<view class="itemR">
					<view class="title">
						<view class="name">{{item.js.cNickName}}</view>
						<view class="intro_box">
							<view class="intro">
								简介
							</view>
							<view class="intro_content">
								{{item.js.cJianjie}}
							</view>
						</view>
						<!-- <view class="address">
									<image src="/static/identify/address.png" mode="" />{{item.distance}}km
								</view> -->
					</view>
					<view class="mark">
						<!-- 评分，默认5星 -->
						<view class="center">
							<image src="/static/identify/star.png" mode="" />{{item.js.nStar}}人
						</view>
						<!-- 收藏数量 -->
						<view class=" center right">
							<image src="/static/identify/my1.png" mode="" />
							<text>{{item.js.number}}</text> 人
						</view>
						<!-- 服务数量 -->
						<view class="right">
							<!-- <image src="/static/identify/serve.png" mode="" /> -->
							已服务: <text>{{item.js.nNum}}</text> 人
						</view>

					</view>
					<view class="num">
						<!-- <view class="free_box">
									<view class="free" v-if="free == 1">
										07:30-20:00 &nbsp; {{item.daytimeMileage}}公里免出行费
									</view>
									<view class="free" v-if="free == 1">
										20:00-07:30 &nbsp; {{item.nigthMileage}}公里免出行费
									</view>
								</view> -->
						<view class="free_box">
							<image src="/static/identify/length.png" mode="" />
							{{item.js.distance}}km
						</view>

						<view class="btn" @click.stop="bookNow(item)">
							<!-- <view class="btn" @click="bookNow" data-id="{{item.id}}" data-fuwu="{{item.nStatus}}" data-distance="{{item.distance}}"> -->
							<text>立即预约</text>
						</view>
					</view>

				</view>
				<!-- 	<view class="itemL" @click="godetails(item.js.id)">
							<image :src="$globalData.publicUrl + item.js.cPortrait" mode="scaleToFill" />
						</view>
						<view class="itemR">
							<view class="title" @click="godetails(item.js.id)">
								<view class="name">{{item.js.cName}}</view>
								<view class="status">{{item.js.nStatus ===1?'服务中' :'可服务'}}</view>
							</view>
							<view class="items" @click="godetails(item.js.id)">
								<view class="">
									<image src="/static/identify/star.png" mode="" />{{item.js.nStar}}
								</view>
								<view class="">
									<image src="/static/identify/serve.png" mode="" />{{item.js.nNum}}
								</view>
								<view class="">
									<image src="/static/identify/collect.png" mode="" />{{item.js.number || '0'}}
								</view>
							</view>
							<view class="btn" @click="bookNow(item.js.id,item.js.nStatus)">
								<text>立即预约</text>
							</view>
						</view> -->
			</view>
		</view>
		<view class="dialog" v-if="dialogShow">
			<view class="closebox" @click="closeDialog"></view>
			<view class="dialog_content">
				<view class="lists" v-for="(item,index) in projects" :key="index">
					<view class="imgs">
						<image :src="$globalData.publicUrl + item.cCover" mode="" />
					</view>
					<view class="right">
						<view class="list_title">
							<view class="title">{{item.cTitle}}</view>
							<view class="time">{{item.nMinute}}分钟</view>
						</view>
						<view class="price">
							<view class="money">￥{{item.dPrice}}</view>
							<view class="counter">
								<view @click="decrease(index)">-</view>
								<text>{{ item.number }}</text>
								<view @click="increase(index)">＋</view>
							</view>
						</view>
					</view>
				</view>
			</view>
			<view class="now" @click="nowYuyue"><text>立即预约</text></view>
		</view>
	</view>
</template>

<script>
	import {
		getCollect,
		engineerDetails,
		addOrder
	} from '../.././api/index.js'
	export default {
		data() {
			return {
				list: [],
				imageUrl: '',
				publicUrl: 'https://1910ca70.r6.cpolar.top', //图片前缀
				projects: [],
				dialogShow: false,
				count: 0,
				details: '',
				sum: 0,
			}
		},
		methods: {
			//预约
			nowYuyue() {
				const allCountsZero = this.projects.every(item => item.number === 0);
				if (allCountsZero) {
					uni.showToast({
						title: '请先选择项目！',
						duration: 1000,
						icon: 'none',
					})
					return
				} else {
					// console.log(this.data.projects,"project")
					var list = []
					this.projects.forEach(element => {
						if (element.number > 0) {
							element.sum = element.number * element.dPrice
							list.push(element)
						}
					});
					var total = 0
					for (let i = 0; i < list.length; i++) {
						total += list[i].sum;
					}
					var data = {
						cJsId: this.details.id,
						cGoods: list,
						cOpenId: uni.getStorageSync('wx_copenid'),
						dTotalMoney: total,
					}
					addOrder(data).then(res => {
						if (res.data.code == 200) {
							uni.navigateTo({
								// url: '../identify/orderDeatails/orderDeatails?orderNo=' + res.data.data.orderNo,
								url: '../identify/pay_order?orderNo=' + res.data.data.orderNo,
							})
						} else {
							uni.showModal({
								title: '提示',
								content: '你还没有添加地址哦！是否去添加？',
								confirmText: '确定', // 确定按钮的文字
								cancelText: '取消', // 取消按钮的文字
								success(res) {
									if (res.confirm) {
										setTimeout(() => {
											uni.navigateTo({
												url: '../my/addAddress/addAddress?type=1'
											})
										}, 100)
										// 用户点击确定按钮后的操作
									} else if (res.cancel) {}
								}
							})
						}
					})
				}
			},
			//预约弹窗关闭
			closeDialog() {
				this.dialogShow = false
			},
			//预约+1
			increase(idx) {
				this.projects[idx].number++;
			},
			//预约-1
			decrease(idx) {
				if (this.projects[idx].number > 0) {
					this.projects[idx].number--;
				}
			},
			//获取收藏列表
			getcollectList() {
				var data = {
					cWxOpenId: uni.getStorageSync('wx_copenid')
				}
				getCollect(data).then(res => {
					if (res.data.code == 200) {
						this.list = res.data.data
						console.log(this.list)
					}
				})
			},
			//跳转至商户详情
			godetails(id) {
				uni.navigateTo({
					url: '../identify/details?id=' + id
				})
			},
			//立即预约
			bookNow(id, nStatus) {
				if (nStatus === 1) {
					uni.showToast({
						title: '该商户不可预约！',
						icon: 'none'
					})
					return
				}
				this.projects = []
				var id = {
					id: id
				}
				engineerDetails(id).then(res => {
					// console.log(res.data.data,"1111111111111111")
					res.data.data.projects.forEach(element => {
						element.number = 0
					})
					this.details = res.data.data,
						this.projects = res.data.data.projects,
						this.dialogShow = true
				})
			},
		},
		onLoad() {},
		onShow() {
			this.getcollectList()
		},
		onHide() {
			this.dialogShow = false
		}
	}
</script>

<style lang="scss" scoped>
	.listAll {
		height: 100vh;

		background: linear-gradient(152deg, #DCFFF8 0%, #F1FEFF 100%);
	}

	.nodata {
		text-align: center;
		padding: 200rpx 0;
	}

	.list {
		height: 100%;
		overflow-y: auto;
		// height: 100%;
		padding: 20rpx;
		// background: #F7FFFF;

		.item {
			width: 100%;
			// height: 208rpx;
			background: #FFFFFF;
			box-shadow: 0px 4rpx 12rpx 0px rgba(88, 209, 187, 0.1);
			border-radius: 24rpx 24rpx 24rpx 24rpx;
			display: flex;
			align-items: center;
			justify-content: center;
			// border: 1px solid rgb(212, 211, 211);
			margin-bottom: 20rpx;
			padding: 24rpx 32rpx;
			box-sizing: border-box;
			position: relative;

			.hot {
				position: absolute;
				top: 0;
				left: 0;
				width: 80rpx;
				height: 40rpx;
				z-index: 9;

				image {
					width: 100%;
					height: 100%;
				}

			}

			.itemL {
				position: relative;
				width: 160rpx;
				height: 100%;
				margin-right: 30rpx;
				display: flex;
				// flex-direction: column;
				align-items: center;
				justify-content: center;


				.img {
					width: 160rpx;
					height: 160rpx;
					// border-radius: 50%;
					// overflow: hidden;

					image {
						width: 100%;
						height: 100%;
					}
				}

				.status {
					font-size: 24rpx;
					position: absolute;
					bottom: 0px;
					background-color: #59b7b6;
					color: #fff;
					padding: 3px 10px;
					border-radius: 20px;
					// margin: 10px 0px;
				}

				.new {
					position: absolute;
					top: -20rpx;
					left: -16rpx;
					padding: 0rpx 5rpx;
					background-color: #f9792d;
					opacity: .8;
					border-radius: 10rpx;
					color: #f3f3f3;
				}
			}

			.itemR {
				flex: 1;
				height: 100%;

				.title {
					width: 100%;
					display: flex;
					justify-content: space-between;
					align-items: center;
					margin-bottom: 24rpx;

					.name {
						width: 70rpx;
						font-size: 32rpx;
						font-weight: 500;
						overflow: hidden;
						white-space: nowrap;
						text-overflow: ellipsis;
						margin-right: 24rpx;
					}

					.intro_box {
						flex: 1;
						display: flex;
						align-items: center;

						.intro {
							width: 64rpx;
							height: 32rpx;
							background: #DCFFFD;
							border-radius: 4rpx 4rpx 4rpx 4rpx;
							font-size: 24rpx;
							color: #20CAC2;
							text-align: center;
							line-height: 32rpx;
							margin-right: 20rpx;
						}

						.intro_content {
							width: 280rpx;
							white-space: nowrap;
							overflow: hidden;
							text-overflow: ellipsis;
							font-size: 24rpx;
							color: #666666;
						}
					}

					.address {
						// width: 40%;
						font-size: 26rpx;
						color: #585858;

						image {
							width: 30rpx;
							height: 30rpx;
							vertical-align: text-bottom;
						}
					}

					.status {
						color: #fff;
						background-color: #0ec891;
						font-size: 18rpx;
						padding: 5rpx 15rpx;
						border-radius: 30px;
						height: 30rpx;
						line-height: 30rpx;
					}
				}

				.mark {
					display: flex;
					color: #666666;

					.right {
						font-size: 24rpx;
						color: #666666;

						text {
							color: #666666;
							margin-right: 5px;
						}
					}

					.center {
						display: flex;
						align-items: center;
						margin-right: 20rpx;
						font-size: 24rpx;
						color: #666666;

						image {
							width: 30rpx;
							height: 30rpx;
							margin-right: 4rpx;
						}
					}
				}

				.num {
					display: flex;
					align-items: center;
					justify-content: space-between;
					// padding-left: 30rpx;
					color: #9e9e9e;
					margin-top: 24rpx;

					.free_box {
						font-size: 24rpx;
						color: #999999;
						display: flex;
						align-items: center;

						image {
							width: 32rpx;
							height: 32rpx;
						}
					}



					.btn {
						font-size: 30rpx;
						line-height: 24rpx;
						padding: 16rpx 24rpx;
						background: linear-gradient(135deg, #FF8B66 0%, #EE5B2D 100%);
						border-radius: 98rpx 98rpx 98rpx 98rpx;
					}
				}

				.items {
					display: flex;
					justify-content: space-between;
					padding: 10rpx 0;

					image {
						width: 30rpx;
						height: 30rpx;
						margin-right: 10rpx;
						vertical-align: text-top;
					}

					view {
						display: flex;
						align-items: center;
					}
				}

				.btn {
					font-size: 26rpx;
					background-color: #2cb8d4;
					border-radius: 30px;
					color: #fff;
					text-align: center;
					padding: 10rpx 0;
				}
			}
		}
	}

	.dialog {
		position: fixed;
		top: 0;
		left: 0;
		width: 100%;
		height: 100%;
		background: rgba(0, 0, 0, .5);
		z-index: 10;
		transition: transform 0.3s ease-out;

		.closebox {
			height: calc(50vh - 60rpx);
			width: 100%;
		}

		.now {
			position: absolute;
			bottom: 0;
			left: 0;
			width: 100%;
			text-align: center;
			height: 100rpx;
			background-color: #f7f8fa;
			padding-top: 10rpx;

			text {
				display: inline-block;
				height: 80rpx;
				line-height: 80rpx;
				width: 90%;
				background-color: #2cb8d4;
				color: #fff;
				border-radius: 50rpx;
			}
		}

		.dialog_content {
			background-color: #fff;
			position: absolute;
			bottom: 0;
			width: calc(100% - 60rpx);
			height: 50vh;
			overflow-y: scroll;
			border-top-left-radius: 20rpx;
			border-top-right-radius: 20rpx;
			padding: 30rpx;
			background-color: #f3f3f3;
			padding-bottom: 100rpx;

			.lists {
				background-color: #fff;
				margin-bottom: 20rpx;
				display: flex;
				justify-content: space-between;
				padding: 20rpx 10rpx;
				border-radius: 10rpx;

				.imgs {
					width: 240rpx;
					height: 160rpx;
					border-radius: 20rpx;
					overflow: hidden;

					image {
						width: 100%;
						height: 100%;
					}
				}

				.right {
					flex: 1;
					padding-left: 30rpx;

					.list_title {
						display: flex;
						justify-content: space-between;
						align-items: center;

						.title {
							font-size: 34rpx;
							font-weight: bold;
						}

						.time {
							font-size: 24rpx;
						}
					}

					.price {
						padding-top: 50rpx;
						display: flex;
						justify-content: space-between;

						.money {
							font-size: 42rpx;
							color: #e61b1b;
							font-weight: bold;
						}

						.counter {
							display: flex;

							view {
								width: 60rpx;
								height: 60rpx;
								line-height: 60rpx;
								background-color: #f7f8fa;
								text-align: center;
								border-radius: 60rpx;
								font-size: 50rpx;
							}

							text {
								width: 100rpx;
								text-align: center;
								line-height: 60rpx;
							}
						}
					}
				}
			}
		}
	}
</style>