<template>
	<view class="container">
		<view class="page-block">
			<view class="page-title-block">
				<view class="title">基本信息</view>
			</view>
			<view class="content">
				<view class="cell flex flex-y-center">
					<view class="title-block">
						<text>优惠券名称</text>
					</view>
					<view class="desc">
						<view class="input-box">{{info.name}}</view>
					</view>
				</view>
				
				<view class="cell flex flex-y-center">
					<view class="title-block">
						<text>发放对象</text>
					</view>
					<view class="desc">
						<view class="input-box">{{info.status == 1?'全平台':'新用户'}}</view>
					</view>
				</view>
				
				<view class="cell flex flex-y-center">
					<view class="title-block">
						<text>优惠券类别</text>
					</view>
					<view class="desc">
						<view class="input-box">{{info.type == 1?'满减券':'指定商品'}}</view>
					</view>
				</view>
				
				<view class="cell flex flex-y-center">
					<view class="title-block">
						<text>首页弹窗</text>
					</view>
					<view class="desc">
						<view class="input-box">{{info.is_index == 1?'是':'否'}}</view>
					</view>
				</view>
				
				<view class="cell flex flex-y-center">
					<view class="title-block">
						<text>优惠券数量</text>
					</view>
					<view class="desc">
						<view class="input-box">{{info.number}}</view>
					</view>
				</view>
				<view class="cell flex flex-y-center">
					<view class="title-block">
						<text>优惠券剩余数量</text>
					</view>
					<view class="desc">
						<view class="input-box">{{info.stock}}</view>
					</view>
				</view>
			</view>
		</view>
		<view class="page-block">
			<view class="page-title-block">
				<view class="title">优惠信息</view>
			</view>
			<view class="content">
				<view class="cell flex flex-y-center">
					<view class="title-block">
						<text>抵扣金额</text>
					</view>
					<view class="desc">
						<view class="input-box">{{info.reduce}}</view>
					</view>
				</view>

				<view class="cell flex flex-y-center">
					<view class="title-block">
						<text>满减金额</text>
					</view>
					<view class="desc">
						<view class="input-box">{{info.full}}</view>
					</view>
				</view>
				<view class="cell flex flex-y-center">
					<view class="title-block">
						<text>有效期</text>
					</view>
					<view class="desc">
						<view class="input-box">{{info.start_time}} - {{info.end_time}}</view>
					</view>

				</view>
				
			</view>
		</view>
		<view class="page-block" v-if="info.type == 2">
			<view class="page-title-block">
				<view class="title">指定商品</view>
			</view>
			<view class="content">
				<view class="cell flex flex-y-center goods-item">
					<image src="../static/images/avatar_def.png" mode="aspectFill" class="goods-img"></image>
					<view class="goods-info">
						<view class="name text-1">巨无霸汉堡</view>
						<view class="stock text-1">库存:100</view>
						<view class="price text-1">￥100.00</view>
					</view>
				</view>
				<view class="cell flex flex-y-center goods-item">
					<image src="../static/images/avatar_def.png" mode="aspectFill" class="goods-img"></image>
					<view class="goods-info">
						<view class="name text-1">巨无霸汉堡</view>
						<view class="stock text-1">库存:100</view>
						<view class="price text-1">￥100.00</view>
					</view>
				</view>
			</view>
		</view>
		<view style="height:30rpx;"></view>
		<view class="footer-bar" style="height: 100rpx;">
			<view class="content flex flex-center" style="height: 100rpx;">
				<view class="detail-btn flex flex-center" style="border-right: 2rpx solid #F4F5F7;" @click="onDel">
					<image src="../static/images/icon_16.png" mode="aspectFit" class="btn-icon"></image>
					<view style="color:#999999">删除优惠券</view>
				</view>
				<view class="detail-btn flex flex-center" @click="toEdit">
					<image src="../static/images/icon_17.png" mode="aspectFit" class="btn-icon"></image>
					<view style="color:#3387FF">重新编辑</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				id:"",
				info:{}
			}
		},
		onLoad(options) {
			this.id = options.id
			this.getData()
		},
		methods: {
			getData(){
				this.request({
					url:"Smdcshop/coupon_info",
					data:{
						id:this.id
					}
				}).then(res=>{
					if(res.code == 200){
						this.info = res.data
					}
				}).catch(err=>{
					console.log('err:',err)
				})
			},
			toEdit(){
				uni.redirectTo({
					url:`/saomaDiancan/editCoupon/editCoupon?id=${this.info.id}`
				})
			},
			onDel(){
				uni.showModal({
					content:"确定删除该优惠券",
					success: (r) => {
						if(r.confirm){
							this.request({
								url:"Smdcshop/coupon_delect",
								data:{
									id:this.info.id
								}
							}).then(res=>{
								if(res.code == 200){
									let pages = getCurrentPages();
									let prevPage = pages[pages.length - 2];
									//
									// #ifdef H5
									prevPage.getData(1)
									// #endif
									// #ifndef H5
									prevPage.$vm.getData(1)
									// #endif
									uni.navigateBack()
								}
							})
						}
					}
				})
			}
		}
	}
</script>

<style>
	@import url("../static/css/common.css");

	page {
		background: #F4F5F7;
	}
	.goods-item{
		padding:25rpx 0;
	}
	.goods-item .goods-img{
		display: block;
		width: 120rpx;
		height: 120rpx;
		border-radius: 8rpx;
		
	}
	.goods-item .goods-info{
		padding-left: 25rpx;
	}
	.goods-item .goods-info .name{
		font-size: 30rpx;
		font-weight: 600;
		color: #333;
		line-height: 1;
	}
	.goods-item .goods-info .stock{
		font-size: 24rpx;
		color: #999;
		margin-top: 16rpx;
		line-height: 1;
	}
	.goods-item .goods-info .price{
		font-size: 30rpx;
		color: #FD3939;
		margin-top: 20rpx;
		font-weight: 600;
		line-height: 1;
	}
	
	
</style>
