<template>
	<view class="container"></view>
</template>

<script>
export default {
	data() {
		return {
			type: null
		}
	},
	onLoad(options) {
		this.type = options.type
		this.handleClick(this.type)
	},
	methods: {
		handleClick(type) {
			// 1为商户,2为业主
			uni.login({
				provider: 'weixin',
				success: (res) => {
					this.handleQuery(type, res.code)
				}
			})
		},
		// 查询请求
		async handleQuery(type, code) {
			if (type === '1') {
				// 查询商家是否绑定
				const res = await this.$myRequest({
					url: '/mhotel/appget_user_ma.action',
					data: {
						code
					}
				})
				if (res.code === 200) {
					let data = JSON.stringify(res.data)
					uni.reLaunch({
						url: `/pages/shopInfo/shopInfo?type=1&data=${data}`
					})
				} else {
					uni.reLaunch({
						url: '/pages/shop/shop'
					})
				}
			} else if (type === '2') {
				// 查询业主是否已绑定
				const res = await this.$myRequest({
					url: '/mhotel/appgetUser.action',
					data: {
						code
					}
				})
				if (res.code === 200) {
					let data = JSON.stringify(res.data)
					uni.reLaunch({
						url: `/pages/shopInfo/shopInfo?type=2&data=${data}`
					})
				} else {
					uni.reLaunch({
						url: '/pages/shop2/shop2'
					})
				}
			}
		}
	}
}
</script>

<style lang="scss" scoped>
.container {
	height: 100vh;
	background-color: #fff;
}
</style>
