<template>
	<view class="pages">
		<!-- 地址 -->
		<view class="text-center text-red" v-if="isTrue && orderType == 2">超出配送距离</view>
		<view class="food">
			<view class="flex bg justify-between padding-lr-xl">
				<view @click="switchTab(2)" :class="orderType == 2 ? 'select' : ''" class="tabBtn"
					v-if="XCXIsSelect == '是'">
					<view class="title">外卖配送</view>
					<view :class="orderType == 2 ? 'active' : ''"></view>
				</view>
				<view @click="switchTab(1)" :class="orderType == 1 ? 'select' : ''" class="tabBtn">
					<view class="title">到店自取</view>
					<view :class="orderType == 1 ? 'active' : ''"></view>
				</view>
			</view>
			<view v-if="orderType == 1">
				<!-- <view class="text-black text-lg margin-top">商家地址</view> -->
				<view class="flex margin-top" style="">
					<u-icon name="map" size="50"></u-icon>
					<view class="flex-sub padding-tb-sm margin-left-sm">
						<view class="text-lg text-bold text-black">
							<text>{{ dataList.shopName }}</text>
							<text class="margin-left-sm" @click="call">{{ dataList.shopPhone }}</text>
						</view>
						<view class="text-df margin-top-xs" style="color: #999999;" @click="goMap">
							{{ dataList.detailedAddress }}
						</view>
					</view>
				</view>
			</view>
			<view class="" v-if="orderType == 2">
				<view class="goods_address" v-if="JSON.stringify(address) == '{}'" @click="goAddress">
					<view class="address_box">
						<view class="address_name">请选择收货地址</view>
						<view class="address_image margin-left">
							<image src="../../../static/images/index/right.png"></image>
						</view>
					</view>
				</view>
				<view class="flex margin-top" style="" v-else @click="goAddress">
					<u-icon name="map" size="50"></u-icon>
					<view class="flex-sub padding-tb-sm margin-left-sm">
						<view class="text-lg text-bold text-black">
							<text>{{ address.userName }}</text>
							<text class="margin-left-sm">{{ address.userPhone }}</text>
						</view>
						<view class="text-df margin-top-xs" style="color: #999999;">
							{{ address.province }}{{ address.city }}{{ address.district }}{{ address.addressDetail }}
						</view>
					</view>
					<view class="address_image margin-left">
						<image src="../../../static/images/index/right.png"></image>
					</view>
				</view>
			</view>
		</view>

		<!-- 商品 -->
		<view class="food">
			<view class="tosend_header_food" v-for="(item, index) in goodsList" :key="index">
				<view class="tosend_header_food_le">
					<image :src="item.goodsPicture[0]" style="border-radius: 10rpx;" mode=""></image>
				</view>
				<view class="flex-sub margin-left-sm">
					<view class="flex justify-between align-center">
						<view class="text-lg text-bold text-black">{{ item.goodsName }}</view>
						<view class="text-lg text-bold text-black">
							<text class="text-sm">¥</text>
							{{ item.goodsPrice }}
						</view>
					</view>
					<view class="flex justify-between align-center text-gray">
						<view v-if="item.skuMessage">{{ item.skuMessage }}</view>
						<view>x{{ item.goodsNum }}</view>
					</view>
					<view class="flex justify-between align-center text-gray margin-tb-sm">
						<view>打包费</view>
						<view class="">￥{{ item.goodsPack }} / 份</view>
					</view>
				</view>
			</view>
			<!-- <view class="tosend_header_do do_top" v-if="item.goodsPack>0" >
				<view>打包费</view>
				<view class="tosend_header_do_ri">￥{{item.goodsPack}}</view>
			</view> -->
			<view class="tosend_header_do justify-between" v-if="paotuiMoney > 0 && orderType == 2">
				<view>跑腿费</view>
				<view class="tosend_header_do_ri">￥{{ paotuiMoney }}</view>
			</view>
			<view class="tosend_header_do justify-between do_bot" @click="isShow">
				<view>优惠券</view>
				<view class="tosend_header_do_ri" v-if="coupon">- ￥{{ coupon.money }}</view>
				<view v-else>
					<image src="../../../static/images/order/right1.png" style="width: 14rpx;height: 24rpx;" mode="">
					</image>
				</view>
			</view>
			<view class="tosend_header_do justify-between">
				<view class="tosend_header_do_le2">合计</view>
				<view class="tosend_header_do_ri2">
					<text>￥</text>
					{{ totalPrice1 }}
				</view>
			</view>
		</view>
		<!-- 订单备注 -->
		<view class="food">
			<view class="padding-tb-sm text-lg text-bold text-bold text-black">订单备注</view>
			<view class="flex align-center justify-between padding-tb-sm padding-lr"
				style="background: #f5f5f5;width: 100%;">
				<u-input v-model="remark" type="textarea" placeholder="请输入订单备注" height="180" maxlength="200"
					style="width: 100%;"></u-input>
			</view>
		</view>

		<!-- 支付方式 -->
		<view class="food">
			<view class="padding-tb-sm text-lg text-bold text-bold text-black">支付方式</view>
			<view style="height: 100upx;" v-for="(item, index) in openLists" :key="index">
				<view class="flex align-center justify-between padding-tb" v-if="item.text != '零钱'">
					<image :src="item.image" style="width: 55rpx;height: 55rpx;border-radius: 50upx;"></image>
					<view class="flex-sub text-xl margin-left">{{ item.text }}</view>
					<radio-group name="openWay" style="margin-left: 20upx;" @change="selectWay(item)">
						<label class="tui-radio">
							<radio class="red" :checked="openWay === item.id ? true : false" />
						</label>
					</radio-group>
				</view>
				<view class="flex align-center justify-between padding-tb" v-if="item.text === '零钱'">
					<image :src="item.image" style="width: 55rpx;height: 55rpx;border-radius: 50upx;"></image>
					<view class="flex-sub text-xl margin-left">{{ item.text }} <text
							style="font-size: 30rpx;margin-left: 10rpx;"
							v-if="userMoney && userMoney > 0">(余额：{{userMoney}})</text>
						<text v-else
							style="font-size: 30rpx;margin-left: 10rpx;text-decoration:underline;color: #ea0000;"
							@tap="goCash()">去充值</text>
					</view>
					<radio-group name="openWay" style="margin-left: 20upx;" @change="selectWay(item)">
						<label class="tui-radio">
							<radio class="red" :checked="openWay === item.id ? true : false" />
						</label>
					</radio-group>
				</view>
			</view>
		</view>
		<view style="height: 120rpx;"></view>
		<!-- 结算 -->
		<view class="goorder">
			<!-- <view class="goorder_but" @click="toSettlement">立即结算</view> -->
			<view class="goorder_but" :class="isTrue && orderType == 2 ? 'goorder_but_' : ''" @click="toSettlement">立即结算
			</view>
		</view>

		<view class="hintPopul" v-if="shopDet && shopDet.putawayFlag == 1">
			<view class="content_">
				<image src="../../../static/images/index/shop.png" style="width: 200rpx;height: 180rpx;"></image>
				<view class="text-xl text-bold">店铺打烊啦</view>
				<view class="hintText margin-top-sm text-gray">现在店铺已经打烊了,营业时间</view>
				<view class="margin-top-xs text-gray margin-bottom">{{ shopDet.businessHours }}-{{ shopDet.lockHours }}
				</view>
				<view class="Btns" @click="goBack()">知道了</view>
			</view>
		</view>

		<u-popup v-model="show" mode="center" :closeable="true" close-icon-pos="top-right" close-icon="close-circle"
			close-icon-size="50" border-radius="20" width="80%" @close="close">
			<view class="padding bg-gray">
				<view class="text-center text-lg text-bold margin-bottom-sm">可用优惠券</view>
				<scroll-view scroll-y="true" style="height: 600rpx;" v-if="couponList.length > 0">
					<view class="flex justify-between align-center radius margin-tb-sm padding-sm bg-white"
						v-for="(item, index) in couponList" :key="index" @click="selCoupon(item)">
						<view>
							<view>{{ item.couponName }}</view>
							<view>有效期至{{ item.expirationTime }}</view>
						</view>
						<view class="text-sm text-bold">
							¥
							<text class="text-lg">{{ item.money }}</text>
						</view>
					</view>
				</scroll-view>
				<view v-if="couponList.length == 0"
					style="height: 100rpx;line-height: 100rpx;text-align: center;font-weight: 700;">暂无可用优惠券</view>
			</view>
		</u-popup>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				userMoney: 0,
				shopDet: '',
				isThrottle: true, //防抖，待支付结果返回后继续
				storeCommodityId: 0,
				openLists: [],
				openWay: 2,
				orderId: '',
				page: 1,
				limit: 100,
				dataList: [],
				packMoney: 0, //打包费
				totalPrice: 0,
				totalPrice1: 0,
				address: {}, //地址
				addressId: '',
				parentId: '',
				shopId: '',
				show: false,
				coupon: '',
				couponList: [],
				orderType: 2,
				paotuiMoney: 0,
				dabaoMoney: 0,
				goodsMoney: null,
				distance: 0,
				isTrue: false,
				goodsList: [],
				XCXIsSelect: '是',
				remark: '',
				GoodsorderId: '',
				ifPaotui:0,//是否满减
				lng:'',
				lat:''
			};
		},
		onLoad(option) {
			// #ifdef APP
			this.openLists = [{
					image: '../../../static/images/my/weixin.png',
					text: '微信',
					id: 2
				},
				{
					image: '../../../static/images/my/zhifubao.png',
					text: '支付宝',
					id: 3
				},
				{
					image: '../../../static/images/my/jinbi.png',
					text: '零钱',
					id: 1
				}
			];
			// #endif

			// #ifdef MP-WEIXIN
			this.XCXIsSelect = this.$queue.getData('XCXIsSelect') ? this.$queue.getData('XCXIsSelect') : '是';
			this.openLists = [{
					image: '../../../static/images/my/weixin.png',
					text: '微信',
					id: 2
				},
				{
					image: '../../../static/images/my/jinbi.png',
					text: '零钱',
					id: 1
				}
			];
			// #endif

			// #ifdef H5
			this.openLists = [{
					image: '../../../static/images/my/weixin.png',
					text: '微信',
					id: 2
				},
				{
					image: '../../../static/images/my/zhifubao.png',
					text: '支付宝',
					id: 3
				},
				{
					image: '../../../static/images/my/jinbi.png',
					text: '零钱',
					id: 1
				}
			];
			// #endif

			this.shopId = option.shopId;
			// #ifndef H5
			uni.getLocation({
				type: 'gcj02', //返回可以用于uni.openLocation的经纬度
				success: function(res) {
					this.lat = res.latitude;
					this.lng = res.longitude;
			
				}
			});
			this.getShopDet(this.shopId);
			// #endif
			// #ifdef H5
			uni.getLocation({
				type: 'gcj02', //返回可以用于uni.openLocation的经纬度
				success: function(res) {
					this.lat = res.latitude;
					this.lng = res.longitude;
				}
			});
			
			this.getShopDet(this.shopId);
			// #endif
			
			this.orderType = option.orderType;
			if (option.orderId) {
				this.orderId = option.orderId;
			}

			uni.showLoading({
				title: '加载中...'
			});
			// this.getOrderList();
			this.getAddressList();
		},
		onShow() {
			this.getMsgData();
			console.log(uni.getStorageSync('addressId'), '地址id');
			this.addressId = this.addressId ? this.addressId : uni.getStorageSync('addressId');
			if (this.addressId) {
				console.log(this.addressId, '地址id');
				this.address = {};
				this.getAddressDet(this.addressId);
			}
		},
		methods: {
			goCash() {
				uni.navigateTo({
					url: '/my/wallet/index'
				});
			},
			getMsgData() {
				this.$Request.get("/app/userintegral/findUserMessage").then(res => {
					if (res.code == 0 && res.data) {
						this.userMoney = res.data.userMoney ? res.data.userMoney : 0;
					}
				});
			},
			//获取店铺详情
			getShopDet(shopId) {
				let data = {
					shopId,
					lng: this.lng,
					lat: this.lat
				};
				this.$Request.get('/app/goods/selectGoodsList', data).then(res => {
					if (res.code == 0 && res.data) {
						this.shopDet = res.data.goodsShop;
						this.ifPaotui=res.data.goodsShop.enableFullReductionFlag
						this.getOrderList();
					}
				});
			},
			goBack() {
				uni.navigateBack({});
			},
			isShow() {
				this.show = true;
			},
			getDistance() {
				if (this.address.lng && this.dataList.shopLng) {
					let data = {
						ol: this.address.lng,
						od: this.address.lat,
						dl: this.dataList.shopLng,
						dd: this.dataList.shopLat
					};
					this.$Request.post('/app/tbindent/distance', data).then(res => {
						if (res.code == 0) {
							this.distance = res.data;
							if (this.distance > Number(this.dataList.distributionDistance)) {
								this.isTrue = true;
							} else {
								this.isTrue = false;
							}
						}
					});
				}
			},
			close() {
				this.show = false;
			},
			switchTab(e) {
				this.orderType = e;
				this.coupon = '';
				if (JSON.stringify(this.address) != '{}') {
					this.getDistance();
				}
				if (this.orderType == 2) {

					this.totalPrice1 = parseFloat(parseFloat(this.totalPrice) + parseFloat(this.paotuiMoney) + parseFloat(
						this.dabaoMoney)).toFixed(2);

				} else {
					this.totalPrice1 = parseFloat(parseFloat(this.totalPrice) + parseFloat(this.dabaoMoney)).toFixed(2);
				}
				if (this.coupon) {
					let totalMoney = parseFloat(parseFloat(this.totalPrice1) - (parseFloat(this.coupon.money) ? parseFloat(
						this.coupon.money) : 0)).toFixed(2);
					if (totalMoney <= 0) {
						this.totalPrice1 = 0.01;
					} else {
						this.totalPrice1 = totalMoney;
					}
				}
			},
			// 删除优惠券
			detCoupon() {
				let data = {
					orderId: this.dataList.orderId
				};
				this.$Request.post('/app/order/deleteCouponByOrderId', data).then(res => {
					if (res.code == 0) {}
				});
			},
			// 选择优惠券
			selCoupon(item) {
				this.coupon = item;
				if (this.orderType == 2) {
					this.totalPrice1 = parseFloat(this.totalPrice + this.paotuiMoney + this.dabaoMoney).toFixed(2);
				} else {
					this.totalPrice1 = parseFloat(this.totalPrice + this.dabaoMoney).toFixed(2);
				}

				let totalMoney = parseFloat(this.totalPrice1 - (this.coupon.money ? this.coupon.money : 0)).toFixed(2);

				if (totalMoney <= 0) {
					this.totalPrice1 = 0.01;
				} else {
					this.totalPrice1 = totalMoney;
				}

				let data = {
					parentId: this.dataList.parentId,
					couponId: this.coupon ? this.coupon.id : ''
				};
				this.$Request.post('/app/order/employCoupon', data).then(res => {
					if (res.code == 0) {
						this.show = false;
					}
				});
			},
			// 优惠卷列表
			getCouponList() {
				// console.log(this.paotuiMoney)
				// console.log(this.dabaoMoney, '123123')
				let minMoney =
					this.orderType == 2 ?
					parseFloat(parseFloat(this.totalPrice) + parseFloat(this.paotuiMoney) + parseFloat(this.dabaoMoney))
					.toFixed(2) :
					parseFloat(this.totalPrice).toFixed(2);
				let data = {
					shopId: this.dataList.shopId,
					page: 1,
					limit: 10,
					minMoney: minMoney
				};
				this.$Request.get('/app/coupon/selectUserCouponList', data).then(res => {
					if (res.code == 0) {
						this.couponList = res.data.list;
					}
				});
			},

			//拼单支付成功取消订单

			cancelPinDan() {
				let that = this;
				// if (that.orderId) {
				// 	let data = {
				// 		orderId: that.orderId
				// 	};
				// 	that.$Request.post('/app/order/deleteOrder', data).then(res => {
				// 		if (res.code == 0) {
				// 			uni.removeStorageSync('orderId');
				// 		}
				// 	});
				// }
			},
			// 商品列表
			getOrderList() {
				let data = {
					shopId: this.shopId,
					status: 1,
					page: 1,
					limit: 1000
					// orderType: this.orderType
				};
				this.$Request.get('/app/order/selectAllOrderList', data).then(res => {
					uni.hideLoading();
					if (res.code == 0 && res.data.pageUtils.list) {
						this.GoodsorderId = res.data.pageUtils.list[0].orderId;
						this.dataList = res.data.pageUtils.list[0];

						if (this.dataList && this.dataList.orderGoodsList && this.dataList.orderGoodsList[0]) {
							this.dataList.orderGoodsList[0].forEach(res => {
								res.goodsPicture = res.goodsPicture.split(',');
								this.dabaoMoney += res.goodsPack * res.goodsNum;
								this.goodsMoney += res.goodsPrice * res.goodsNum;
								this.goodsMoney = parseFloat(this.goodsMoney + this.dabaoMoney);
							});
							this.goodsList = this.dataList.orderGoodsList[0];
						}

						// this.paotuiMoney = this.dataList.errandMoney
						if(this.ifPaotui==1){
							this.paotuiMoney = this.dataList.errandMoney;
						}else if(this.ifPaotui==0){
							// 判断商品金额是否大于最低减免配送费金额
							console.log(this.goodsMoney, '商品总金额', res,this.dataList.exemptMinMoney)
							if (Number(this.goodsMoney) >= Number(this.dataList.exemptMinMoney)) {
								this.paotuiMoney = 0;
							} else {
								this.paotuiMoney = this.dataList.errandMoney;
							}
						}
						
						this.totalPrice = res.data.money;
						if (this.orderType == 2) {
							this.totalPrice1 = parseFloat(parseFloat(this.totalPrice) + parseFloat(this
								.paotuiMoney) + parseFloat(this.dabaoMoney)).toFixed(2);
						} else {
							this.totalPrice1 = parseFloat(parseFloat(this.totalPrice) + parseFloat(this
								.dabaoMoney)).toFixed(2);
						}

						// console.log(this.dataList)
						this.getCouponList();
						this.detCoupon();
						this.getDistance();
					}
				});
			},
			selectWay(item) {
				this.openWay = item.id;
			},
			takeReark() {
				let datas = {
					orderId: this.GoodsorderId,
					remark: this.remark
				};
				this.$Request.post('/app/order/updateOrdersRemark', datas).then(res => {

					if (res.code == 0) {} else {
						uni.showToast({
							title: res.msg,
							icon: 'none'
						});
					}
				});
			},
			// 立即结算
			toSettlement() {
				if (this.isThrottle == false) {
					return
				}
				let that = this;

				if (this.isTrue && this.orderType == 2) {
					uni.showToast({
						title: '超出配送范围',
						icon: 'none'
					});
					reutrn;
				}
				if (this.orderType == 2 && !this.address.addressId) {
					uni.showToast({
						title: '请选择收货地址',
						icon: 'none'
					});
					return;
				}
				if (this.remark) {
					this.takeReark();
				}
				uni.showLoading({
					title: '支付中...'

				});
				this.isThrottle = false
				if (this.openWay == 1) {
					//零钱支付
					let data = {
						parentId: this.dataList.parentId,
						couponId: this.coupon ? this.coupon.id : '',
						addressId: this.address.addressId ? this.address.addressId : '',
						orderType: this.orderType
					};
					this.$Request.post('/app/wxPay/balanceOrder', data).then(res => {

						if (res.code == 0) {
							uni.hideLoading();
							that.$queue.showToast('支付成功');
							that.cancelPinDan();
							setTimeout(function() {
								that.isThrottle = true
								uni.switchTab({
									url: '/pages/order/index'
								});
							}, 1000);
						} else {
							that.$queue.showToast(res.msg);
							that.isThrottle = true
						}
					});
				} else if (this.openWay == 2) {
					//微信支付
					// #ifdef H5
					let data = {
						parentId: this.dataList.parentId,
						couponId: this.coupon ? this.coupon.id : '',
						addressId: this.address.addressId ? this.address.addressId : '',
						orderType: this.orderType,
						type: 2
					};
					this.$Request.post('/app/wxPay/wxPayJsApiOrder', data).then(res => {
						uni.hideLoading();
						if (res.code == 0) {
							this.callPay(res.data);
						} else {
							uni.showToast({
								title: res.msg,
								icon: 'none'
							});
							this.isThrottle = true
						}
					});
					// #endif
					// #ifdef MP-WEIXIN

					let data = {
						parentId: this.dataList.parentId,
						couponId: this.coupon ? this.coupon.id : '',
						addressId: this.address.addressId ? this.address.addressId : '',
						orderType: this.orderType,
						type: 3
					};
					this.$Request.post('/app/wxPay/wxPayJsApiOrder', data).then(res => {
						// uni.hideLoading();
						if (res.code == 0) {
							uni.requestPayment({
								provider: 'wxpay',
								timeStamp: res.data.timestamp,
								nonceStr: res.data.noncestr,
								package: res.data.package,
								signType: res.data.signType,
								paySign: res.data.sign,
								success: function(suc) {
									that.cancelPinDan();
									uni.hideLoading();
									that.$queue.showToast('支付成功');
									setTimeout(function() {
										that.isThrottle = true
										uni.switchTab({
											url: '/pages/order/index'
										});
									}, 1000);
								},
								fail: function(err) {
									console.log('fail:' + JSON.stringify(err));
									that.isThrottle = true
									uni.showToast({
										title: '支付失败',
										icon: 'none'
									});
								}
							});
						} else {
							uni.showToast({
								title: res.msg,
								icon: 'none'
							});
							that.isThrottle = true
						}
					});
					// #endif

					// #ifdef APP
					let data = {
						type: 1,
						parentId: this.dataList.parentId,
						couponId: this.coupon ? this.coupon.id : '',
						addressId: this.address.addressId ? this.address.addressId : '',
						orderType: this.orderType
					};
					this.$Request.post('/app/wxPay/wxPayJsApiOrder', data).then(res => {
						console.log(res);
						this.showpay = false;
						if (res.code == 0) {
							this.isCheckPay(res.code, 'wxpay', JSON.stringify(res.data));
						} else {
							that.isThrottle = true
						}
					});
					// #endif
				} else if (this.openWay == 3) {
					// #ifdef H5
					let data = {
						type: 5,
						parentId: this.dataList.parentId,
						couponId: this.coupon ? this.coupon.id : '',
						addressId: this.address.addressId ? this.address.addressId : '',
						orderType: this.orderType
					};
					this.$Request.post('/app/wxPay/wxPayJsApiOrder', data).then(res => {
						this.showpay = false;
						this.isThrottle = true
						const div = document.createElement('div');
						div.innerHTML = res.data; //此处form就是后台返回接收到的数据
						document.body.appendChild(div);
						document.forms[0].submit();
					});
					// #endif

					// #ifdef APP
					let data = {
						type: 4,
						parentId: this.dataList.parentId,
						couponId: this.coupon ? this.coupon.id : '',
						addressId: this.address.addressId ? this.address.addressId : '',
						orderType: this.orderType
					};
					this.$Request.post('/app/wxPay/wxPayJsApiOrder', data).then(res => {
						this.showpay = false;
						this.setPayment('alipay', res.data);
					});
					// #endif
				}
			},
			callPay: function(response) {
				if (typeof WeixinJSBridge === 'undefined') {
					if (document.addEventListener) {
						document.addEventListener('WeixinJSBridgeReady', this.onBridgeReady(response), false);
					} else if (document.attachEvent) {
						document.attachEvent('WeixinJSBridgeReady', this.onBridgeReady(response));
						document.attachEvent('onWeixinJSBridgeReady', this.onBridgeReady(response));
					}
				} else {
					this.onBridgeReady(response);
				}
			},
			onBridgeReady: function(response) {
				let that = this;
				if (!response.package) {
					return;
				}
				WeixinJSBridge.invoke(
					'getBrandWCPayRequest', {
						appId: response.appid, //公众号名称，由商户传入
						timeStamp: response.timestamp, //时间戳，自1970年以来的秒数
						nonceStr: response.noncestr, //随机串
						package: response.package,
						signType: response.signType, //微信签名方式：
						paySign: response.sign //微信签名
					},
					function(res) {
						if (res.err_msg === 'get_brand_wcpay_request:ok') {
							// 使用以上方式判断前端返回,微信团队郑重提示：
							//res.err_msg将在用户支付成功后返回ok，但并不保证它绝对可靠。

							that.cancelPinDan();
							that.$queue.showToast('支付成功');
							setTimeout(function() {
								uni.switchTab({
									url: '/pages/order/index'
								});
								that.isThrottle = true
							}, 1000);
						} else {
							uni.hideLoading();
							that.isThrottle = true
						}
						WeixinJSBridge.log(response.err_msg);
					}
				);
			},
			isCheckPay(code, name, order) {
				if (code == 0) {
					console.log('999999999999');
					this.setPayment(name, order);
				} else {
					uni.hideLoading();
					uni.showToast({
						title: '支付信息有误'
					});
					this.isThrottle = true
				}
			},
			setPayment(name, order) {
				let that = this;

				console.log(777777777, name, order);
				uni.requestPayment({
					provider: name,
					orderInfo: order, //微信、支付宝订单数据
					success: function(res) {
						uni.hideLoading();
						that.cancelPinDan();
						uni.showLoading({
							title: '支付成功',
							icon: 'none'
						});
						setTimeout(function() {
							that.isThrottle = true
							uni.navigateBack();
						}, 1000);
					},
					fail: function(err) {
						uni.hideLoading();
						that.isThrottle = true
					},
					complete() {
						that.isThrottle = true
						uni.hideLoading();
					}
				});
			},
			// 获取选择的地址
			getAddressDet(e) {
				this.$Request.get('/app/address/selectAddressById?addressId=' + e).then(res => {
					if (res.code == 0) {
						this.address = res.data;
						if (JSON.stringify(this.address) != '{}') {
							this.getDistance();
						}
						uni.removeStorageSync('addressId');
					}
				});
			},
			// 获取地址列表
			getAddressList() {
				let that = this;
				let data = {
					page: 1,
					limit: 100
				};
				that.$Request.get('/app/address/selectAddressList', data).then(res => {
					if (res.code == 0) {
						that.address = res.data.list[0] ? res.data.list[0] : {};
						res.data.list.forEach(ret => {
							if (ret.addressDefault == 1) {
								that.address = ret;
							}
						});

						if (JSON.stringify(this.address) != '{}') {
							this.getDistance();
						}
					}
				});
			},
			goAddress() {
				uni.navigateTo({
					url: '/my/address/index?add=1'
				});
			},
			// 点击调起地图查看位置
			goMap() {
				// let that = this
				// let plugin = requirePlugin('routePlan');
				// let key = 'A3RBZ-23MHW-PTPR5-RLCER-UJTXQ-JIF2G'; //使用在腾讯位置服务申请的key
				// let referer = that.dataList.shopName; //调用插件的app的名称
				// let endPoint = JSON.stringify({ //终点
				// 	'name': that.dataList.shopName,
				// 	'latitude': that.dataList.shopLat,
				// 	'longitude': that.dataList.shopLng,
				// });
				// wx.navigateTo({
				// 	url: 'plugin://routePlan/index?key=' + key + '&referer=' + referer + '&endPoint=' + endPoint
				// });

				let that = this;
				let lati = parseFloat(that.dataList.shopLat);
				let longi = parseFloat(that.dataList.shopLng);
				uni.authorize({
					scope: 'scope.userLocation',
					success(res) {
						uni.openLocation({
							name: that.dataList.shopName,
							latitude: lati,
							longitude: longi,
							success: function() {}
						});
					},
					fail(err) {}
				});
			},
			// 打电话
			call() {
				uni.makePhoneCall({
					phoneNumber: this.dataList.shopPhone
				});
			}
		}
	};
</script>

<style scoped>
	.hintPopul {
		width: 100%;
		height: 100vh;
		position: fixed;
		top: 0;
		background: rgba(0, 0, 0, 0.4);
		z-index: 999;
	}

	.content_ {
		position: absolute;
		left: 0;
		right: 0;
		top: 0;
		bottom: 0;
		margin: auto;
		text-align: center;
		width: 500rpx;
		height: 400rpx;
		border-radius: 20rpx;
		background-color: #fff;
		padding-top: 120rpx;
	}

	.content_ image {
		position: absolute;
		top: -50rpx;
		left: 0;
		right: 0;
		margin: auto;
	}

	.hintText {
		font-size: 30rpx;
	}

	.Btns {
		width: 460rpx;
		height: 60rpx;
		line-height: 60rpx;
		text-align: center;
		background: #fcd202;
		font-size: 28rpx;
		border: 2rpx solid #fcd202;
		color: #333333;
		border-radius: 50rpx;
		font-weight: 700;
		margin: auto;
	}


	.goods_address {
		width: 94%;
		background: #ffffff;
		height: 120rpx;
		margin: 20rpx auto 0;
		border-radius: 18rpx;
	}

	.address_box {
		width: 90%;
		margin: 0 auto;
		height: 120rpx;
		display: flex;
		line-height: 120rpx;
	}

	.address_name {
		flex: 1;
		font-size: 30rpx;
	}

	.address_image {
		/* flex: 1; */
		display: flex;
		justify-content: flex-end;
		align-items: center;
	}

	.address_image image {
		width: 25rpx;
		height: 40rpx;
	}

	/* 地址 */
	.address {
		width: 88%;
		margin: 3% auto;
		padding: 3%;
		display: flex;
		background-color: #ffffff;
		border-radius: 18rpx;
	}

	.adderss_le {
		width: 90%;
		line-height: 1.5;
	}

	.adderss_le_text {
		font-size: 30rpx;
		font-weight: bold;
		color: #333333;
	}

	.adderss_le_text2 {
		font-size: 24rpx;
		font-weight: 500;
		color: #999999;
		display: flex;
	}

	.adderss_le_text2 view {
		margin-left: 2%;
	}

	.adderss_le_text2 view:first-child {
		margin-left: 0;
	}

	.adderss_ri {
		width: 10%;
		text-align: right;
		line-height: 3;
	}

	.adderss_ri image {
		width: 18rpx;
		height: 30rpx;
	}

	/* 商品 */
	.food {
		width: 94%;
		margin: 3% auto;
		padding: 3%;
		background-color: #ffffff;
		border-radius: 18rpx;
	}

	.tosend_header_food {
		width: 100%;
		display: flex;
		margin-top: 3%;
	}

	.tosend_header_food_le {
		width: 15%;
	}

	.tosend_header_food_le image {
		width: 110rpx;
		height: 110rpx;
		border-radius: 10rpx;
	}

	.tosend_header_food_ce {
		margin: 0 0 0 4%;
		width: 57%;
	}

	.tosend_header_food_ri {
		text-align: right;
		width: 25%;
	}

	.tosend_header_food_text {
		font-size: 34rpx;
		font-weight: 500;
		color: #333333;
		line-height: 1.8;
	}

	.tosend_header_food_text text {
		font-size: 25rpx;
	}

	.tosend_header_food_text2 {
		font-size: 28rpx;
		font-weight: 500;
		color: #999999;
	}

	.do_top {
		padding-top: 3%;
	}

	.do_bot {
		padding-bottom: 3%;
		border-bottom: 2rpx solid #e6e6e6;
	}

	.tosend_header_do {
		width: 100%;
		color: #333333;
		font-size: 30rpx;
		display: flex;
		margin-top: 20rpx;
		line-height: 1.5;
	}

	.tosend_header_do view {
		/* flex: 1; */
	}

	.tosend_header_do_ri {
		text-align: right;
	}

	.tosend_header_do_le2 {
		font-family: PingFang SC;
		font-weight: 500;
		color: #999999;
		padding-top: 1.5%;
	}

	.tosend_header_do_ri2 {
		text-align: right;
		color: #ea0000;
		font-size: 40rpx;
	}

	.tosend_header_do_ri2 text {
		font-size: 30rpx;
	}

	/* 支付 */
	/* .payment_all{
		width: 88%;margin: 3% auto;padding: 3%;background-color: #FFFFFF;
		border-radius: 18rpx;
	}
	.payment{
		width: 100%;display: flex;margin-top: 3%;
	}
	.payment_le{
		width: 13%;
	}
	.payment_le image{
		width: 60rpx;height: 60rpx;
	}
	.payment_ce{
		width: 52%;
		font-size: 30rpx;
		font-weight: bold;
		color: #333333;line-height: 60rpx;
	}
	.payment_ri{
		width: 35%;text-align: right;line-height: 60rpx;
	} */
	/* 结算 */
	.goorder {
		width: 100%;
		padding: 2% 3%;
		position: fixed;
		bottom: 0;
		background-color: #ffffff;
		z-index: 999;
	}

	.goorder_but {
		width: 100%;
		line-height: 3.5;
		text-align: center;
		background: #fcd202;
		border-radius: 36rpx;
		font-weight: 700;
	}

	.goorder_but_ {
		opacity: 0.5;
	}

	.bg {
		background-color: #ffffff;
	}

	.tabBtn {
		/* background-color: #f6f6fa; */
		height: 60rpx;
		line-height: 60rpx;
		color: #999999;
		font-size: 38rpx;
	}

	.active {
		/* width: 82rpx; */
		height: 6rpx;
		background: #fcd202;
		/* position: relative;
		top: -20rpx; */
		z-index: 9;
	}
</style>