<template>
	<view class="page">
		<u-navbar title="订单详情" :border-bottom="false" :background="bgc" title-color='#000' title-size='36' height='45'  back-icon-color='#000'></u-navbar>
		
		<map class="map" id="map" ref="map" :scale="zoomSize" :latitude="latitude" :longitude="longitude"
			:show-location="true" :markers="markers" :polyline="polyline" :polygons="polygon" :enable-zoom="true"
			:enable-scroll="true">
		</map>
		<view class="jiaoyi">
			<view class="pic">
				<image src="https://api.ccttiot.com/smartmeter/img/static/uiXte3LpSV30jyvTUR2R" mode=""></image> 
				<text v-if="info.status == 'PROCESSING'">进行中</text>
				<text v-if="info.status == 'WAIT_PAY'">待支付</text>
				<text v-if="info.status == 'CANCELED'">已取消</text>
				<text v-if="info.status == 'FINISHED'">交易完成</text>
				<text v-if="info.status == 'WAIT_VERIFY'">待审核</text>
				<text v-if="info.status == 'RIDE_WAIT_PAY'">骑行待支付</text>
			</view>
			<view class="gx">
				<text v-if="info.status == 'PROCESSING'">订单进行中</text>
				<text v-if="info.status == 'WAIT_PAY'">订单待支付</text>
				<text v-if="info.status == 'CANCELED'">订单已取消</text>
				<text v-if="info.status == 'FINISHED'">感谢您的支持，欢迎再次光临</text>
				<text v-if="info.status == 'RIDE_WAIT_PAY'">订单待支付</text>
			</view>
			<view class="" @click="btntx" style="margin-top: 10rpx;color: #4C97E7;display: flex;align-items: center;width: 100%;justify-content: center;">
				订单投诉 <u-icon name="arrow-right" color="#4C97E7" size="28"></u-icon>
			</view>
		</view>
		<view class="ordermx">
			<view class="top">
				订单明细
			</view>
			<view class="xuxian">
				<view class="one">
					<view class="qian">
						订单编号
					</view>
					<view class="shen">
						{{info.no == null ? '--' : info.no}} <image src="https://api.ccttiot.com/smartmeter/img/static/uimYURcxkn9ItLquwPpM" mode=""></image>
					</view>
				</view>
				<view class="one">
					<view class="qian">
						下单时间
					</view>
					<view class="shen">
						{{info.createTime == null ? '--' : info.createTime}}
					</view>
				</view>
				<view class="one">
					<view class="qian">
						结束时间
					</view>
					<view class="shen">
						{{info.endTime == null ? '--' : info.endTime}}
					</view>
				</view>
			</view>
			<view class="xuxian">
				<view class="one">
					<view class="qian">
						骑行费
					</view>
					<view class="shen">
						{{info.ridingFee == null ? '0.00' : info.ridingFee.toFixed(2)}}元
					</view>
				</view>
				<view class="one">
					<view class="qian">
						停车点外调度费
					</view>
					<view class="shen">
						{{info.manageFee == null ? '0.00' : info.manageFee.toFixed(2)}}元
					</view>
				</view>
				<view class="one">
					<view class="qian">
						运营区外调度费
					</view>
					<view class="shen">
						{{info.dispatchFee == null ? '0.00' : info.dispatchFee.toFixed(2)}}元
					</view>
				</view>
				<view class="one">
					<view class="qian">
						合计
					</view>
					<view class="shen">
						{{info.totalFee == null ? '0.00' : info.totalFee.toFixed(2)}}元
					</view>
				</view>
			</view>
			<view class="xuxian">
				<view class="one">
					<view class="qian">
						预存金额
					</view>
					<view class="shen">
						{{info.depositFee == null ? '0.00' : info.depositFee.toFixed(2)}}元
					</view>
				</view>
				<view class="one">
					<view class="qian">
						结算支付
					</view>
					<view class="shen">
						{{info.ridePayAmount == null ? '0.00' : info.ridePayAmount.toFixed(2)}}元
					</view>
				</view>
				<view class="one">
					<view class="qian">
						退款总额
					</view>
					<view class="shen">
					    {{info.payRefunded == null ? '0.00' : info.payRefunded.toFixed(2)}}元
					</view>
				</view>
			</view>
			<view class="xuxian">
				<view class="one">
					<view class="qian">
						优惠券
					</view>
					<view class="shen">
						{{info.vipName == null ? '--' : info.vipName}}
					</view>
				</view>
				<view class="one">
					<view class="qian">
						折扣
					</view>
					<view class="shen">
						{{info.vipDiscountValue == null ? '--' : info.vipDiscountValue}}折
					</view>
				</view>
				<view class="one">
					<view class="qian">
						骑行费优惠
					</view>
					<view class="shen">
					    {{info.ridingDiscount == null ? '--' : info.ridingDiscount.toFixed(2)}}元
					</view>
				</view>
				<view class="one">
					<view class="qian">
						总计优惠
					</view>
					<view class="shen">
					    {{info.totalDiscountAmount == null ? '--' : info.totalDiscountAmount.toFixed(2)}}元
					</view>
				</view>
			</view>
			<view class="xuxian" style="border: 0;">
				<view class="one" v-if="info.status == 'PROCESSING'">
					<view class="qian">
						预估金额
					</view>
					<view class="shen">
						<span style="color: #E7612E;font-size: 40rpx;">{{yugumoney.toFixed(2)}}</span>元
					</view>
				</view>
				<view class="one">
					<view class="qian">
						实付金额
					</view>
					<view class="shen">
						<span style="color: #E7612E;font-size: 40rpx;">{{info.actualReceivedAmount.toFixed(2)}}</span>元
					</view>
				</view>
			</view>
		</view>
		<view class="qixing">
			<view class="top">
				骑行信息
			</view>
			<view class="xuxian">
				<view class="one">
					<view class="qian">
						骑行时长                                        
					</view>
					<view class="shen">
						{{ rideDuration == '' ? '--' : rideDuration}}
					</view>
				</view>
				<view class="one">
					<view class="qian">
						骑行距离                                                  
					</view>
					<view class="shen" v-if="info.status != 'PROCESSING'">
						{{info.distance > 1000 ? (info.distance / 1000).toFixed(2) + 'km' : info.distance.toFixed(2) + 'm'}}
					</view>
					<view class="shen" v-else>
						订单结束后展示
					</view>
				</view>
				<view class="one">
					<view class="qian">
						运营区                                                  
					</view>
					<view class="shen">
					    {{info.areaName == null ? '--' : info.areaName}}
					</view>
				</view>
				<view class="one">
					<view class="qian">
						车牌号                                               
					</view>
					<view class="shen">
					   {{info.deviceVehicleNum == null ? '--' : info.deviceVehicleNum}}
					</view>
				</view>
				<view class="one">
					<view class="qian">
						车辆编号（SN）                                 
					</view>
					<view class="shen">
					   {{info.deviceSn == null ? '--' : info.deviceSn}}
					</view>
				</view>
			</view>
		</view>
		<view class="" v-if="info.status == 'RIDE_WAIT_PAY'" style="display: flex;align-items: center;justify-content: space-between;position: fixed;width: 100%;height: 230rpx;
		left: 50%;background-color: #fff;padding: 20rpx 40rpx;box-sizing: border-box;
		transform: translateX(-50%);
		bottom: 0;">
			<view class="bottom-content">
				<view class="coupon-select" @click="openCouponPopup">
					<text>优惠券</text>
					<text v-if="selectedCoupon">{{selectedCoupon.name.length > 4 ? selectedCoupon.name.slice(0,4) + '...' : selectedCoupon.name}}(优惠￥{{youhuiobj.discountAmount}})</text>
				</view>
				<view class="kefu" @click="getyajin" v-if="info.suitDepositDeduction && info.isCredit == false">
					押金抵扣<text style="font-weight: 400;"></text>
					<text class="xiao">
						抵扣完成，剩余押金返回账户
					</text>
				</view>
				<view class="kefu" @click="getzhifu">
					{{channelobj[0].name}}<text style="font-weight: 400;">(￥{{info.totalFee}})</text>
					<text class="xiao">
						支付完成，全部押金返回账户
					</text>
				</view>
			</view>
		</view>
		<!-- 优惠券选择弹窗 -->
		<view class="coupon-popup" v-if="showCouponPopup">
			<view class="coupon-mask" @click="closeCouponPopup"></view>
			<view class="coupon-content">
				<view class="coupon-header">
					<text>选择优惠券</text>
					<text class="close-btn" @click="closeCouponPopup">×</text>
				</view>
				<view class="coupon-list">
					<view class="coupon-item" v-for="(item, index) in couponList" :key="index">
						<view class="coupon-info">
							<view class="coupon-name">{{item.name}}</view>
							<view class="coupon-detail">
								<text>折扣：{{item.discount}}折</text>
								<text>剩余：{{item.surplusTotal}}次</text>
								<text v-if="item.enableLimit">频率：每{{item.limitRound}}天限制{{item.limitCount}}次，当前已用{{item.roundCount}}次</text>
							</view>
						</view>
						<view class="coupon-btn" @click="useCoupon(item)">
							<text :class="{'used': item.used}">{{item.used ? '已选择' : '选择'}}</text>
						</view>
					</view>
					<view class="no-coupon" v-if="couponList.length === 0">
						暂无可用优惠券
					</view>
				</view>
			</view>
		</view>
		<!-- 平台客服弹窗 -->
		<view class="kefutc" v-if="kefuflag">
			<image src="https://api.ccttiot.com/smartmeter/img/static/umtjJg2CJLiOS6hfAEzo" mode="" @click="btnkefu"></image>
			<view class="box">
				<view class="" style="max-height: 280rpx;overflow: scroll;">
					<view class="top" v-for="(item,index) in kefulist" :key="index">
						<view class="dianhua">
							{{item.name == null ? '--' : item.name}}：{{item.contact == null ? '--' : item.contact}}
							<view class="wz">
								工作时间：{{item.startTime}}~{{item.endTime}}
							</view>
						</view>
						<view class="boda" @click.stop="btnptkf(item.contact)">
							<u-icon name="phone-fill" color="#4297F3" size="28"></u-icon>
							<text>拨打</text>
						</view>
					</view>
				</view>
				<view class="bot">
					<view class="wzs">
						客服电话高峰期可能遇忙，请耐心等待
					</view>
				</view>
			</view>
		</view>
		<view class="mask" v-if="kefuflag"></view>
		<view class="kfrens">
			<image class="kfren" @click="btntel" src="https://api.ccttiot.com/smartmeter/img/static/uJd9ccJt76zc7r2Nlpb8" mode=""></image>
			联系客服
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				bgc: {
					backgroundColor: "#fff",
				},
				id: 0,
				info: {},
				rideDuration: '' ,// 新增属性用于存储骑行时间
				kefulist:[],
				kefuflag:false,
				yugumoney:'',
				
				zoomSize: 15,
				markers: [], // 标记点数组
				polyline: [], // 轨迹折线数组
				polygon: [], // 用于存储区域多边形
				latitude: '',
				longitude: '',
				isMap: false,
				trackPoints: [], // 存储轨迹点数据
				channelId:'',
				dikouflag:true,
				
				// 新增优惠券相关数据
				showCouponPopup: false,
				couponList: [],
				selectedCoupon: null,
				youhuiobj:{},
				vipUserId:null,
				creditUserId:'',
				channelobj:{}
			}
		},
		onLoad(option) {
			this.id = option.id
			console.log(option,this.id,'020202020');
			this.getyouhui()
			this.updateTrackData()
			this.orderInfo()
			this.getyugu()
		},
		methods: {
			// 点击去投诉
			btntx(){
				uni.navigateTo({
					url:'/page_fenbao/tousu/index?obj=' + JSON.stringify(this.info)
				})
			},
			getParking() {
				let data = {
					areaId: this.info.areaId
				};
				this.$u.get('/bst/areaSub/listByAreaId', data).then((res) => {
					if (res.code === 200) {
						const filteredData = res.data.filter(item => item.status != 1);
						const type1Data = [];
						const type2Data = [];
						const type3Data = [];
						filteredData.forEach(row => {
							if (row.type == 1) type1Data.push(row);
							else if (row.type == 2) type2Data.push(row);
							else if (row.type == 3) type3Data.push(row);
						});
						
						// 处理 type1 数据
						const validBoundaries = type1Data.map(row => row.boundaryStr).filter(boundary =>
								typeof boundary === 'string' && boundary.trim() !== '');
						const polygons = this.convertBoundaryToPolygons(validBoundaries, 1);
						if (polygons && polygons.length > 0) {
							this.polygon = this.polygon.concat(polygons);
						}
						
						// 处理 type2 数据
						const validBoundaries1 = type2Data.map(row => row.boundaryStr).filter(boundary =>
								typeof boundary === 'string' && boundary.trim() !== '');
						const polygons1 = this.convertBoundaryToPolygons(validBoundaries1, 2);
						if (polygons1 && polygons1.length > 0) {
							this.polygon = this.polygon.concat(polygons1);
						}
						
						// 处理 type3 数据
						const validBoundaries2 = type3Data.map(row => row.boundaryStr).filter(boundary =>
								typeof boundary === 'string' && boundary.trim() !== '');
						const polygons2 = this.convertBoundaryToPolygons(validBoundaries2, 3)
						if (polygons2 && polygons2.length > 0) {
							this.polygon = this.polygon.concat(polygons2);
						}
						
						this.parkingList = filteredData
						this.$forceUpdate()
						this.toggleIconAndCallout()
					}
				}).catch(error => {
					console.error("Error fetching parking data:", error)
				})
			},
			toggleIconAndCallout() {
				this.showIconAndCallout = !this.showIconAndCallout
				if (this.showIconAndCallout) {
					const newMarkers = []
					this.parkingList.forEach(item => {
						newMarkers.push({
							id: parseFloat(item.id),
							latitude: parseFloat(item.latitude),
							longitude: parseFloat(item.longitude),
							width: 20,
							height: 28.95,
							iconPath: item.type == 1 ? 'https://lxnapi.ccttiot.com/bike/img/static/up2xXqAgwCX5iER600k3' : item.type == 2 ? 'https://lxnapi.ccttiot.com/bike/img/static/uDNY5Q4zOiZTCBTA2Jdq' : 'https://lxnapi.ccttiot.com/bike/img/static/u53BAQcFIX3vxsCzEZ7t',
							callout: {
								content: item.name,
								color: '#ffffff',
								fontSize: 14,
								borderRadius: 10,
								bgColor: item.type == 1 ? '#3A7EDB' : item.type == 2 ? '#FF473E' : '#FFC107',
								padding: 6,
								display: 'ALWAYS'
							},
							isCalloutVisible: true // 添加标记
						})
					})
					this.$set(this, 'markers', [...this.markers, ...newMarkers])
				} else {
					// 过滤掉所有气泡显示的标记
					this.$set(this, 'markers', this.markers.filter(marker => !marker.isCalloutVisible))
				}
			},
			getArea() {
				let id = this.info.areaId;
				if (!id) {
					console.error("Area ID is missing");
					return;
				}
				this.$u.get(`/bst/area/${id}`).then((res) => {
					if(res.code == 200){
						this.latitude = res.data.latitude
						this.longitude = res.data.longitude
					}
					if (res.data && res.data.boundaryStr) {
						const polygon = this.convertBoundaryToPolygon(res.data.boundaryStr);
						if (polygon) {
							this.polygon = [polygon];
							console.log('Area boundary added:', polygon);
							this.getParking();
						}
					}
				}).catch(error => {
					console.error("Error fetching area data:", error);
				});
			},
			
			convertBoundaryToPolygon(boundary) {
				if (!boundary) return null;
				try {
					const points = JSON.parse(boundary).map(coord => ({
						latitude: coord[1],
						longitude: coord[0]
					}));
					return {
						points: points,
						fillColor: "#55888840",
						strokeColor: "#22FF0080",
						strokeWidth: 1,
						zIndex: 1
					};
				} catch (error) {
					console.error("Error converting boundary to polygon:", error);
					return null;
				}
			},
			
			convertBoundaryToPolygons(boundaries, num) {
				if (!boundaries || !boundaries.length) return [];
				const colors = {
					1: { fill: "#3A7EDB40", stroke: "#3A7EDB" },
					2: { fill: "#FFF5D640", stroke: "#FF473E" },
					3: { fill: "#FFE0E040", stroke: "#FFC107" }
				};
				return boundaries.map(boundary => {
					if (!boundary) return null;
					try {
						const coords = JSON.parse(boundary);
						if (!Array.isArray(coords)) return null;
						const points = coords.map(coord => ({
							latitude: coord[1],
							longitude: coord[0]
						}))
						return {
							points: points,
							fillColor: colors[num].fill,
							strokeColor: colors[num].stroke,
							strokeWidth: 1,
							zIndex: 1
						};
					} catch (error) {
						console.error("Error converting boundary to polygons:", error)
						return null
					}
				}).filter(Boolean)
			},
			updateTrackData() {
				this.$u.get('/app/locationLog/allByOrder?orderId=' + this.id).then((res) => {
					if (res.code === 200) {
						if (!res.data || res.data.length === 0) {
							uni.showToast({
								title: '该时间段内无轨迹数据',
								icon: 'none',
								duration: 2000
							});
							return
						}
						// 清空之前的轨迹数据
						this.polyline = []
						this.markers = []
						// 处理轨迹点数据并按时间排序
						this.trackPoints = res.data
							.map(point => ({
								latitude: parseFloat(point.latitude),
								longitude: parseFloat(point.longitude),
								time: point.at,
								status: point.status,
								onlineStatus: point.onlineStatus,
								remainingPower: point.bat || 0
							}))
							.sort((a, b) => new Date(a.time) - new Date(b.time)); // 按时间排序
						// 添加起点和终点标记
						if (this.trackPoints.length > 0) {
							const startPoint = this.trackPoints[0]
							const endPoint = this.trackPoints[this.trackPoints.length - 1]
							// 添加起点标记
							this.markers.push({
								id: 'start',
								latitude: startPoint.latitude,
								longitude: startPoint.longitude,
								width: 22,
								height: 32,
								iconPath: 'https://api.ccttiot.com/smartmeter/img/static/uoORewceRbnD0jcNHhns'
							})
							// 添加终点标记
							this.markers.push({
								id: 'end',
								latitude: endPoint.latitude,
								longitude: endPoint.longitude,
								width: 22,
								height: 32,
								iconPath: 'https://api.ccttiot.com/smartmeter/img/static/u5HZcdTVcyNGkHDUeT4h'
							})
							// 添加轨迹折线
							this.polyline.push({
								points: this.trackPoints.map(point => ({
									latitude: point.latitude,
									longitude: point.longitude
								})),
								color: '#00AF99',
								width: 4,
								dottedLine: false,
								arrowLine: true,
								borderWidth: 2,
								borderColor: '#ffffff'
							})
							// 更新地图显示范围
							this.$nextTick(() => {
								if (this.$refs.map) {
									this.$refs.map.includePoints({
										points: this.trackPoints,
										padding: [80, 80, 80, 80]
									})
								}
							})
						}
					}
				})
			},
			
			// 计算实付金额
			formatPayedAmount(payedAmount, payRefunded, payRefunding) {
				if (!payedAmount) return '0.00';
				const amount = parseFloat(payedAmount) || 0;
				const refunded = parseFloat(payRefunded) || 0;
				const refunding = parseFloat(payRefunding) || 0;
				const actualAmount = amount - (refunded + refunding);
				return `${actualAmount}`;
			},
			// 点击隐藏客服
			btnkefu(){
				console.log(211);
				this.kefuflag = false
			},
			// 请求预估金额
			getyugu() {
				let data = {
					orderId:this.id,
					checkLocation:false
				}
				this.$u.post(`/app/order/calcFee`,data).then((res) => {
					if (res.code == 200) {
						this.yugumoney = res.data.ridingFee
					}
				})
			},
			// 请求订单详情
			orderInfo() {
				this.$u.get("/app/order/mineDetail?id=" + this.id).then((res) => {
					if (res.code == 200) {
						this.info = res.data
						if(this.info.status == 'RIDE_WAIT_PAY'){ //骑行待支付
							this.$u.get(`/app/channel/rideFee?orderId=${this.id}`).then((res) => {
								if (res.code == 200) {
									this.channelId = res.data[0].id
									this.channelobj = res.data
									if(res.data[0].subList != null && res.data[0].subList.length > 0){
										this.creditUserId = res.data[0].subList[0].id
									}
									this.getCouponList() 
								} else {
									uni.showToast({
										title: res.msg,
										icon: 'none',
										duration: 2000
									})
								}
							})
						}
						this.getArea()
						this.calculateRideDuration() // 计算骑行时间
					}
				})
			},
			// 骑行待支付押金抵扣
			getyajin(){
				let that = this
				uni.showModal({
					title: '提示',
					content: '您当前要进行押金抵扣吗？',
					showCancel: true,
					success: function (res) {
						if (res.confirm) {
							if(that.dikouflag == true){
							    that.dikouflag = false
									uni.showLoading({
										title: '加载中...',
										mask: true
									})
									let fee = that.youhuiobj
									let data = {
										id: that.id,
										vipUserId:that.vipUserId,
										fee
									}
									that.$u.put(`/app/order/deduct`, data).then((resp) => {
										if (resp.code == 200) {
											that.orderInfo()
											that.dikouflag = true
											uni.hideLoading()
										} else {
											uni.hideLoading()
											uni.showToast({
												title: resp.msg,
												icon: 'none',
												duration: 2000
											})
											that.dikouflag = true
										}
									}).catch(e => {
										that.dikouflag = true
										uni.hideLoading()
									})
							}
						} else if (res.cancel) {
							
						}
					}
				})
			},
			// 骑行待支付接口
			getzhifu(){ 
				if(this.dikouflag == true){
				    this.dikouflag = false
						uni.showLoading({
							title: '加载中...',
							mask: true
						})
						let fee = this.youhuiobj
						let data = {
							orderId: this.id,
							payAmount: this.info.totalFee,
							channelId: this.channelId,
							creditUserId:this.creditUserId,
							appId: this.$store.state.appid,
							vipUserId:this.vipUserId,
							fee
						}
						this.$u.put(`/app/order/payRideFee`, data).then((resp) => {
							if (resp.code == 200) {
								let that = this
								if(resp.data.needPay == true){
									uni.requestPayment({
										provider: 'wxpay',
										timeStamp: resp.data.payParams.timeStamp,
										nonceStr: resp.data.payParams.nonceStr,
										package: resp.data.payParams.packageVal,
										signType: resp.data.payParams.signType,
										paySign: resp.data.payParams.paySign,
										success: (respc) => {
											console.log(respc, '支付成功')
											that.$u.put(`/app/pay/refreshPayResult?no=${resp.data.pay.no}`).then((res) => {
												that.orderInfo()
												that.dikouflag = true
											})
											uni.hideLoading()
										},
										fail(err) {
											setTimeout(() => {
												uni.hideLoading()
											}, 1000)
											that.dikouflag = true
											console.log('取消或者支付失败')
										}
									})
								}else{
									setTimeout(()=>{
										that.orderInfo()
										that.dikouflag = true
										uni.hideLoading()
										uni.showToast({
											title: '操作成功',
											icon: 'success',
											duration:2000
										})
									},2000)
								}
							} else {
								uni.hideLoading()
								uni.showToast({
									title: resp.msg,
									icon: 'none',
									duration: 2000
								})
								this.dikouflag = true
							}
						}).catch(e => {
							this.dikouflag = true
							uni.hideLoading()
						})
				}
			},
			
			// 计算骑行时间
			calculateRideDuration() {
				if(this.info.startTime != null){
					const createTime = new Date(this.info.startTime)
					let returnTime = ''
					if(this.info.status === 'PROCESSING'){
						// 进行中订单，计算到当前时间
						returnTime = new Date()
						const duration = (returnTime - createTime) / 1000 // 时间差，单位秒
						const hours = Math.floor(duration / 3600)
						const minutes = Math.floor((duration % 3600) / 60)
						if (hours > 0) {
							this.rideDuration = `${hours}小时${minutes}分`
						} else {
							this.rideDuration = `${minutes}分`
						}
					} else if(this.info.endTime != null){
						// 非进行中订单，计算到结束时间
						returnTime = new Date(this.info.endTime)
						const duration = (returnTime - createTime) / 1000 // 时间差，单位秒
						const hours = Math.floor(duration / 3600)
						const minutes = Math.floor((duration % 3600) / 60)
						const seconds = Math.floor(duration % 60)
						if (hours > 0) {
							this.rideDuration = `${hours}小时${minutes}分${seconds}秒`
						} else {
							this.rideDuration = `${minutes}分${seconds}秒`
						}
					}
				}
			},
			// 点击拨打平台客服电话
			btnptkf(tel){
				uni.makePhoneCall({
					phoneNumber: tel,
					success: function(res) {
						console.log('拨打电话成功', res)
					},
					fail: function(err) {
						console.error('拨打电话失败', err)
					}
				})
			},
			btntel(){
				this.$u.get(`/app/customerService/list?pageNum=1&pageSize=999&areaId=${this.info.areaId}`).then(res => {
					if(res.code == 200){
						if(res.rows.length > 0){
							this.kefulist = res.rows
							this.kefuflag = true
						}else{
							uni.showToast({
								title: '暂无客服电话',
								icon: 'none',
								duration:2000
							})
						}
					}
				})
			},
			// 新增优惠券相关方法
			openCouponPopup() {
				if (this.info.status !== 'RIDE_WAIT_PAY') return;
				this.showCouponPopup = true;
			},
			
			closeCouponPopup() {
				this.showCouponPopup = false;
			},
			// 获取本人优惠劵
			getCouponList() {
				this.$u.get(`/app/vipUser/list?pageNum=1&pageSize=999&areaId=${this.info.areaId}&isEffective=true&minSurplusCount=1`).then(res =>{
					if(res.code == 200){
						this.couponList = res.rows
					}
				})
			},
			// 确定选择优惠券
			useCoupon(coupon) {
				console.log(coupon);
				this.selectedCoupon = coupon
				this.couponList.forEach(item => {
					item.used = item.id === coupon.id
				})
				uni.showToast({
					title: '选择优惠券成功',
					icon: 'success',
					duration:2000
				})
				this.getyouhui()
				this.closeCouponPopup()
			},
			// 选择优惠券计算价格
			getyouhui(){
				if(this.selectedCoupon && this.selectedCoupon.id){
					this.vipUserId = this.selectedCoupon.id
				}
				let data = {
					orderId:this.id,
					vipUserId:this.vipUserId
 				}
				this.$u.post(`/app/order/calcRideFee`,data).then(res =>{
					if(res.code == 200){
						this.info.totalFee = res.data.payAmount
						this.youhuiobj = res.data
					}
				})
			},
		}
	}
</script>
<style lang="scss">
        page{
        	background-color: #F7FAFE;
        }
        .map {
			position: relative;
			width: 750rpx;
			height: 752rpx;
			.track {
				position: absolute;
				display: flex;
				align-items: center;
				justify-content: center;
				left: 30rpx;
				bottom: 40rpx;
				border-radius: 50%;
				width: 82rpx;
				height: 82rpx;
				.img {
					width: 82rpx;
					height: 82rpx;
				}
			}
			.park {
				position: absolute;
				display: flex;
				align-items: center;
				justify-content: center;
				right: 30rpx;
				bottom: 40rpx;
				border-radius: 50%;
				width: 82rpx;
				height: 82rpx;
				.img {
					width: 82rpx;
					height: 82rpx;
				}
			}
		}        
		.kfrens{
			position: fixed;
			right: 30rpx;
			top: 40%;
			z-index: 99;
			width: 140rpx;
			height: 140rpx;
			.kfren{
				width: 80rpx;
				height: 80rpx;
				display: block;
				box-shadow: 0 0 20rpx rgba(124, 124, 124, 0.3);
				  -webkit-box-shadow: 0 0 20rpx #7C7C7C;
				  -moz-box-shadow: 0 0 20rpx #7C7C7C;
				  border-radius: 50%;
				  margin: auto;
				  margin-bottom: 20rpx;
			}
			text-align: center;
		}
     .kefutc{
		animation: fadeIn 0.5s ease-in-out forwards;
		position: fixed;
		top: 660rpx;
		left: 50%;
		transform: translateX(-50%);
		z-index: 999;
		.bot{
			margin-top: 30rpx;
			.wz{
				margin-top: 10rpx;
				font-size: 28rpx;
				color: #3D3D3D;
			}
			.wzs{
				margin-top: 10rpx;
				font-size: 24rpx;
				color: #7C7C7C;
			}
		}
		.top{
			width: 538rpx;
			height: 122rpx;
			background: #FFFFFF;
			box-shadow: 0rpx 0rpx 10rpx 0rpx rgba(0,0,0,0.1);
			border-radius: 14rpx 14rpx 14rpx 14rpx;
			display: flex;
			justify-content: space-between;
			align-items: center;
			padding-right: 14rpx;
			box-sizing: border-box;
			margin-top: 20rpx;
			.dianhua{
				font-weight: 600;
				font-size: 28rpx;
				color: #3D3D3D;
				padding-left: 26rpx;
				box-sizing: border-box;
			}
			.boda{
				width: 94rpx;
				height: 94rpx;
				background: #DCEDFF;
				border-radius: 8rpx 8rpx 8rpx 8rpx;
				text-align: center;
				padding-top: 8rpx;
				box-sizing: border-box;
				text{
					display: block;
				}
			}
		}
		image{
			position: absolute;
			top: -280rpx;
			z-index: -1;
			left: 50%;
			transform: translateX(-50%);
			width: 614rpx;
			height: 748rpx;
		}
	}
	.mask{
		width: 100%;
		height: 100vh;
		position: fixed;
		top: 0;
		left: 0;
		background-color: rgba(0,0,0,0.3);
		z-index: 9;
	}
    .page{
	width: 750rpx;
	background: #F7F7F7;
	border-radius: 0rpx 0rpx 0rpx 0rpx;
	padding-bottom: 250rpx;
	box-sizing: border-box;
	// .kefu{
	// 	width: 48%;
	// 	height: 100rpx;
	// 	line-height: 100rpx;
	// 	background-color: #4C97E7;
	// 	color: #fff;
	// 	font-size: 36rpx;
	// 	font-weight: 600;
	// 	text-align: center;
	// 	border-radius: 20rpx;
	// }
	.qixing{
		width: 702rpx;
		height: 466rpx;
		background: #FFFFFF;
		border-radius: 16rpx 16rpx 16rpx 16rpx;
		padding: 0 42rpx;
		box-sizing: border-box;
		margin: auto;
		margin-top: 32rpx;
		.top{
			font-weight: 600;
			font-size: 32rpx;
			color: #3D3D3D;
			padding: 36rpx 0 24rpx 0;
			box-sizing: border-box;
			border-bottom: 1px dashed #D8D8D8;
		}
		.xuxian{
			.one{
				display: flex;
				justify-content: space-between;
				align-items: center;
				margin-top: 30rpx;
				.qian{
					color: #808080;
					font-size: 28rpx;
				}
				.shen{
					color: #3D3D3D;
				}
			}
		}
	}
	.ordermx{
		width: 702rpx;
		max-height: 1862rpx;
		background: #FFFFFF;
		border-radius: 16rpx 16rpx 16rpx 16rpx;
		padding: 0 42rpx;
		box-sizing: border-box;
		margin: auto;
		margin-top: 32rpx;
		.xuxian{
			padding-bottom: 24rpx;
			box-sizing: border-box;
			border-bottom: 1px dashed #D8D8D8;
			.one{
				display: flex;
				justify-content: space-between;
				align-items: center;
				margin-top: 30rpx;
				.qian{
					color: #808080;
					font-size: 28rpx;
				}
				.shen{
					color: #3D3D3D;
					image{
						width: 23rpx;
						height: 28rpx;
						vertical-align: baseline;
						margin-left: 10rpx;
					}
				}
			}
		}
		.top{
			font-weight: 600;
			font-size: 32rpx;
			color: #3D3D3D;
			padding: 36rpx 0 24rpx 0;
			box-sizing: border-box;
			border-bottom: 1px dashed #D8D8D8;
		}
		
	}
	.jiaoyi{
		width: 702rpx;
		height: 210rpx;
		background: #FFFFFF;
		border-radius: 16rpx 16rpx 16rpx 16rpx;
		margin: auto;
		text-align: center;
		margin-top: 26rpx;
		.pic{
			padding-top: 34rpx;
			display: flex;
			align-items: center;
			justify-content: center;
			width: 100%;
			image{
				width: 38rpx;
				height: 38rpx;
				margin-right: 10rpx;
			}
			font-weight: 600;
			font-size: 40rpx;
			color: #4C97E7;
		}
		.gx{
			font-size: 28rpx;
			color: #808080;
			margin-top: 20rpx;
		}
	}
	.bottom-content {
		width: 100%;
		display: flex;
		gap: 20rpx;
		.coupon-select {
			display: flex;
			justify-content: space-between;
			width:660rpx;
			height: 40rpx;
			line-height: 40rpx;
			background-color: #fff;
			color: #ff6f6f;
			font-size: 22rpx;
			border-radius: 20rpx;
			border: 2rpx dashed #ff6f6f;
			padding: 0 20rpx;
			box-sizing: border-box;
			position: absolute;
			top: 10rpx;
			left: 50%;
			transform: translateX(-50%);
			border-radius: 0;
			.selected-coupon {
				font-size: 24rpx;
				color: #666;
				position: absolute;
				bottom: 10rpx;
				left: 50%;
				transform: translateX(-50%);
				width: 100%;
				text-align: center;
				white-space: nowrap;
				overflow: hidden;
				text-overflow: ellipsis;
			}
		}
		
		.kefu {
			width: 100%;
			height: 100rpx;
			background-color: #4C97E7;
			color: #fff;
			font-size: 36rpx;
			font-weight: 600;
			text-align: center;
			border-radius: 20rpx;
			padding-top: 10rpx;
			box-sizing: border-box;
			.xiao{
				font-size: 20rpx;
				color: #efefef;
				display: block;
			}
		}
	}
	.coupon-popup {
		position: fixed;
		top: 0;
		left: 0;
		width: 100%;
		height: 100%;
		z-index: 999;
		
		.coupon-mask {
			position: absolute;
			top: 0;
			left: 0;
			width: 100%;
			height: 100%;
			background-color: rgba(0, 0, 0, 0.5);
		}
		
		.coupon-content {
			position: absolute;
			bottom: 0;
			left: 0;
			width: 100%;
			background-color: #fff;
			border-radius: 20rpx 20rpx 0 0;
			padding: 30rpx;
			box-sizing: border-box;
			max-height: 60vh;
			
			.coupon-header {
				display: flex;
				justify-content: space-between;
				align-items: center;
				margin-bottom: 30rpx;
				
				text {
					font-size: 32rpx;
					font-weight: 600;
					color: #333;
				}
				
				.close-btn {
					font-size: 40rpx;
					color: #999;
					padding: 10rpx;
				}
			}
			
			.coupon-list {
				max-height: calc(60vh - 100rpx);
				overflow-y: auto;
				padding-bottom: 50rpx;
				box-sizing: border-box;
				.coupon-item {
					display: flex;
					justify-content: space-between;
					align-items: center;
					padding: 20rpx;
					background-color: #f8f8f8;
					border-radius: 10rpx;
					margin-bottom: 20rpx;
					
					.coupon-info {
						flex: 1;
						
						.coupon-name {
							font-size: 28rpx;
							color: #333;
							margin-bottom: 10rpx;
						}
						
						.coupon-detail {
							font-size: 24rpx;
							color: #999;
							
							text {
								display: block;
								margin-bottom: 6rpx;
							}
						}
					}
					
					.coupon-btn {
						width: 120rpx;
						height: 60rpx;
						line-height: 60rpx;
						text-align: center;
						background-color: #4C97E7;
						border-radius: 30rpx;
						margin-left: 20rpx;
						
						text {
							color: #fff;
							font-size: 24rpx;
							
							&.used {
								color: #ccc;
							}
						}
					}
				}
				
				.no-coupon {
					text-align: center;
					color: #999;
					font-size: 28rpx;
					padding: 40rpx 0;
				}
			}
		}
	}
}
</style>
