<template>
	<view class="v-pages-bg bgcolor p-b-24">
		<view class="fod_det_pic">
			<image :src="rootPath + foodDetail.imagelist[0]" mode="aspectFill" class="ms_top_img"></image>
		</view>
		<!-- 标题 -->		
		<view class="v-card detail container-fluid m-t--80">
			<view class="v-detail-top"><text class="postion">{{foodDetail.region}}</text></view>
			<view class="v-detail-name"><text class="text">{{ foodDetail.title }}</text></view>
		</view>
		<!-- 团购 -->		
		<view class="v-card detail container-fluid m-t-24">
			<view class="v-detail-title">
				<view class="text">
					<text>团购</text>
				</view>
			</view>
		</view>
		<!-- 代金券 -->
		<view class="v-card detail container-fluid m-t-24">
			<view class="v-detail-title">
				<view class="text">
					<text>代金券</text>
				</view>
			</view>
		</view>
		<!-- 介绍 -->
		<view class="v-card detail container-fluid m-t-24">
			<view class="v-detail-title">
				<view class="text">
					<text>美食介绍</text>
				</view>
			</view>
			<view class="v-detail-content m-t-24">
				<u-parse :content="foodDetail.content" />
			</view>
		</view>
		<!-- 附近商家推荐 -->
		<view class="v-card detail container-fluid m-t-24">
			<view class="v-detail-title">
				<view class="text">
					<text>附近商家推荐</text>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import uParse from '@/uni_modules/uview-ui/components/u-parse/u-parse.vue';
	export default {
		components: {
			uParse
		},
		data() {
			return {
				strings: '',
				fid: '',
				zhankai: 0,
				shouqi: 1,
				fareacode: '',
				foodDetail: {},
				restaurantList: [],
				lon: '',
				lat: '',
				isShowBusiness: 'NO',
				rootPath: this.$config.ROOTPATH,
				netType: true
			};
		},
		onLoad: function(option) {
			var that = this;
			this.$util.getNetworkType(
				function(res) {
					if (res.networkType === 'none') {
						uni.showToast({
							title: that.$param.netMsg,
							icon: "none",
							duration: 2000
						})
						that.netType = false;
					}
				},
				function() {
					uni.showToast({
						title: that.$param.netMsg,
						icon: "none",
						duration: 2000
					})
					that.netType = false;
				}
			)
			if (!that.netType) {
				return;
			}
			this.$util.hideLoadingByTime();
			this.fid = option.fid;
			this.fareacode = option.fareacode;
			(this.lon = this.$param.clng), (this.lat = this.$param.clat);
			this.getIsShow();
			this.getFoodDetail(option.fid, option.fareacode);

			that.$util.saveOperatorLog(that, 'FOOD', option.fid);
		},
		methods: {
			getIsShow: function() {
				var that = this;
				this.$Request
					.post(this.$config.getSysParamFormRegion, {
						userkey: this.$param.userkey
					})
					.then(res => {
						if (!that.$util.isSuccess(res)) {
							return;
						}
						//console.log(res.data);
						var d = res.data;
						this.isShowBusiness = d.isShowBusiness;
					});
			},
			preview(src, e) {
				// do something
			},
			navigate(href, e) {
				// do something
			},
			getFoodDetail: function(guid, region) {
				var that = this;
				var data = {
					userkey: this.$param.userkey,
					type: this.$param.foodType,
					guid: guid,
					lng: this.lon,
					lat: this.lat
				};
				this.$Request.post(this.$config.getMessgeInfoDetailFormId, data).then(res => {
					if (!that.$util.isSuccess(res)) {
						return;
					}
					console.log("========")
					var data = res.data;
					data.logo = this.$config.ROOTPATH + data.logo;
					var shangjia = data[that.$param.shangjiakey];
					for (let i = 0; i < shangjia.length; i++) {
						shangjia[i].logo = this.$config.ROOTPATH + shangjia[i].logo;
						shangjia[i].distance = this.$util.formatDistance(shangjia[i].distance);
					}
					this.restaurantList = shangjia;
					this.foodDetail = data;				
				});
			},
			opens: function() {
				(this.zhankai = 1), (this.shouqi = 0);
			},
			goToNavigation: function(lon, lat, address, businessname) {
				// #ifdef H5

				if (this.$wechat.isWechat()) {
					var mapParam = {
						latitude: lat,
						longitude: lon,
						scale: 18,
						name: businessname,
						address: address
					};
					this.$util.openLocation(mapParam);
					return;
				}
				window.location.href = 'https://uri.amap.com/navigation?to=' + lon + ',' + lat + ',' + businessname +
					'&mode=car&src=nyx_super&callnative=1';
				// #endif

				// #ifdef APP-PLUS
				if (plus.os.name == 'Android') {
					//判断手机是否安装了百度地图 判断hasBaiduMap的true false
					var hasBaiduMap = plus.runtime.isApplicationExist({
						pname: 'com.baidu.BaiduMap',
						action: 'baidumap://'
					});
					//判断手机是否安装了高德地图 判断hasAmap的true false
					var hasAmap = plus.runtime.isApplicationExist({
						pname: 'com.autonavi.minimap',
						action: 'androidamap://'
					});
					//打开百度app导航url
					var urlBaiduMap =
						'baidumap://map/direction?origin=' + this.lat + ',' + this.lon + '&destination=' + lat + ',' +
						lon + '&coord_type=bd09ll&src=andr.baidu.openAPIdemo';
					//打开高德app导航url   dlat  dlon dname为终点经纬度和地名。不传起点默认为当前位置。
					var urlAmap = 'androidamap://route?slat=' + this.lat + '&slon=' + this.lon + '&dlat=' + lat +
						'&dlon=' + lon + '&dev=0&t=2';
					//底部弹框选择打开的应用
					if (hasBaiduMap && hasAmap) {
						plus.nativeUI.actionSheet({
								title: '选择地图应用',
								cancel: '取消',
								buttons: [{
										title: '百度地图'
									},
									{
										title: '高德地图'
									}
								]
							},
							function(e) {
								switch (e.index) {
									case 1:
										plus.runtime.openURL(urlBaiduMap);
										break;
									case 2:
										plus.runtime.openURL(urlAmap);
										break;
								}
							}
						);
					} else if (hasAmap) {
						plus.runtime.openURL(urlAmap);
					} else if (hasBaiduMap) {
						plus.runtime.openURL(urlBaiduMap);
					}
				}
				// #endif
			},
			goToRetaurant: function(guid) {
				uni.navigateTo({
					url: '/subPageA/store/storedetail/storedetail?id=' + guid
				});
			}
		}
	};
</script>

<style>
</style>