<template>
	<view class="container">
		<block v-if="!isLoding">

			<view v-if="status == 'PROCESS'">
				<view class="tips">授权开通搜索直达待商家确认中</view>
				<view class="btn" @click="navBack">返回</view>
			</view>
			<view v-else-if="status == 'SUCCESS'">
				<view class="tips">搜索直达开通成功</view>
				<view class="btn" @click="navBack">返回</view>
			</view>
			<view v-else>
				<view class="tips">授权开通搜索直达</view>
				<view class="btn" @click="showquan">开通授权</view>
			</view>
		</block>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				admin_id: uni.getStorageSync("admin_id"),
				isLoding: true,
				status: ""
			}
		},

		onLoad(e) {
			this.getInfo()
		},

		methods: {
			getInfo() {
				this.request({
					url: "alipaycoupon/operation",
					data: {
						admin_id: this.admin_id
					}
				}).then(res => {
					
					if (res.code == 200) {
						if (!Array.isArray(res.data)) {
							this.status = res.data
						}

					} else {
						uni.showToast({
							title: res.message,
							icon: 'none'
						})
					}
					this.isLoding = false
				}).catch(res => {
					uni.showToast({
						title: res.message,
						icon: 'none'
					})
				})

			},
			showquan() {
				this.request({
					url: "alipaycoupon/operation_open",
					data: {
						admin_id: this.admin_id
					}
				}).then(res => {
					if (res.code == 200) {
						uni.showModal({
							content: res.message,
							showCancel: false,
							success: () => {
								this.getInfo()
							}
						})
					} else {
						uni.showToast({
							title: res.message,
							icon: 'none'
						})
					}
				}).catch(res => {
					uni.showToast({
						title: res.message,
						icon: 'none'
					})
				})
			},
			navBack() {
				uni.navigateBack()
			}

		}
	}
</script>

<style scoped lang="scss">
	.container {
		padding: 200rpx 32rpx 0;

		.tips {
			text-align: center;
			font-size: 26rpx;
			color: #666;
		}

		.btn {
			width: 300rpx;
			height: 80rpx;
			background: linear-gradient(315deg, #3387ff 2%, #569bff 99%);
			border-radius: 8rpx;
			box-shadow: 0rpx 0rpx 8rpx 0rpx rgba(51, 135, 255, 0.20);
			text-align: center;
			line-height: 80rpx;
			font-size: 36rpx;
			font-weight: 500;
			color: #fff;
			margin: 40rpx auto;
		}
	}
</style>
