<template>
	<!-- 选择门店 -->
	<view>
		<u-navbar border title="选择门店" 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>
</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: {
			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">
</style>