<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.pro.navigateTo(item.absUrl,item);
						break;
					case 'scan':
						if (!uni.utils.pluschooseImage()) {
							return false
						}
						// #ifdef H5
						if (this.wxSdk) {
							wx.scanQRCode({
								needResult: 1, // 默认为0，扫描结果由微信处理，1则直接返回扫描结果，
								scanType: ['qrCode', 'barCode'], // 可以指定扫二维码还是一维码，默认二者都有
								success: res => {
									// 当needResult 为 1 时，扫码返回的结果
									console.log(res.resultStr, res)
								}
							});
						} else {
							uni.showModal({
								title: '注意',
								content: '微信sdk初始化失败，请重新加载',
								success: res => {
									window.location.reload();
								}
							});
						}
						// #endif
						// #ifdef APP || MP-WEIXIN
						uni.scanCode({
							success: res => {
								console.log(res.result, res)
							}
						});
						// #endif
						break;
				}
			}
		}
	};
</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>