<template>
	<view class="contentV">
		<customNav :shownav="true" :title="$t('index.xiadanzhifu')" titledetl=""></customNav>

		<view class="ctinrow">
			<view class="topSwichV" :style="{backgroundColor:Bcolor}" @click="peisong">
				<view class="topSwichV">
					<image class="toppz" :src="peisongimg" mode="widthFix"></image>
					<text class="toppztext" :style="{color:Tcolor}">{{$t('order.peisong')}}</text>
				</view>
			</view>
			<view class="topSwichVL" :style="{backgroundColor:Bcolorr}" @click="ziqu">
				<view class="topSwichVL">
					<image class="toppz" :src="ziquimg" mode="widthFix"></image>
					<text class="toppztext" :style="{color:Tcolorr}">{{$t('order.ziqu')}}</text>
				</view>
			</view>
			<!-- <view class="topSwichVL" :style="{backgroundColor:Bcolorrr}" @click="tangshi">
				<view class="topSwichVL">
					<image class="toppz" :src="tangshiimg" mode="widthFix"></image>
					<text class="toppztext" :style="{color:Tcolorrr}">{{$t('shouye.tangshi')}}</text>
				</view>
			</view> -->
		</view>
		<label class="linesp"></label>
		<uni-list v-if="showAdrr==0">
			<uni-list-item :title="dizhiID.address" :note="dizhiID.phone" :rightText="dizhiID.name"
				thumb="/static/images/dizhil@3x.png" thumb-size="sm" @click="changaddr" link></uni-list-item>
		</uni-list>
		<uni-list>
			<uni-list-item :title="delryTime.length>0?$t('order.yuyueshijian'):$t('order.jinkuaisd')"
				:note="delryTime.length>0?delryTime:('10~20 '+$t('order.Xfenzhongsd'))"
				:rightText="$t('order.yuyueshijian')" thumb="/static/images/time@3x.png" thumb-size="sm"
				@click="yuyueshijian" link></uni-list-item>
		</uni-list>
		<label class="linesp"></label>
		<label class="linesp"></label>
		<uni-list>
			<uni-list-item :title="$t('index.goodslist')"></uni-list-item>
		</uni-list>
		<view v-for="(item,findex) in foodlist">
			<view class="spnodetail">
				<view class="">
					<myImage class="spIcon" :mysrc="item.image" mymode="scaleToFill"></myImage>
				</view>
				<view style="width: 82%;">
					<view class="actBTV">
						<view style="font-size: 30rpx;width: 100%;">
							<text class="text2row" style="width: 100%;">{{item.name}}</text>
						</view>
						<view class="contentInRowL">
							<image v-if="item.number>0" class="imageRJ" src="/static/images/jian@3x.png"
								mode="aspectFit" @click="jiajian(findex,-1)"></image>
							<text v-if="item.number>0" class="textR">{{item.number}}</text>
							<image class="imageR" src="/static/images/plus-circle-fill@3x.png" mode="aspectFit"
								@click="jiajian(findex,1)"></image>
						</view>
					</view>
					<view class="actBTV">
						<view style="font-size: 26rpx;color: blueviolet;">{{$t('shangpin.shoujia')}}:
							{{$formPr(item.price+item.otherPrice)}}{{$t('locale.huobidw')}}
						</view>
						<view class="xiaoji" style="font-size: 28rpx;color: brown;">{{$t('shangpin.xiaoji')}}:
							{{$formPr((item.price+item.otherPrice)*item.number)}}{{$t('locale.huobidw')}}
						</view>
					</view>
					<view class="viewinrow">
						<text class="kouweisku">{{arraytoStr(item.ask)}}</text>
					</view>
					<view v-if="item.beizhu" class="">
						<text style="font-size: 30rpx;color:#00A6FF;">{{item.beizhu}}</text>
					</view>
				</view>
			</view>
		</view>
		<label class="linesp"></label>
		<label class="linesp"></label>

		<view style="background-color:white;width: 100%;">
			<view class="contentInRowS shifdf" @click="xuanzcux">
				<view class="contentInRowL" style="width: 86%;">
					<image style="width: 50rpx;height: 50rpx;" src="/static/images/hongbkqh@3x.png" mode="scaleToFill">
					</image>
					<view class="contentColumn" style="width: 100%;">
						<text class="shifdftext"
							:style="youyh?'color:fuchsia;':'color:darkgray;'">{{$t('index.hongbaokq')}}</text>
						<text class="hdts" style="color: black;font-size: 26rpx;">{{yhhd}}</text>
					</view>
				</view>
				<image v-if="hyyh!=0" style="width: 50rpx;height: 50rpx;" src="/static/images/dagoul.png"
					mode="scaleToFill"></image>
			</view>
		</view>

		<!-- <view style="background-color:white;width: 100%;">
			<view class="contentInRowS shifdf"  @click="jifenduihuan">
				<view class="contentInRowL" style="width: 86%;">
					<image style="width: 50rpx;height: 50rpx;" src="/static/images/hongbkqh@3x.png" mode="scaleToFill"></image>
					<view class="contentColumn" style="width: 100%;">
						<text class="shifdftext" :style="isjifenduihan?'color:green;':'color:darkgray;'">积分兑换</text>
						<text v-if="points>0" class="hdts" style="color: black;font-size: 26rpx;">{{points}}积分兑换{{pointsReduction}}</text>
					</view>
				</view>
				<image v-if="isjifenduihan" style="width: 50rpx;height: 50rpx;" src="/static/images/dagoul.png" mode="scaleToFill"></image>
			</view>
		</view> -->

		<view class="contentInRowS shifdf" @click="shifodaofu">
			<view class="contentInRowC">
				<image style="width: 50rpx;height: 50rpx;" src="/static/images/payflact@3x.png" mode="scaleToFill">
				</image>
				<text class="shifdftext"
					:style="shifoudf==0?'color:darkgray;':'color:fuchsia;'">{{$t('index.huodaofukan')}}</text>
			</view>
			<image v-if="shifoudf==1" style="width: 50rpx;height: 50rpx;" src="/static/images/dagoul.png"
				mode="scaleToFill"></image>
		</view>
		<label class="linesp"></label>
		<label class="linesp"></label>
		<uni-list>
			<uni-list-item :title="$t('order.beizhu')"></uni-list-item>
		</uni-list>
		<textarea class="pinglun" :placeholder="$t('order.srddbz')" :value="remarks" @input="sumfontnum"></textarea>
		<label class="linesp"></label>
		<label class="linesp"></label>
		<!-- 		<view v-if="showAdrr==0">
			<uni-list>
				<uni-list-item :title="$t('order.menpaizp')"></uni-list-item>
			</uni-list>
			<view class="contentColumnC" style="margin-top: 30rpx;" @click="selectImage">
				<netImage width="640" height="640" :mysrc="mpImage" mymode="scaleToFill"></netImage>
			</view>
			<view class="linesp" style="margin-top: 20rpx;"></view>
			<label class="linesp"></label>
		</view> -->

		<uni-list>
			<uni-list-item :title="$t('order.shangpinxj')" :rightText="$formPr(spxj)+$t('locale.huobidw')" />
			<uni-list-item :title="$t('order.peisongfei')" :rightText="$formPr(psf)+$t('locale.huobidw')" />
			<uni-list-item :title="$t('order.youhuijine')" :rightText="'-'+$formPr(hyyh)+$t('locale.huobidw')" />
		</uni-list>
		<label class="linesp"></label>
		<label class="linesp"></label>
		<uni-list>
			<uni-list-item :title="$t('order.zhifujine')" :rightText="$formPr(zje)+$t('locale.huobidw')" />
		</uni-list>
		<label class="linesp"></label>
		<label class="linesp"></label>
		<view class="delbtct">
			<view class="delbt" @click="qufukuan">
				<label>{{actTitle}}</label>
			</view>
		</view>

		<label class="linesp"></label>
		<liu-delivery-time @change="changeTime" @close="deliveryclose" ref="chooseTime"
			:title="$t('order.yuyueshijian')"></liu-delivery-time>
		<yhdslCropper ref="yhdslCropper" :quality="1" mode="scale" @uploadImg="uploadImg" :scale="scale"></yhdslCropper>
		<popViewGG :show="showpop" :acttips="$t('order.queding')" :maskClosable="true" :isCancel="false"
			@chooseCancel="chooseCancel">
			<view class="contentColumnC" style="width: 100%;background-color: whitesmoke;">
				<view class="contentColumnC" style="height: 80rpx;width: 100%;background-color: lightgray;">
					<view class="contentInRowS" style="height: 80rpx;width: 90%;">
						<text style="font-size: 30rpx;color: crimson;" @click="querenyhhd"></text>
						<text style="font-size: 28rpx;">{{$t('index.hongbaokq')}}</text>
						<text style="font-size: 30rpx;color: #00A6FF;"
							@click="querenyhhd">{{$t('order.queding')}}</text>
					</view>
				</view>
				<view v-if="cxList.length>0" style="width: 90%;">
					<checkbox-group @change="hdradioChange">
						<label class="contentColumn" style="margin-top: 16rpx;" v-for="(item, index) in cxList"
							:key="index">
							<checkbox :value="item.id" :checked="item.id === hdidpt||item.id === hdidsj">
								<view class="contentColumn" :style="item.type==0?'color: #00A6FF;':'color:green;'">
									<text style="font-size: 28rpx;">{{item.salesName}}</text>
									<text style="font-size: 28rpx;">{{getNote(item,0)}}</text>
								</view>
							</checkbox>
						</label>
					</checkbox-group>
				</view>
				<view v-if="kqList.length>0" style="width: 90%;">
					<checkbox-group @change="kaqradioChange">
						<label class="contentColumn" style="margin-top: 16rpx;" v-for="(item, index) in kqList"
							:key="index">
							<checkbox :value="item.id" :checked="item.id === kqidpt||item.id === kqidsj">
								<view class="contentColumn" :style="item.type==0?'color: #00A6FF;':'color:green;'">
									<text style="font-size: 28rpx;">{{item.name}}</text>
									<text style="font-size: 28rpx;">{{getNote(item,1)}}</text>
								</view>
							</checkbox>
						</label>
					</checkbox-group>
				</view>
				<view class="contentInRowC" style="width: 100%;height: 80rpx;margin-top: 16rpx;">
					<text>{{$t('hongbaokq.leijiyh')}} {{hyyh}}{{$t('locale.huobidw')}}</text>
				</view>
				<view style="height: 80rpx;"></view>
			</view>
		</popViewGG>
		<popViewGG :tips="$t('order.zhifufangshi')" :show="zffsS" :showbotom="false" :maskClosable="true"
			:isCancel="true" @chooseCancel="chooseCancel">
			<view class="contentColumnC" style="width: 100%;background-color: whitesmoke;">
				<view class="zhifbut" style="background-color: deeppink;" @click="huodaofukuan">
					{{$t('index.huodaofukan')}}
				</view>
				<!-- <view class="zhifbut" style="background-color:#00A6FF;" @click="getVNPay">VNPAY</view> -->
			</view>
		</popViewGG>
	</view>
</template>

<script>
	import uniList from '@/uni_modules/uni-list/uni-list.vue';
	import uniListItem from '@/uni_modules/uni-list-item/uni-list-item.vue';
	// import uniAd from '@/uni_modules/uni-list-ad/uni-list-ad.vue';
	// import uniChat from '@/uni_modules/uni-list-chat/uni-list-chat.vue';
	import yhdslCropper from '@/components/yhdsl-cropper/yhdsl-cropper.vue';
	import api from "@/pages/api/api.js"
	export default {
		components: {
			uniList,
			uniListItem,
			yhdslCropper
		},
		data() {
			return {
				mendid: 0,
				userid: 0,
				ddId: '',
				rId: '',
				showAdrr: 0,
				foodlist: [],
				Bcolor: 'whitesmoke',
				Bcolorr: 'lightgray',
				Bcolorrr: 'lightgray',
				Tcolor: 'black',
				Tcolorr: 'darkgray',
				Tcolorrr: 'darkgray',
				peisongimg: '/static/images/peisongh@3x.png',
				ziquimg: '/static/images/ziqu@3x.png',
				tangshiimg: '/static/images/tangshih.png',
				actTitle: this.$t('order.querendd'),
				actType: 0,
				remarks: '',
				spxj: 0.00,
				psf: 0.00,
				freight: 0.00,
				hyyh: 0.00,
				zje: 0.00,
				jvli: 0.00,
				zhixianjuli: 0.00,
				zhixianfreight: 0.00,
				dizhiID: '',
				addrList: [],
				peisongdizhiaddress: '',
				peisongdizhiname: '',
				peisongdizhiphone: '',
				zfindex: 0,
				delryTime: '',
				isGetyunfei: false,
				mendianMs: '',
				cid: '',
				orderDetl: '',
				shifouzhifu: false,
				zhifuUrl: '',
				shifoudf: 0,
				scale: 1,
				baseUrl: this.$baseImagurl,
				mpImage: '',
				showpop: false,
				indicatorStyle: 'height: 50px;',
				zffsS: false,
				keyixd: true,

				cxList: [],
				hdidpt: 0, //平台促销活动id
				hdidsj: 0, //门店促销活动id
				kqList: [],
				kqidpt: 0, //平台使用优惠券id
				kqidsj: 0, //门店优惠券id

				yhhd: '',
				youyh: false,


				discountAmount: 0, //平台优惠券优惠金额
				salesReduction: 0, //平台促销減免值

				mdDiscountAmount: 0, //门店优惠券优惠金额
				mdSalesReduction: 0, //门店促销減免值

				isjifenduihan: false,
				sumpoints: 0, //全部积分
				pointsBl: 0, //积分抵扣比例
				points: 0, //抵扣的积分
				pointsReduction: 0 //积分抵扣值
			}
		},
		onLoad(option) {
			console.log(option)
			this.foodlist = uni.getStorageSync("JSfoodlist");
			uni.setStorageSync('JSfoodlist', '');
			this.mendid = option.mendid;
			this.userid = option.userid;
			this.cid = uni.getStorageSync("cid");

			this.cuxiaoList();
			//this.getPoint();
		},
		onShow() {
			var temp = uni.getStorageSync("peisongdizhi");
			if (undefined == temp || null == temp || '' == temp) {
				this.dizhiID = '';
				//this.getaddressList();
			} else {
				this.dizhiID = temp;
				this.mpImage = this.dizhiID.annexes;
			}
			this.isGetyunfei = false;
			if (this.mendianMs == '') {
				this.getmendianDetail(this.mendid);
			} else {
				if (this.dizhiID == '') {
					this.getaddressList();
				} else {
					console.log('4444')
					this.getyunfei(this.dizhiID.latitude, this.dizhiID.longitude);
				}
			}

			if (this.shifouzhifu) {
				this.shifouzhifu = false;
				this.getorderDetl();
			}
		},
		methods: {
			// 检测是否为安卓设备
			isAndroidDevice() {
				// 在H5环境中检测
				// #ifdef H5
				const ua = navigator.userAgent.toLowerCase();
				return ua.indexOf('android') > -1;
				// #endif

				// 在App环境中检测
				// #ifdef APP-PLUS
				return plus.os.name === 'Android';
				// #endif

				// 其他环境默认返回false
				return false;
			},

			// 安卓设备自动下载并安装APK
			downloadAndInstallAndroid(androidUrl) {
				const that = this;

				// 先尝试打开已安装的应用
				this.tryOpenInstalledApp();
			},

			// 尝试打开已安装的应用
			tryOpenInstalledApp() {
				const that = this;
				const appSchema = 'cityexpressuser://';

				// 在App环境中使用plus.runtime.openURL
				// #ifdef APP-PLUS
				plus.runtime.openURL(appSchema, function() {
					console.log(that.$t('download.app_opened_success'));
				}, function(e) {
					console.log(that.$t('download.app_not_installed'));
					// 应用未安装，继续下载流程
					that.startDownloadProcess();
				});
				// #endif

				// 在H5环境中尝试打开应用
				// #ifdef H5
				this.tryOpenAppInH5(appSchema);
				// #endif
			},

			// 在H5环境中尝试打开应用
			tryOpenAppInH5(appSchema) {
				const that = this;

				// 检测是否为iOS设备
				const isIOS = this.isIOSDevice();

				if (isIOS) {
					// iOS设备使用特殊处理
					this.tryOpenIOSApp(appSchema);
				} else {
					// 安卓设备使用iframe方式
					this.tryOpenAndroidApp(appSchema);
				}
			},

			// 尝试打开iOS应用
			tryOpenIOSApp(appSchema) {
				const that = this;

				// 记录开始时间
				const startTime = Date.now();
				let hasApp = false;

				// 监听页面可见性变化
				const handleVisibilityChange = () => {
					if (document.hidden) {
						hasApp = true;
						clearTimeout(timeout);
						document.removeEventListener('visibilitychange', handleVisibilityChange);
						document.removeEventListener('pagehide', handlePageHide);
						document.removeEventListener('blur', handleBlur);
					}
				};

				// 监听页面隐藏事件
				const handlePageHide = () => {
					hasApp = true;
					clearTimeout(timeout);
					document.removeEventListener('visibilitychange', handleVisibilityChange);
					document.removeEventListener('pagehide', handlePageHide);
					document.removeEventListener('blur', handleBlur);
				};

				// 监听窗口失焦事件
				const handleBlur = () => {
					hasApp = true;
					clearTimeout(timeout);
					document.removeEventListener('visibilitychange', handleVisibilityChange);
					document.removeEventListener('pagehide', handlePageHide);
					document.removeEventListener('blur', handleBlur);
				};

				// 设置超时检测
				const timeout = setTimeout(() => {
					if (!hasApp) {
						// 应用未安装，继续下载流程
						that.startDownloadProcess();
					}
					document.removeEventListener('visibilitychange', handleVisibilityChange);
					document.removeEventListener('pagehide', handlePageHide);
					document.removeEventListener('blur', handleBlur);
				}, 1500); // 缩短超时时间

				// 添加事件监听器
				document.addEventListener('visibilitychange', handleVisibilityChange);
				document.addEventListener('pagehide', handlePageHide);
				window.addEventListener('blur', handleBlur);

				// 尝试打开应用
				try {
					// 方法1: 直接使用window.location
					window.location.href = appSchema;
				} catch (e) {
					// 方法2: 使用iframe
					const iframe = document.createElement('iframe');
					iframe.style.display = 'none';
					iframe.style.width = '1px';
					iframe.style.height = '1px';
					iframe.src = appSchema;
					document.body.appendChild(iframe);

					// 清理iframe
					setTimeout(() => {
						if (document.body.contains(iframe)) {
							document.body.removeChild(iframe);
						}
					}, 1000);
				}
			},

			// 尝试打开安卓应用
			tryOpenAndroidApp(appSchema) {
				const that = this;

				let hasApp = false;

				// 监听页面可见性变化
				const handleVisibilityChange = () => {
					if (document.hidden) {
						hasApp = true;
						clearTimeout(timeout);
						document.removeEventListener('visibilitychange', handleVisibilityChange);
						document.removeEventListener('pagehide', handlePageHide);
						document.removeEventListener('blur', handleBlur);
					}
				};

				// 监听页面隐藏事件
				const handlePageHide = () => {
					hasApp = true;
					clearTimeout(timeout);
					document.removeEventListener('visibilitychange', handleVisibilityChange);
					document.removeEventListener('pagehide', handlePageHide);
					document.removeEventListener('blur', handleBlur);
				};

				// 监听窗口失焦事件
				const handleBlur = () => {
					hasApp = true;
					clearTimeout(timeout);
					document.removeEventListener('visibilitychange', handleVisibilityChange);
					document.removeEventListener('pagehide', handlePageHide);
					document.removeEventListener('blur', handleBlur);
				};

				// 设置超时检测
				const timeout = setTimeout(() => {
					if (!hasApp) {
						// 应用未安装，继续下载流程
						that.startDownloadProcess();
					}
					document.removeEventListener('visibilitychange', handleVisibilityChange);
					document.removeEventListener('pagehide', handlePageHide);
					document.removeEventListener('blur', handleBlur);
				}, 1500); // 缩短超时时间

				// 添加事件监听器
				document.addEventListener('visibilitychange', handleVisibilityChange);
				document.addEventListener('pagehide', handlePageHide);
				window.addEventListener('blur', handleBlur);

				// 尝试打开应用
				try {
					// 方法1: 直接使用window.location
					window.location.href = appSchema;
				} catch (e) {
					// 方法2: 使用iframe
					const iframe = document.createElement('iframe');
					iframe.style.display = 'none';
					iframe.style.width = '1px';
					iframe.style.height = '1px';
					iframe.src = appSchema;
					document.body.appendChild(iframe);

					// 清理iframe
					setTimeout(() => {
						if (document.body.contains(iframe)) {
							document.body.removeChild(iframe);
						}
					}, 1000);
				}
			},

			// 开始下载流程
			startDownloadProcess() {
				const that = this;

				// 显示下载提示
				uni.showLoading({
					title: this.$t('download.downloading'),
					mask: true
				});

				// 获取下载链接
				api('getAppDownload', {}, r => {
					console.log(r);

					// 检测是否为安卓设备
					const isAndroid = this.isAndroidDevice();

					if (isAndroid) {
						// 安卓设备下载APK
						that.downloadAndroidAPK(r.data.data.androidUrl);
					} else {
						// iOS设备打开App Store
						that.openAppStore(r.data.data.iosUrl);
					}
				});
			},

			// 下载安卓APK
			downloadAndroidAPK(androidUrl) {
				const that = this;

				// 在App环境中使用plus.downloader
				// #ifdef APP-PLUS
				const appDownloadTask = plus.downloader.createDownload(androidUrl, {
					filename: '_downloads/CTE.apk'
				}, function(download, status) {
					uni.hideLoading();

					if (status === 200) {
						// 下载成功，尝试安装
						that.installAndroidApp(download.filename);
					} else {
						uni.showToast({
							title: that.$t('download.download_failed'),
							icon: 'none',
							duration: 2000
						});
					}
				});

				// 监听下载进度
				appDownloadTask.addEventListener('statechanged', function(download, status) {
					if (status === 200) {
						const progress = Math.round((download.downloadedSize / download.totalSize) * 100);
						uni.showLoading({
							title: that.$t('download.downloading_progress', {
								progress: progress
							}),
							mask: true
						});
					}
				});

				appDownloadTask.start();
				// #endif

				// 在H5环境中使用uni.downloadFile
				// #ifdef H5
				const h5DownloadTask = uni.downloadFile({
					url: androidUrl,
					success: function(res) {
						uni.hideLoading();

						if (res.statusCode === 200) {
							// 下载成功，尝试安装
							that.installAndroidApp(res.tempFilePath);
						} else {
							uni.showToast({
								title: that.$t('download.download_failed'),
								icon: 'none',
								duration: 2000
							});
						}
					},
					fail: function(err) {
						uni.hideLoading();
						console.log('下载失败:', err);

						// 下载失败时，提供手动下载选项
						uni.showModal({
							title: that.$t('download.download_failed'),
							content: that.$t('download.download_failed_manual'),
							showCancel: true,
							cancelText: that.$t('comp.quxiao'),
							confirmText: that.$t('comp.queren'),
							success: function(res) {
								if (res.confirm) {
									// 使用浏览器打开下载链接
									window.open(androidUrl, '_blank');
								}
							}
						});
					}
				});

				// 监听下载进度
				h5DownloadTask.onProgressUpdate(function(res) {
					const progress = Math.round(res.progress);
					uni.showLoading({
						title: that.$t('download.downloading_progress', {
							progress: progress
						}),
						mask: true
					});
				});
				// #endif
			},

			// 打开App Store
			openAppStore(iosUrl) {
				const that = this;

				// 在App环境中使用plus.runtime.openURL
				// #ifdef APP-PLUS
				plus.runtime.openURL(
					'itms-apps://itunes.apple.com/cn/app/cte/id6468907188',
					(res) => {
						console.log(that.$t('download.app_store_success'))
					},
					(err) => {
						console.log(that.$t('download.app_store_failed'))
						// 如果 itms-apps:// 失败，回退到浏览器打开
						plus.runtime.openURL('https://apps.apple.com/cn/app/cte/id6468907188')
					}
				);
				// #endif

				// 在H5环境中，针对iOS设备优化
				// #ifdef H5
				// 先尝试直接打开App Store链接
				const appStoreUrl = 'https://apps.apple.com/cn/app/cte/id6468907188';

				// 尝试多种方式打开App Store
				that.tryOpenAppStore(appStoreUrl);
				// #endif
			},

			// 安装安卓应用
			installAndroidApp(filePath) {
				const that = this;

				// 在App环境中，直接尝试安装APK
				// #ifdef APP-PLUS
				uni.showModal({
					title: that.$t('download.download_complete'),
					content: that.$t('download.install_confirm'),
					showCancel: true,
					cancelText: that.$t('comp.quxiao'),
					confirmText: that.$t('comp.queren'),
					success: function(res) {
						if (res.confirm) {
							// 使用plus.runtime.install安装APK
							plus.runtime.install(filePath, {
								force: false
							}, function() {
								uni.showToast({
									title: that.$t('download.install_success'),
									icon: 'success',
									duration: 2000
								});
							}, function(e) {
								console.log('安装失败:', e);
								uni.showModal({
									title: that.$t('download.install_failed'),
									content: that.$t('download.install_failed_manual'),
									showCancel: true,
									cancelText: that.$t('comp.quxiao'),
									confirmText: that.$t('comp.queren'),
									success: function(res) {
										if (res.confirm) {
											// 打开文件管理器
											plus.runtime.openFile(filePath);
										}
									}
								});
							});
						}
					}
				});
				// #endif

				// 在H5环境中，提示用户手动安装
				// #ifdef H5
				uni.showModal({
					title: that.$t('download.download_complete'),
					content: that.$t('download.manual_install_hint'),
					showCancel: false,
					confirmText: that.$t('comp.queren'),
					success: function(res) {
						if (res.confirm) {
							// 尝试打开下载链接，让用户手动下载
							window.open(filePath, '_blank');
						}
					}
				});
				// #endif
			},

			// 下载iOS应用
			downloadIOSApp(iosUrl) {
				// 检测是否为iOS设备
				const isIOS = this.isIOSDevice();

				if (!isIOS) {
					// 非iOS设备直接打开浏览器链接
					window.open('https://apps.apple.com/cn/app/cte/id6468907188', '_blank');
					return;
				}

				// 先尝试打开已安装的应用
				this.tryOpenInstalledApp();
			},

			// 检测是否为iOS设备
			isIOSDevice() {
				// #ifdef H5
				const ua = navigator.userAgent.toLowerCase();
				return /iphone|ipad|ipod/.test(ua);
				// #endif

				// #ifdef APP-PLUS
				return plus.os.name === 'iOS';
				// #endif

				return false;
			},

			// 尝试打开App Store的多种方式
			tryOpenAppStore(appStoreUrl) {
				// 方法1: 直接使用window.open
				const newWindow = window.open(appStoreUrl, '_blank');

				// 如果新窗口被阻止，尝试其他方法
				if (!newWindow || newWindow.closed || typeof newWindow.closed == 'undefined') {
					// 方法2: 尝试使用itms-apps协议
					this.tryItmsProtocol();
				}
			},

			// 尝试使用itms-apps协议
			tryItmsProtocol() {
				const itmsUrl = 'itms-apps://itunes.apple.com/cn/app/cte/id6468907188';

				// 创建一个隐藏的iframe来尝试打开itms-apps协议
				const iframe = document.createElement('iframe');
				iframe.style.display = 'none';
				iframe.style.width = '1px';
				iframe.style.height = '1px';
				iframe.src = itmsUrl;
				document.body.appendChild(iframe);

				// 设置超时，如果App Store没有打开，则回退到浏览器
				setTimeout(() => {
					if (document.body.contains(iframe)) {
						document.body.removeChild(iframe);
					}
					// 最后回退到浏览器打开
					window.location.href = 'https://apps.apple.com/cn/app/cte/id6468907188';
				}, 1500);
			},

			//促销
			cuxiaoList() {
				this.youyh = false;
				this.yhhd = '';
				var price = 0;
				for (var i = 0; i < this.foodlist.length; i++) {
					price = price + (this.foodlist[i].price + this.foodlist[i].otherPrice) * this.foodlist[i].number;
				}
				this.cxList = [];
				api('cuxiaoList', {
					mdId: this.mendid,
					price: price,
					yfPrice: this.psf
				}, r => {
					console.log(r);
					console.log('-----------1', this.mendid, price, this.psf)
					if (r.data.code == 200) {
						this.cxList = r.data.data;
						if (this.cxList.length > 0) {
							this.yhhd = this.$t('order.qingxzyhkq');
							this.youyh = true;
						}
					}
					this.jisuanjiner();
					this.kaquanList();
				}, failc => {
					//console.log('getadvertis----',failc)
				})
			},
			kaquanList() {
				var price = 0;
				for (var i = 0; i < this.foodlist.length; i++) {
					price = price + (this.foodlist[i].price + this.foodlist[i].otherPrice) * this.foodlist[i].number;
				}
				this.kqList = [];
				api('orderyhList', {
					mdId: this.mendid,
					price: price,
					yfPrice: this.psf
				}, r => {
					console.log(r);
					console.log('-----------2', this.mendid, price, this.psf)
					if (r.data.code == 200) {
						this.kqList = r.data.data;
						if (this.kqList.length > 0) {
							this.yhhd = this.$t('order.qingxzyhkq');
							this.youyh = true;
						} else {
							if (!this.youyh) {
								this.yhhd = '';
								this.youyh = false;
							}
						}
					}
					this.jisuanjiner();
				}, failc => {
					//console.log('getadvertis----',failc)
				})
			},
			//积分
			getPoint() {
				api('getPoint', {}, r => {
					console.log("getPoint：", r);
					if (r.data.code == 200) {
						this.sumpoints = r.data.data.points; //积分
						this.pointsBl = r.data.data.bl; //积分抵扣值
					} else if (r.data.code == 500) {
						this.sumpoints = 0; //积分
						this.pointsBl = 0; //积分抵扣值
					}
				}, failc => {
					//console.log('getadvertis----',failc)
				})
			},

			hdradioChange(evt) {
				console.log(evt.detail.value)
				var hdids = evt.detail.value;
				var hdid = 0;
				var hdidpt = 0;
				var hdidsj = 0;
				for (var i = 0; i < hdids.length; i++) {
					var oid = hdids[i];
					if (oid == this.hdidpt) {
						hdidpt = oid;
					} else if (oid == this.hdidsj) {
						hdidsj = oid;
					} else {
						hdid = oid;
					}
				}
				this.hdidpt = hdidpt;
				this.hdidsj = hdidsj;
				var sobj = null;
				for (var i = 0; i < this.cxList.length; i++) {
					var obj = this.cxList[i];
					if (obj.id == hdid) {
						sobj = obj;
						break;
					}
				}
				if (this.cxList.length > 0 && hdid > 0) {
					for (var i = 0; i < this.cxList.length; i++) {
						var obj = this.cxList[i];
						if (obj.id == this.hdidpt) {
							if (sobj.salesType == obj.salesType) {
								this.hdidpt = 0;
							}
						}
						if (obj.id == this.hdidsj) {
							if (sobj.salesType == obj.salesType) {
								this.hdidsj = 0;
							}
						}
					}
				}
				if (this.kqList.length > 0 && hdid > 0) {
					for (var i = 0; i < this.kqList.length; i++) {
						var obj = this.kqList[i];
						if (obj.id == this.kqidpt) {
							if (sobj.salesType == obj.yhfangs) {
								this.kqidpt = 0;
							}
						}
						if (obj.id == this.kqidsj) {
							if (sobj.salesType == obj.yhfangs) {
								this.kqidsj = 0;
							}
						}
					}
				}
				if (hdid > 0) {
					if (sobj && sobj.type == 0) {
						this.hdidpt = hdid;
					} else if (sobj && sobj.type == 1) {
						this.hdidsj = hdid;
					}
				}

				this.jisuanjiner();
			},
			kaqradioChange(evt) {
				console.log(evt)
				var kqids = evt.detail.value;
				var kqid = 0;
				var kqidpt = 0;
				var kqidsj = 0;
				for (var i = 0; i < kqids.length; i++) {
					var oid = kqids[i];
					if (oid == this.kqidpt) {
						kqidpt = oid;
					} else if (oid == this.kqidsj) {
						kqidsj = oid;
					} else {
						kqid = oid;
					}
				}
				this.kqidpt = kqidpt;
				this.kqidsj = kqidsj;
				var sobj = null;
				for (var i = 0; i < this.kqList.length; i++) {
					var obj = this.kqList[i]
					if (obj.id == kqid) {
						sobj = obj;
						break;
					}
				}
				if (this.cxList.length > 0 && kqid > 0) {
					for (var i = 0; i < this.cxList.length; i++) {
						var obj = this.cxList[i];
						if (obj.id == this.hdidpt) {
							if (sobj.yhfangs == obj.salesType) {
								this.hdidpt = 0;
							}
						}
						if (obj.id == this.hdidsj) {
							if (sobj.yhfangs == obj.salesType) {
								this.hdidsj = 0;
							}
						}
					}
				}
				if (this.kqList.length > 0 && kqid > 0) {
					for (var i = 0; i < this.kqList.length; i++) {
						var obj = this.kqList[i];
						if (obj.id == this.kqidpt) {
							if (sobj.yhfangs == obj.yhfangs) {
								this.kqidpt = 0;
							}
						}
						if (obj.id == this.kqidsj) {
							if (sobj.yhfangs == obj.yhfangs) {
								this.kqidsj = 0;
							}
						}
					}
				}
				if (kqid >= 0) {
					if (sobj && sobj.type == 0) {
						this.kqidpt = kqid;
					} else if (sobj && sobj.type == 1) {
						this.kqidsj = kqid;
					}
				}

				this.jisuanjiner();
			},

			getNote(obj, index) {
				var str = '';
				if (index == 0) {
					var str = '';
					if (obj.salesType == 1 && obj.salesReduction > 1) { //优惠方式：1 运费，2 订单 ,3 商品
						str = this.$t('hongbaokq.yunfeiyh');
					}
					if (obj.salesType == 1 && obj.salesReduction < 1 && obj.salesReduction > 0) { //优惠方式：1 运费，2 订单 ,3 商品
						str = this.$t('hongbaokq.yunfeizk');
					}
					if (obj.salesType == 1 && obj.salesReduction == 0) { //优惠方式：1 运费，2 订单 ,3 商品
						str = this.$t('hongbaokq.yunfeiquanm');
					}
					if (obj.salesType == 2 && obj.salesReduction > 1) {
						str = this.$t('hongbaokq.dingdanyh');
					}
					if (obj.salesType == 2 && obj.salesReduction < 1) {
						str = this.$t('hongbaokq.dingdanzk');
					}
					if (obj.salesType == 3 && obj.salesReduction > 1) {
						str = this.$t('hongbaokq.shangpinyh');
					}
					if (obj.salesType == 3 && obj.salesReduction < 1) {
						str = this.$t('hongbaokq.shangpinzk');
					}

					if (obj.salesReduction != 0) {
						str = str + ' ' + obj.salesReduction;
					}

				}

				if (index == 1) {

					if (obj.yhfangs == 1 && obj.yhnum > 1) { //优惠方式：1 运费，2 订单 ,3 商品
						str = this.$t('hongbaokq.yunfeiyh');
					}
					if (obj.yhfangs == 1 && obj.yhnum < 1 && obj.yhnum > 0) { //优惠方式：1 运费，2 订单 ,3 商品
						str = this.$t('hongbaokq.yunfeizk');
					}
					if (obj.yhfangs == 1 && obj.yhnum == 0) { //优惠方式：1 运费，2 订单 ,3 商品
						str = this.$t('hongbaokq.yunfeiquanm');
					}
					if (obj.yhfangs == 2 && obj.yhnum > 1) {
						str = this.$t('hongbaokq.dingdanyh');
					}
					if (obj.yhfangs == 2 && obj.yhnum < 1) {
						str = this.$t('hongbaokq.dingdanzk');
					}
					if (obj.yhfangs == 3 && obj.yhnum > 1) {
						str = this.$t('hongbaokq.shangpinyh');
					}
					if (obj.yhfangs == 3 && obj.yhnum < 1) {
						str = this.$t('hongbaokq.shangpinzk');
					}

					if (obj.yhnum != 0) {
						str = str + ' ' + obj.yhnum;
					}
				}
				return str;
			},
			querenyhhd() {
				this.showpop = false;
			},
			//积分兑换
			jifenduihuan() {
				if (this.sumpoints > 0) {
					this.isjifenduihan = !this.isjifenduihan;
				} else {
					this.isjifenduihan = false;
				}
			},

			jisuandikou(dingdanjiner) {
				var sumkyjine = this.sumpoints * this.pointsBl;
				if (sumkyjine > dingdanjiner) {
					var jifen = dingdanjiner / this.pointsBl;
					jifen = parseInt(jifen);
					this.points = jifen;
					this.pointsReduction = jifen * this.pointsBl;
				} else {
					this.points = this.sumpoints;
					this.pointsReduction = sumkyjine;
				}
				return this.pointsReduction;
			},

			//商品数量加减
			jiajian(index, state) {
				if (this.actType > 0) {
					return;
				}
				var tempList = this.foodlist;
				if (state > 0) {
					var temp = tempList[index];
					temp.number = temp.number + 1;
					tempList[index] = temp;
					this.gengxingouwuche(temp);
				} else {
					var temp = tempList[index];
					if (temp.number > 1) {
						temp.number = temp.number - 1;
						tempList[index] = temp;
					} else {
						temp.number = temp.number - 1;
						tempList.splice(index, 1);
					}
					this.gengxingouwuche(temp);
				}
				this.foodlist = tempList;
				this.cuxiaoList();
				if (this.foodlist.length == 0) {
					uni.showToast({
						title: that.$t('comp.qingxzsp'),
						icon: 'none',
						duration: 2500
					})
				}
			},

			xuanzcux() {
				this.showpop = true;
			},

			chooseCancel() {
				this.showpop = false;
				this.zffsS = false;
				console.log('chooseCancel');
			},
			//--------------------------------------------------------

			arraytoStr(arry) {
				var str = '';
				if (arry.length > 0) {
					for (var i = 0; i < arry.length; i++) {
						str = str + arry[i] + '; ';
					}

				}
				return str;
			},
			jisuanjiner() {
				this.spxj = 0;
				this.hyyh = 0;
				this.zje = 0;
				for (var i = 0; i < this.foodlist.length; i++) {
					this.spxj = this.spxj + (this.foodlist[i].price + this.foodlist[i].otherPrice) * this.foodlist[i]
						.number;
				}
				this.hyyh = this.jisuanyouhuijiner(this.spxj);
				this.hyyh = parseInt(this.hyyh);
				this.zje = (this.spxj + this.psf) - this.hyyh;
				this.zje = parseInt(this.zje);
				//开始积分抵扣
				this.jisuandikou(this.zje)
				this.zje = this.zje - this.pointsReduction;
				this.zje = parseInt(this.zje);
				//
			},
			jisuanyouhuijiner(price) {
				var zongyouhui = 0;
				this.salesReduction = 0;
				this.mdSalesReduction = 0;
				this.discountAmount = 0;
				this.mdDiscountAmount = 0;
				if (this.cxList.length > 0) {
					for (var i = 0; i < this.cxList.length; i++) {
						var obj = this.cxList[i];
						console.log('111111', this.hdidpt, obj)
						if (obj.id == this.hdidpt) {
							console.log('111111', this.hdidpt, obj)
							if (obj.salesType == "1") {
								if (obj.salesReduction < 1) {
									this.salesReduction = this.psf * (100 - obj.salesReduction * 100) / 100;
								} else if (obj.salesReduction > 1) {
									if (obj.salesReduction > this.psf) {
										this.salesReduction = this.psf;
									} else {
										this.salesReduction = obj.salesReduction;
									}
								}
							}
							if (obj.salesType == "2") {
								if (obj.salesReduction < 1) {
									this.salesReduction = this.salesReduction + (price + this.psf) * (100 - obj
										.salesReduction * 100) / 100;
								} else if (obj.salesReduction > 1) {
									if (obj.salesReduction > (price + this.psf)) {
										this.salesReduction = (price + this.psf);
									} else {
										this.salesReduction = obj.salesReduction;
									}
								}
								console.log(price, obj.salesReduction, price * (1 - obj.salesReduction))
							}
							if (obj.salesType == "3") {
								if (obj.salesReduction < 1) {
									this.salesReduction = this.salesReduction + price * (100 - obj.salesReduction * 100) /
										100;
								} else if (obj.salesReduction > 1) {
									if (obj.salesReduction > price) {
										this.salesReduction = price;
									} else {
										this.salesReduction = obj.salesReduction;
									}
								}
							}
						}
						if (obj.id == this.hdidsj) {
							console.log('1111112', this.hdidsj, obj)
							if (obj.salesType == "1") {
								this.mdSalesReduction = this.mdSalesReduction + this.psf;
								if (obj.salesReduction < 1) {
									this.mdSalesReduction = this.psf * (100 - obj.salesReduction * 100) / 100;
								} else if (obj.salesReduction > 1) {
									if (obj.salesReduction > this.psf) {
										this.mdSalesReduction = this.psf;
									} else {
										this.mdSalesReduction = obj.salesReduction;
									}
								}
							}
							if (obj.salesType == "2") {
								if (obj.salesReduction < 1) {
									this.mdSalesReduction = this.mdSalesReduction + (price + this.psf) * (100 - obj
										.salesReduction * 100) / 100;
								} else if (obj.salesReduction > 1) {
									if (obj.salesReduction > (price + this.psf)) {
										this.mdSalesReduction = (price + this.psf);
									} else {
										this.mdSalesReduction = obj.salesReduction;
									}
								}
							}
							if (obj.salesType == "3") {
								if (obj.salesReduction < 1) {
									this.mdSalesReduction = this.mdSalesReduction + price * (100 - obj.salesReduction *
										100) / 100;
								} else if (obj.salesReduction > 1) {
									if (obj.salesReduction > price) {
										this.mdSalesReduction = price;
									} else {
										this.mdSalesReduction = obj.salesReduction;
									}
								}
							}
						}
					}

				}
				if (this.kqList.length > 0) {
					for (var i = 0; i < this.kqList.length; i++) {
						var obj = this.kqList[i];
						if (obj.id == this.kqidpt) {
							console.log('1111113', this.kqidpt, obj)
							if (obj.yhfangs == 1) {
								if (obj.yhnum < 1) {
									this.discountAmount = this.psf * (100 - obj.yhnum * 100) / 100;
								} else if (obj.yhnum > 1) {
									if (obj.yhnum > this.psf) {
										this.discountAmount = this.psf;
									} else {
										this.discountAmount = obj.yhnum;
									}
								}
							}
							if (obj.yhfangs == 2) {
								if (obj.yhnum < 1) {
									this.discountAmount = (price + this.psf) * (100 - obj.yhnum * 100) / 100;
								} else if (obj.yhnum > 1) {
									if (obj.yhnum > (price + this.psf)) {
										this.discountAmount = (price + this.psf);
									} else {
										this.discountAmount = obj.yhnum;
									}
								}
								console.log(price, obj.yhnum, price * (1 - obj.yhnum))
							}
							if (obj.yhfangs == 3) {
								if (obj.yhnum < 1) {
									this.discountAmount = price * (100 - obj.yhnum * 100) / 100;
								} else if (obj.yhnum > 1) {
									if (obj.yhnum > price) {
										this.discountAmount = price;
									} else {
										this.discountAmount = obj.yhnum;
									}
								}
							}
						}
						if (obj.id == this.kqidsj) {
							console.log('1111114', this.kqidsj, obj)
							if (obj.yhfangs == 1) {
								if (obj.yhnum < 1) {
									this.mdDiscountAmount = this.psf * (100 - obj.yhnum * 100) / 100;
								} else if (obj.yhnum > 1) {
									if (obj.yhnum > this.psf) {
										this.mdDiscountAmount = this.psf;
									} else {
										this.mdDiscountAmount = obj.yhnum;
									}
								}
							}
							if (obj.yhfangs == 2) { //订单
								if (obj.yhnum > 1) {
									if (obj.yhnum > (price + this.psf)) {
										this.mdDiscountAmount = (price + this.psf);
									} else {
										this.mdDiscountAmount = obj.yhnum;
									}
								} else {
									this.mdDiscountAmount = this.mdDiscountAmount + (price + this.psf) * (100 - obj.yhnum *
										100) / 100;
								}

								console.log(price, obj.yhnum, price * (1 - obj.yhnum))
							}
							if (obj.yhfangs == 3) { //商品
								if (obj.yhnum > 1) {
									if (obj.yhnum > price) {
										this.mdDiscountAmount = price;
									} else {
										this.mdDiscountAmount = obj.yhnum;
									}
								} else {
									this.mdDiscountAmount = this.mdDiscountAmount + price * (100 - obj.yhnum * 100) / 100;
								}

								console.log(price, obj.yhnum, price * (1 - obj.yhnum))
							}
						}
					}

				}
				console.log(this.hdidpt, this.hdidsj, this.kqidpt, this.kqidsj)
				console.log(this.salesReduction, this.mdSalesReduction, this.discountAmount, this.mdDiscountAmount)
				zongyouhui = this.salesReduction + this.mdSalesReduction + this.discountAmount + this.mdDiscountAmount;
				console.log('zongyouhui:', zongyouhui);
				return zongyouhui;
			},
			sumfontnum(e) {
				this.remarks = e.target.value;
			},
			shifodaofu() {
				if (this.actType > 1) {
					return;
				}
				if (this.shifoudf == 0) {
					this.shifoudf = 1;
				} else {
					this.shifoudf = 0;
				}
				if (this.actType == 1 && this.shifoudf == 1) {
					this.actTitle = this.$t('index.huodaofukan');
					uni.showToast({
						title: this.$t('order.xuanzezhif'),
						icon: 'none',
						duration: 2500
					})
				} else if (this.actType == 1 && this.shifoudf == 0) {
					this.actTitle = this.$t('order.quzhifu');
				}
				console.log(this.shifoudf)
			},
			changaddr() {
				uni.navigateTo({
					url: '/pages/UserCenter/dizhi/dizhilist'
				})
			},

			yuyueshijian() {
				this.$refs.chooseTime.open()
			},
			changeTime(e) {
				//选择的时间
				console.log('选择的时间', e.value);
				this.delryTime = e.value;
			},
			deliveryclose() {
				this.delryTime = '';
			},
			peisong() {
				if (this.actType > 0) {
					return;
				}
				this.showAdrr = 0;
				this.peisongimg = '/static/images/peisongh@3x.png';
				this.ziquimg = '/static/images/ziqu@3x.png';
				this.tangshiimg = '/static/images/tangshih.png';
				this.Bcolor = 'whitesmoke';
				this.Bcolorr = 'lightgray';
				this.Bcolorrr = 'lightgray';
				this.Tcolor = 'black';
				this.Tcolorr = 'darkgray';
				this.Tcolorrr = 'darkgray';
				this.psf = parseFloat(this.freight);

				this.jisuanjiner();
			},
			ziqu() {
				if (this.actType > 0) {
					return;
				}
				this.showAdrr = 1;
				this.peisongimg = '/static/images/peisong@3x.png';
				this.ziquimg = '/static/images/ziquh@3x.png';
				this.tangshiimg = '/static/images/tangshih.png';
				this.Bcolor = 'lightgray';
				this.Bcolorr = 'whitesmoke';
				this.Bcolorrr = 'lightgray';
				this.Tcolor = 'darkgray';
				this.Tcolorr = 'black';
				this.Tcolorrr = 'darkgray';
				this.psf = 0;
				this.jisuanjiner();
			},
			tangshi() {
				this.showAdrr = 2;
				this.peisongimg = '/static/images/peisong@3x.png';
				this.ziquimg = '/static/images/ziqu@3x.png';
				this.tangshiimg = '/static/images/tangshi.png';
				this.Bcolor = 'lightgray';
				this.Bcolorr = 'lightgray';
				this.Bcolorrr = 'whitesmoke';
				this.Tcolor = 'darkgray';
				this.Tcolorr = 'darkgray';
				this.Tcolorrr = 'black';
				this.psf = 0;
				this.jisuanjiner();
			},
			//确认订单，要求下载app
			qufukuan() {

				if (this.foodlist.length == 0) {
					uni.showToast({
						title: this.$t('comp.qingxzsp'),
						icon: 'none',
						duration: 2500
					})
					return;
				}
				api('getAppDownload', {}, r => {
					console.log(r)
					uni.showModal({
						title: this.$t('api.message'),
						content: this.$t('jiesuan.xiazapp'),
						showCancel: true,
						cancelText: this.$t('jiesuan.xzios'),
						confirmText: this.$t('jiesuan.xiazandriod'),
						success: (res) => {
							if (res.confirm) {
								// 点击下载Android版本
								const isAndroid = this.isAndroidDevice();
								if (isAndroid) {
									// 安卓设备自动下载并安装
									this.downloadAndInstallAndroid(r.data.data.androidUrl);
								} else {
									// 非安卓设备直接打开下载链接
									window.open(r.data.data.androidUrl, '_blank');
								}
							} else if (res.cancel) {
								// 点击下载iOS版本
								this.downloadIOSApp(r.data.data.iosUrl);
							}
						}
					});
					return;
				});
				return


				if (this.keyixd == false) {
					uni.showToast({
						title: this.$t('mend.dianjiastatedy'),
						icon: 'none',
						duration: 2500
					})
					return;
				}


				if (this.actType == 2) { //已经支付过了！！
					// uni.showToast({
					//     title: '已经支付过了！！',
					//     icon: 'none',
					//     duration: 2500
					// })
					return;
				}
				if (this.actType == 1) { //未支付，跳转支付
					this.zffsS = true;
					return;
				}
				var data;
				if (this.ddId.length > 0) {
					console.log('已经生成订单，不能重复提交');
				} else {
					this.ddId = '99' + new Date().valueOf();
				}
				var cretim = getApp().globalData.sj();
				// console.log(cretim);
				// return;
				if (this.showAdrr == 0) {
					if (this.dizhiID == '') {
						uni.showToast({
							title: this.$t('order.shdz'),
							icon: 'none',
							duration: 3500
						})
						return;
					}
					if (!this.isGetyunfei) {
						uni.showToast({
							title: this.$t('order.hqyfsb'),
							icon: 'none',
							duration: 3500
						})
						return;
					}

					data = {
						"ddId": this.ddId,
						"shId": this.userid,
						"mdId": this.mendid,
						"shdzId": this.dizhiID.id,
						"amount": this.zje,
						"remarks": this.remarks,
						"type": 0,
						"delryTime": this.delryTime, //new Date().toISOString(), 
						"foodlist": this.foodlist,
						"freight": this.psf,
						"jvli": this.jvli,
						"longitude": this.mendianMs.longitude,
						"latitude": this.mendianMs.latitude,
						"collectPayment": this.shifoudf,
						"cretim": cretim,
						"yhId": this.kqidpt, //平台使用优惠券id
						"mdYhId": this.kqidsj, //门店优惠券id
						"activity": this.hdidpt, //平台促销活动id
						"mdActivity": this.hdidsj, //门店促销活动id
						"salesReduction": this.salesReduction, //平台促销減免值
						"mdSalesReduction": this.mdSalesReduction, //门店促销減免值
						"discountAmount": this.discountAmount, //平台优惠券优惠金额
						"mdDiscountAmount": this.mdDiscountAmount, //门店优惠券优惠金额
						"xiadanjiaoyan": 2
					}
				} else {
					data = {
						"ddId": this.ddId,
						"shId": this.userid,
						"mdId": this.mendid,
						"shdzId": '',
						"amount": this.zje,
						"remarks": this.remarks,
						"type": this.showAdrr,
						"delryTime": this.delryTime, // new Date().toISOString(), 
						"foodlist": this.foodlist,
						"freight": this.psf,
						"jvli": this.jvli,
						"longitude": this.mendianMs.longitude,
						"latitude": this.mendianMs.latitude,
						"collectPayment": this.shifoudf,
						"cretim": cretim,
						"yhId": this.kqidpt, //平台使用优惠券id
						"mdYhId": this.kqidsj, //门店优惠券id
						"activity": this.hdidpt, //平台促销活动id
						"mdActivity": this.hdidsj, //门店促销活动id
						"salesReduction": this.salesReduction, //平台促销減免值
						"mdSalesReduction": this.mdSalesReduction, //门店促销減免值
						"discountAmount": this.discountAmount, //平台优惠券优惠金额
						"mdDiscountAmount": this.mdDiscountAmount, //门店优惠券优惠金额
						"xiadanjiaoyan": 2
					}
				}
				this.zhifuUrl = '';
				this.addorder(data);

			},
			getaddressList() {
				api('getaddressList', {}, r => {
					this.addrList = r.data.data;
					if (this.dizhiID != '') {
						console.log('3333')
						this.getyunfei(this.dizhiID.latitude, this.dizhiID.longitude);
					} else {
						if (this.addrList.length > 0) {
							console.log('2222')
							this.dizhiID = this.addrList[0];
							this.mpImage = this.dizhiID.annexes;
							this.getyunfei(this.dizhiID.latitude, this.dizhiID.longitude);
						}
					}
				}, failc => {
					//console.log('getadvertis----',failc)
				})
			},
			getmendianDetail(id) {
				api('getmendianDetail', {
					id: id
				}, r => {
					this.mendianMs = r.data.data;
					console.log('getmendianDetail', this.mendianMs);
					if (this.mendianMs) {
						if (this.mendianMs.state == 1) {
							this.keyixd = false;
						}
					}
					if (this.dizhiID == '') {
						this.getaddressList();
					} else {
						console.log('111')
						this.getyunfei(this.dizhiID.latitude, this.dizhiID.longitude);
					}
				}, failc => {
					//console.log('getadvertis----',failc)
				})
			},
			getyunfei(lat, lng) {
				if (this.mendianMs == '') {
					return;
				}
				//this.getjuliForyunfei(lat,lng);//前端请求规划路径
				//this.getjuliForyunfeiHT(lat,lng);//后端请求规划路径
				//先请求直线距离运费，如果规划路径运费小于直线距离则用直线距离的值
				//1--------在这个方法中调用规划计算
				console.log("getyunfei----------")
				this.zhixianyuanfei(lat, lng);
			},
			//通过坐标直线计算运费
			zhixianyuanfei(lat, lng) {
				var that = this;
				api('getyunfei', {
					lat1: lng,
					lng1: lat,
					lat2: this.mendianMs.longitude,
					lng2: this.mendianMs.latitude
				}, r => {
					console.log('直线运费');
					console.log(r);
					if (r.data.code != 200) {
						return;
					}
					that.freight = parseInt(r.data.data.freight);
					if (that.freight > 0) {} else {
						that.freight = 0;
					}
					that.zhixianfreight = that.freight;
					that.zhixianjuli = r.data.data.jvli;
					that.getjuliForyunfeiHT(lat, lng);
				}, failc => {
					//console.log('getadvertis----',failc)
				})
			},
			getjuliForyunfei(lat, lng) { //前端
				var data = {
					"origin": {
						"location": {
							"latLng": {
								"latitude": lat,
								"longitude": lng
							}
						}
					},
					"destination": {
						"location": {
							"latLng": {
								"latitude": this.mendianMs.latitude,
								"longitude": this.mendianMs.longitude
							}
						}
					},
					"travelMode": "DRIVE",
					"units": "METRIC" //米
				};
				console.log(data);
				api('getdistense', data, r => {
					console.log('getadvertis----', r);
					if (r.statusCode == 200) {
						var dist = r.data.routes[0].distanceMeters;
						console.log(dist / 1000);
						this.getyunfeiWithJuli(dist / 1000);
						console.log('路径运费');
					} else {
						this.zhixianyuanfei(lat, lng);
						console.log('路径计算距离失败！');
						uni.showToast({
							title: this.$t('api.wangluoshibai'),
							icon: 'none',
							duration: 3500
						})
					}
				}, failc => {
					console.log('getadvertis----', failc)
				})
			},
			getjuliForyunfeiHT(lat, lng) {
				var that = this;
				var latlng1 = '' + lat + ',' + lng;
				var latlng2 = '' + this.mendianMs.latitude + ',' + this.mendianMs.longitude;
				// var latlng1='10.715641,106.73932';//''+lat+','+lng;
				// var latlng2='10.754999,106.735601';//''+this.mendianMs.latitude+','+this.mendianMs.longitude;
				api('getluxianjvli', {
					latlng1: latlng1,
					latlng2: latlng2,
					id: this.userid
				}, r => {
					console.log('getjuliForyunfeiHT', r);
					if (r.data.code == 200) {
						if (r.data.data[0]) {
							var legs = r.data.data[0].legs;
							if (legs[0]) {
								var juli = legs[0].distance.value;
								// uni.showToast({
								//     title:'通过轨迹计算运费',
								//     icon: 'none',
								//     duration: 3500
								// })
								if (juli > that.zhixianjuli) {
									that.getyunfeiWithJuli(juli / 1000);
								} else {
									that.psf = that.freight;
									that.jvli = that.zhixianjuli;
									that.isGetyunfei = true;
									console.log('直线运费');
									if (this.showAdrr == 0) {
										that.jisuanjiner();
									}
								}

								return;
							}
						}
					}
					that.psf = that.freight;
					that.jvli = that.zhixianjuli;
					that.isGetyunfei = true;
					console.log('直线运费');

					if (this.showAdrr == 0) {
						that.jisuanjiner();
					}
				}, failc => {
					//console.log('getadvertis----',failc)
				})
			},


			getyunfeiWithJuli(distence) {
				var that = this;
				api('getZuiyyfei', {
					quli: JSON.stringify(distence)
				}, r => {
					console.log(r);
					if (r.data.code != 200) {
						return;
					}
					that.psf = parseInt(r.data.data.freight);
					if (that.psf > 0) {} else {
						that.psf = 0;
					}
					that.freight = that.psf;
					that.jvli = r.data.data.jvli;
					that.isGetyunfei = true;
					if (this.showAdrr == 0) {
						that.jisuanjiner();
					}
				}, failc => {
					//console.log('getadvertis----',failc)
				})
			},

			addorder(data) {
				var that = this;
				uni.showLoading({
					title: 'Loading...',
					mask: true
				})
				console.log('addorder', data);
				api('addorder', data,
					r => {
						console.log(r);
						uni.hideLoading();
						if (r.data.code == 200) {
							this.qingkonggouwuche();
							this.ddId = data.ddId;
							this.rId = r.data.data.id;
							this.orderDetl = r.data.data;
							if (this.shifoudf == 0) {
								this.actType = 1;
								this.actTitle = that.$t('order.quzhifu');
								uni.showToast({
									title: that.$t('order.xuanzezhif'),
									icon: 'none',
									duration: 2500
								})
							} else {
								this.actType = 1;
								this.actTitle = that.$t('index.huodaofukan');
								//到付订单，直接更新支付状态
								this.huodaofukuan();
							}

						} else {
							uni.showToast({
								title: r.data.msg,
								icon: 'none',
								duration: 3000
							})
						}
					}, failc => {
						uni.hideLoading();
						//console.log('getadvertis----',failc)
					})
			},

			getVNPay() {
				api('setorderuzt', {
					id: this.rId,
					"collectPayment": 0
				}, res => {
					if (res.data.code != 200) {
						return;
					}
				}, failc => {
					return;
				})
				this.zffsS = false;
				var language = uni.getStorageSync('language');
				var lg;
				if (language == 'yuenan') {
					lg = 'vi';
				} else {
					lg = 'en';
				}
				uni.showLoading({
					title: 'Loading...',
					mask: true
				})
				api('VNPay', {
					orderid: this.ddId,
					amount: parseInt(this.zje),
					language: lg
				}, r => {
					uni.hideLoading();
					if (r.data.code != 200) {
						uni.showToast({
							title: r.data.msg,
							icon: 'none',
							duration: 3500
						})
						return;
					}
					this.shifouzhifu = true;
					this.zhifuUrl = '/pages/OrderList/buy/Zhifuyemian?url=' + encodeURIComponent(JSON.stringify(r
						.data.data)) + '&ddid=' + this.ddId;
					uni.navigateTo({
						url: '/pages/OrderList/buy/Zhifuyemian?url=' + encodeURIComponent(JSON.stringify(r
							.data.data)) + '&ddid=' + this.ddId
					})
				}, failc => {
					uni.hideLoading();
					//console.log('getadvertis----',failc)
				})
			},
			huodaofukuan() {
				this.shifoudf = 1;
				this.zffsS = false;
				uni.showLoading({
					title: 'Loading...',
					mask: true
				})
				var that = this;
				api('setorderuzt', {
					id: this.rId,
					"collectPayment": this.shifoudf
				}, res => {
					console.log('setorderuzt:', res)
					uni.hideLoading();
					if (res.data.code == 200) {
						this.actType = 2;
						this.actTitle = that.$t('order.yizhifu');
						uni.showToast({
							title: that.$t('order.xiadancg'),
							icon: 'none',
							duration: 2500,
							mask: true
						})
						setTimeout(function() {
							// 这里写要延时执行的代码
							uni.redirectTo({
								url: '/pages/OrderList/OrderDetail?ddid=' + that.ddId +
									'&isShangjia=0'
							})
						}, 2500);
					} else {
						if (res.data.msg) {
							uni.showToast({
								title: res.data.msg,
								icon: 'none',
								duration: 2000
							})
						}
					}
				}, failc => {
					uni.hideLoading();
					//console.log('getadvertis----',failc)
				})
			},
			setorderuzt() {
				var that = this;
				api('setorderuzt', {
					id: this.rId,
					state: 1
				}, res => {
					this.actType = 2;
					this.actTitle = that.$t('order.yizhifu');
					uni.showToast({
						title: that.$t('order.xiadancg'),
						icon: 'none',
						duration: 2500,
						mask: true
					})
					setTimeout(function() {
						// 这里写要延时执行的代码
						uni.redirectTo({
							url: '/pages/OrderList/OrderDetail?ddid=' + that.ddId + '&isShangjia=0'
						})
					}, 2500);

				}, failc => {
					//console.log('getadvertis----',failc)
				})
			},
			getorderDetl() {
				var that = this;
				api('getorderxq', {
					ddid: this.ddId
				}, r => {
					this.orderDetl = r.data.data;
					if (this.orderDetl.state == 1) {
						that.actType = 2;
						that.actTitle = that.$t('order.yizhifu');
						uni.showToast({
							title: that.$t('order.xiadancg'),
							icon: 'none',
							duration: 2500,
							mask: true
						})
						setTimeout(function() {
							// 这里写要延时执行的代码
							uni.redirectTo({
								url: '/pages/OrderList/OrderDetail?ddid=' + that.ddId +
									'&isShangjia=0'
							})
						}, 2500);

					}
				}, failc => {
					//console.log('getadvertis----',failc)
				})
			},
			qingkonggouwuche() {
				if (this.foodlist.length > 1) {
					uni.setStorageSync('gouwuche', '');
					return;
				}

				var gwc = uni.getStorageSync('gouwuche');
				var gouwuche;
				if ('' == gwc || null == gwc || undefined == gwc) {} else {
					gouwuche = JSON.parse(gwc);
					if (gouwuche.foodlist.length <= 1) {
						uni.setStorageSync('gouwuche', '');
						return;
					}
					for (var i = 0; i < gouwuche.foodlist.length; i++) {
						var sp = gouwuche.foodlist[i];
						if (this.foodlist[0].id == sp.id) {
							gouwuche.foodlist.splice(i, 1);
							let gwcS = JSON.stringify(gouwuche);
							uni.setStorageSync('gouwuche', gwcS);
						}
					}
				}
			},
			gengxingouwuche(item) {
				var gwc = uni.getStorageSync('gouwuche');
				if ('' == gwc || null == gwc || undefined == gwc) {
					return;
				}
				var gouwuche = JSON.parse(gwc);
				for (var i = 0; i < gouwuche.foodlist.length; i++) {
					var sp = gouwuche.foodlist[i];
					if (item.id == sp.id) {
						if (item.number > 0) {
							gouwuche.foodlist[i].number = item.number;
						} else {
							gouwuche.foodlist.splice(i, 1);
						}
						if (gouwuche.foodlist.length < 1) {
							uni.setStorageSync('gouwuche', '');
						} else {
							let gwcS = JSON.stringify(gouwuche);
							uni.setStorageSync('gouwuche', gwcS);
						}
						return;
					}
				}
			},
			pushMsg(cid, orderId) { //消息推送
				api('pushMsgSJ', {
					cid: cid,
					title: this.$t('order.xindd'),
					content: orderId,
					payload: ''
				}, res => {
					console.log(res)
				}, failc => {
					//console.log('getadvertis----',failc)
				})
			},
			selectImage() {
				console.log('selectImage');
				this.$refs.yhdslCropper.chooseImage();
			},
			uploadImg(e) {
				console.log('------------uploadImg:', e)
				this.spImage = e;
				var that = this;
				uni.uploadFile({
					url: this.$upImagurl, //上传图片api
					filePath: e,
					name: 'file',
					header: {
						//"Authorization": userinfo.token
					},
					success: (res) => {
						let group = JSON.parse(res.data);
						that.mpImage = group.data;
						console.log(group)
						api('ADDaddress', {
								id: that.dizhiID.id,
								annexes: that.mpImage
							},
							res => {
								if (res.data.code == 200) {
									that.dizhiID.annexes = that.mpImage;
									uni.setStorageSync("peisongdizhi", that.dizhiID);
								}
								console.log('getGoodsDetail:', res);
							}, failc => {
								//console.log('getadvertis----',failc)
							})
						uni.showToast({
							title: that.$t('mend.shangccg'),
							icon: "success"
						})

					}
				});
			},
		}
	}
</script>

<style lang="scss">
	page {
		background-color: #F2F3F7;
	}

	.contentV {
		width: 100%;
		position: relative;

	}

	.linesp {
		width: 100%;
		height: 8rpx;
		background-color: aliceblue;
	}

	.pinglun {
		margin: 16rpx;
		padding: 10rpx;
		width: 92%;
		height: 100rpx;
		border-radius: 15rpx;
		border: 2rpx solid lightgray;
	}

	.ctinrow {
		margin-top: 20rpx;
		width: 100%;
		height: 80rpx;
		display: flex;
		flex-direction: row;
		align-items: center;
		justify-content: center;
	}


	.delbtct {
		margin-left: 10%;
		margin-top: 20rpx;
		padding-bottom: 30rpx;
		width: 80%;
	}

	.delbt {
		text-align: center;
		font-size: 36rpx;
		width: 100%;
		height: 80rpx;
		line-height: 80rpx;
		color: white;
		background-color: goldenrod;
		border-radius: 10rpx;
	}

	.topSwichV {
		height: 70rpx;
		width: 280rpx;
		border-radius: 35rpx;
		display: flex;
		flex-direction: row;
		align-items: center;
		justify-content: center;
	}

	.topSwichVL {
		margin-left: -40rpx;
		height: 70rpx;
		width: 200rpx;
		border-radius: 35rpx;
		display: flex;
		flex-direction: row;
		align-items: center;
		justify-content: center;
	}

	.toppz {
		width: 50rpx;
	}

	.toppztext {
		font-size: 30rpx;
	}

	.spnodetail {
		display: flex;
		flex-direction: row;
		align-items: center;
		background-color: white;
		margin-top: 20rpx;
		margin-bottom: 20rpx;
	}

	.spIcon {
		margin: 20rpx;
		width: 90rpx;
		height: 90rpx;
	}

	.xiaoji {
		margin-left: auto;
		margin-right: 30rpx;
	}

	.actBTV {
		width: 100%;
		display: flex;
		flex-direction: row;
		justify-content: space-between;
		align-items: center;
	}

	.viewinrow {
		display: flex;
		flex-direction: row;
		align-items: center;
		width: 100%;
	}

	.kouweisku {
		padding-right: 10rpx;
		color: chocolate;
		font-size: 26rpx;
	}

	.shifdf {
		height: 90rpx;
		width: 90%;
		margin-left: 5%;
		align-items: center;
	}

	.shifdftext {
		margin-left: 30rpx;
		font-size: 30rpx;
	}

	.hdts {
		margin-left: 30rpx;
		font-size: 30rpx;
		overflow: hidden;
		text-overflow: ellipsis;
		display: -webkit-box;
		-webkit-line-clamp: 1;
		-webkit-box-orient: vertical;
	}

	.picker-view {
		width: 750rpx;
		height: 300rpx;
		margin-top: 10rpx;
	}

	.item {
		line-height: 100rpx;
		text-align: center;
	}

	.zhifbut {
		text-align: center;
		margin-top: 12rpx;
		margin-bottom: 12rpx;
		width: 80%;
		border-radius: 10rpx;
		color: white;
		line-height: 70rpx;
	}

	.imageRJ {
		width: 40rpx;
		height: 40rpx;
		margin-right: 8rpx;
	}

	.imageR {
		width: 40rpx;
		height: 40rpx;
		margin-right: 30rpx;
	}

	.textR {
		font-size: 26rpx;
		margin-left: 6rpx;
		margin-right: 6rpx;
	}
</style>