<template>
	<view>
		<view class="box_1">
			<view class="fod_det_pic">
				<image :src="rootPath + foodDetail.imagelist[0]" mode="aspectFill" class="ms_top_img"></image>
			</view>
			<view class="an_box_3">
				<view class="an_t_1">{{ foodDetail.title }}</view>
				<view class="amt_60 wc_cont">
					<view :class="[zhankai > shouqi ? 'fod_det_inf' : 'fod_det_inf h_define_cont']">
						<view class="lst_tit"><u-parse :content="foodDetail.content" :loading="loading" @preview="preview"
								@navigate="navigate" /></view>
						<!-- <view @tap="opens()" :class="[zhankai > shouqi ? 'hide' : 'nr_hide']">
							+ 查看详细
							<image src="/static/animg/index/btn_more.png" class="data-is-bottom"></image>
						</view> -->
						<!-- 内容显示完全出现 THE END-->
						<!-- <view class="amt_30"><view class="cont_end">-THE END-</view></view> -->
					</view>
				</view>
			</view>
		</view>
		<view class="an_box_3">
			<view v-if="isShowBusiness == 'YES' && (restaurantList != null && restaurantList.length > 0)">
				<view class="wc_tit_wp">
					<view class="an_t">
						<view class="an_t_1">附近商家推荐</view>
					</view>
				</view>

				<view @tap="goToRetaurant(item.guid)" class="amt_30" v-for="(item, index) in restaurantList" :key="index"
					:item-id="index" :data-year="index">
					<view class="dy_fx ls_inf_box">
						<image :src="item.logo" class="an_ls_img2" mode="aspectFill"></image>

						<view class="fx_1 ls_txt">
							<text class="lst_tit word_1">{{ item.title }}</text>
							<text class="lsinf word_1">{{ item.address }}</text>
							<text @click="goToNavigation(item.lng, item.lat, item.address, item.title)" class="lsinf">{{ item.distance
								}}</text>
						</view>
					</view>

					<view v-if="restaurantList.length <= 0" style="text-align: center;color: gray;">暂无数据！</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
import uParse from '@/components/gaoyia-parse/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;
				}
				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>
/* @import "/static/css/common.css";
	@import "../../cate/destination.css";
	@import "fooddetial.css";
	.content {
		padding-left: 1.5em;
		padding-right: 1.5em;
		font-size: 35upx; 
	}
	
	.fod_det_bt:after{ display: block; content: ''; width: 524rpx;  margin: 0 auto; margin-top:30rpx;height: 16rpx; background:url(/subPageA/images/bg_ms.png) no-repeat center;  }
	.mssj_jul:before{ content: '';display: inline-block; width: 38rpx; height: 38rpx; background:url(/subPageA/images/icn_mi.png) no-repeat; background-size: 100%; margin-right: 5rpx; position: relative; top:6rpx} */


.nr_hide {
	height: 76rpx;
	position: relative;
	display: flex;
	align-items: center;
	justify-content: center;
}

.data-is-bottom {
	width: 30rpx;
	height: 30rpx;
	padding: 0;
	margin-left: 15rpx;
}
</style>
