<template>
	<view class="towcontent flex-between">
		<view class="towcontent_item flex-colum" v-for="(item,index) in district" :key="index"
			@click="clickdistrict(item,index)">
			<image :src="item.coverImg" mode="aspectFill"></image>
			<text>{{item.name}}</text>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {};
		},
		props: {
			district: {
				type: Array,
				default () {
					return []
				}
			},
			title: {
				type: String,
				default: '每日特价'
			},
			img: {
				type: String,
				default: ''
			},
		},
		methods: {
			clickdistrict(item) {
				switch (item.jumpType) {
					case 'absolute':
						uni.pro.navigateTo('webview/webview', {
							url: item.absUrl
						});
						break;
					case 'relative':
					uni.setStorage({
						key: 'itemData',
						data: item,
					});
						uni.pro.navigateTo(item.absUrl, item.name);
						break;
					case 'scan':
						if (!uni.utils.pluschooseImage()) {
							return false
						}
						// #ifdef APP || MP-WEIXIN
						uni.scanCode({
							success: (res) => {
								let tableCode = this.getQueryString(decodeURIComponent(res.result), 'code')
								uni.cache.set('tableCode', tableCode)
								if (tableCode) {
									uni.pro.navigateTo('order_food/order_food', {
										tableCode: tableCode,
									})
								}
							}
						});
						// #endif
						break;
				}
			},
			getQueryString(url, name) { //解码
				var reg = new RegExp('(^|&|/?)' + name + '=([^&|/?]*)(&|/?|$)', 'i')
				var r = url.substr(1).match(reg)
				if (r != null) {
					return r[2]
				}
				return null;
			},
		}
	};
</script>

<style scoped lang="scss">
	.towcontent {
		position: relative;
		margin-top: -32rpx;
		padding: 32rpx 40rpx;
		width: 100%;
		background: #F9F9F9;
		border-radius: 48rpx 48rpx 0rpx 0rpx;
		overflow-x: auto;
		flex-wrap: nowrap;

		.towcontent_item {
			width: 25%;
			margin-left: 34rpx;

			image {
				width: 92rpx;
				height: 92rpx;
			}

			text {
				margin-top: 16rpx;
				font-family: Source Han Sans CN, Source Han Sans CN;
				font-weight: 400;
				font-size: 28rpx;
				color: #333333;
				white-space: nowrap;
			}
		}

		.towcontent_item:nth-child(1) {
			margin-left: 0rpx;
		}
	}
</style>