<template>
	<!-- 选择门店 -->
	<view>
		<u-navbar border :title="navTitle" autoBack placeholder></u-navbar>
		<!-- <view v-if="treeData.length > 0">
			<tree-item v-for="item in treeData" :key="item.id" :item="item" @confirm="confirm"></tree-item>
		</view>
		<view style="margin-top: 30%;" v-else>
			<u-empty mode="list" text="门店列表为空"></u-empty>
		</view> -->
		<view class="card_head_mark">
			<view class="card_sys" @click="sweep()">
				<u-icon name="scan" size="60" color="#18b566"></u-icon>
				<view class="sys_title">扫一扫</view>
			</view>
			<view class="title_sad">扫描门店/气站二维码</view>
		</view>
	</view>
</template>

<script>
	import TreeItem from '@/components/TreeItem.vue';
	export default {
		components: {
			TreeItem
		},
		data() {
			return {
				treeData: [],
				navTitle: '',
				selectiveType: '',
			}
		},
		onLoad(receive) {
			this.navTitle = receive.title
			this.selectiveType = receive.id
			// this.getList()
		},
		methods: {
			// 扫一扫
			sweep() {
				// 允许从相机和相册扫码
				uni.scanCode({
					scanType: ['qrCode'],
					autoZoom: false,
					success: (res) => {
						if (res.result) {
							let url = res.result;
							const arrf = url.split(',')
							console.log(arrf, '--------');
							if (arrf.length > 3) {
								this.$cache.setCache('storeInformation', arrf)
								uni.navigateTo({
									url: '/pages/order/delivery?id=' + this.selectiveType + '&title=' +
										this.navTitle +
										'&cmpCode=' + arrf[0]
								});
							} else {
								uni.$u.toast('请扫描门店二维码')
							}
						} else {
							console.log('请重新扫描');
							return false;
						}
					},
					fail: (res) => {
						console.log('未识别到二维码1');
					}
				})
			},
			getList() {
				if (this.selectiveType == '25' || this.selectiveType == '27') {
					this.$api.get('/api/store/all2').then(res => {
						if (res.code == 200) {
							if (res.data) {
								this.treeData = res.data
							}
						}
					})
				} else {
					this.$api.get('/api/store/all').then(res => {
						if (res.code == 200) {
							if (res.data) {
								this.treeData = res.data
							}
						}
					})
				}
			},
			// 选择门店
			confirm(cmpCode) {
				uni.navigateTo({
					url: '/pages/order/delivery?id=' + this.selectiveType + '&title=' + this.navTitle +
						'&cmpCode=' + cmpCode
				});
			}
		}
	}
</script>

<style lang="scss">
	.card_head_mark {
		display: flex;
		justify-content: center;
		flex-direction: column;
		align-items: center;
		padding-bottom: 30rpx;
		border-bottom: 2rpx solid #e4e7ed;
	}

	.card_sys {
		cursor: pointer;
		margin-top: 30rpx;
		display: flex;
		justify-content: center;
		align-items: center;
		flex-direction: column;
		width: 180rpx;
		height: 180rpx;
		border-radius: 20rpx;
		background-color: #f4f4f5;
	}

	.sys_title {
		font-size: 32rpx;
		color: #18b566;
	}

	.title_sad {
		font-size: 30rpx;
		margin-top: 20rpx;
	}
</style>