<template>
	<view>
		<view class="width100 fotct coupon-status font20 fcorred" v-if="couponDesInfo.couponAgentCode.status == 2">待使用
		</view>
		<view class="width100 fotct coupon-status font20 fcor41c" v-if="couponDesInfo.couponAgentCode.status == 1">待销售
		</view>
		<view class="width100 fotct coupon-status font20 fcor41c" v-if="couponDesInfo.couponAgentCode.status  == 3">已使用
		</view>
		<view class="line1"></view>
		<view class="width90" style="min-height: 60px;">
			<view class="flright fotct">
				<image class="coupon-img" :src="imageUrl+couponDesInfo.couponInfo.couponImg"></image>
			</view>
			<view class="coupon-mes mart10">
				<view class="fcor333 fontwig6 font24 width100 text2">{{couponDesInfo.couponInfo.couponName}}</view>
				<view class="fcor666  font13 width100 mart5" v-if="oneTime">
					出售时间:{{oneTime | formatDate('-')}}</view>
				<view class="fcor666  font13 width100 mart5" v-if="twoTime">
					使用有效期:{{twoTime | formatDate('-')}}</view>
				<view class="fcorred  font15 width100 mart5" v-if="threeTime">
					消费时间:{{threeTime | formatDate('-')}}</view>
			</view>
		</view>
		<view class="width90 mart5 font13 fcor666" v-if="couponDesInfo.couponAgentCode.convertUserPhone != null ">
			客户电话:{{couponDesInfo.couponAgentCode.convertUserPhone}}</view>
		<view class="width90 mart5 font13 fcor666" v-if="couponDesInfo.couponAgentCode.remark != null ">
			备注:{{couponDesInfo.couponAgentCode.remark}}</view>

		<view class="width100" v-if="couponDesInfo.couponInfo.couponSource != 4">
			<view class="width90 mart5 font13 fcor666" v-if="couponDesInfo.couponCode != null">
				加油站点:{{couponDesInfo.couponCode.storeName}}</view>
			<view class="line1 mart15"></view>
			<view class="width100" v-if="couponDesInfo.couponAgentCode.type == 1">
				<view class="width90 mart10 fcor666">核销码(商户扫客户)</view>
				<view class="mart20 fotct fcorred font15 marb20">
					请告知加油员用码商支付</view>
				<view class="width90 mart20 fotct">
					<image class="coupon-qr" :src="imageUrl+'couponCode/'+couponDesInfo.couponCode.ext1"></image>
				</view>
			</view>
			<view class="width90"
				v-if="couponDesInfo.couponAgentCode.status !=3 && couponDesInfo.couponAgentCode.type != 1 && couponDesInfo.couponInfo.couponSource != 5">
				<view class="width90 mart10 fcor666">点击下方复制按钮,复制兑换码发送用户</view>
				<view class="mart30 fotct font18 marb20 fcor666">{{couponDesInfo.couponAgentCode.convertCode}}</view>
				<view class="btn90w mart40" @click="copycont(couponDesInfo.couponAgentCode.convertCode)">复制兑换码</view>
			</view>
			
			<view class="width90"
				v-if="couponDesInfo.couponInfo.couponSource == 5">
				<view class="width90 mart10 fcor666">点击下方复制按钮,复制链接发送用户微信</view>
				<view class="mart30 fotct font14 marb20 fcor666">#小程序://中油好客e站/YCjV6saueaTanhF</view>
				<view class="btn90w mart40" @click="copycontmini">复制链接</view>
			</view>
		</view>
		<!-- <view class="width90" v-if="couponDesInfo.couponCode.status ==3 && couponDesInfo.couponAgentCode.type != 1">
			<view class="mart20 fotct fcorred font15 marb20">
				请告知加油员用码商支付</view>
			<view class="width90 mart20 fotct">
				<image class="coupon-qr" :src="imageUrl+'couponCode/'+couponDesInfo.couponCode.ext1"></image>
			</view>
			<view class="mart30 fotct font18 marb20 fcor666">{{couponDesInfo.couponAgentCode.convertCode}}</view>
		</view> -->
		<view class="height60"></view>
	</view>
</template>

<script>
	import {
		getCodeById
	} from "../../../Utils/Api.js";
	let app = getApp()
	export default {
		data() {
			return {
				couDesId: '',
				imageUrl: app.globalData.imgUrl,
				couponDesInfo: [],
				storeList: [],
				oneTime: '',
				twoTime: '',
				threeTime: '',
				menddesId: ''
			}
		},
		onLoad(option) {
			this.couDesId = option.id;
			this.getCodeById();
		},
		onUnload() {
			let pages = getCurrentPages() //页面栈
			let prePage = pages[pages.length - 2] //上一页
			prePage.$vm.reFreshs = Math.random()
		},
		filters: {
			//过滤器 用于格式化时间
			formatDate: function(value, spe = '/') {
				let data = new Date(value);
				let year = data.getFullYear();
				let month = data.getMonth() + 1;
				let day = data.getDate();
				let h = data.getHours();
				let mm = data.getMinutes();
				let s = data.getSeconds();
				month = month >= 10 ? month : "0" + month;
				day = day >= 10 ? day : "0" + day;
				h = h >= 10 ? h : "0" + h;
				mm = mm >= 10 ? mm : "0" + mm;
				s = s >= 10 ? s : "0" + s;
				return `${year}${spe}${month}${spe}${day} ${h}:${mm}:${s}`;
			}
		},

		methods: {
			//我的卡券详情
			getCodeById() {
				uni.showLoading({
					title: '加载中...'
				})
				let params = {
					couponAgentCodeId: this.couDesId
				}
				getCodeById(params).then(res => {
					uni.hideLoading()
					if (res.return_code == '000000') {
						this.couponDesInfo = res.return_data;
						if (res.return_data.couponInfo.couponSource != 4 && res.return_data.couponInfo
							.couponSource != 5) {
							if (res.return_data.couponCode != null) {
								this.oneTime = res.return_data.couponCode.receiveTime;
								this.twoTime = res.return_data.couponCode.useEndTime;
								this.threeTime = res.return_data.couponCode.consumeTime;
							}
							return;
						}
						this.oneTime = res.return_data.couponCodeOther.activeTime;
						this.twoTime = res.return_data.couponCodeOther.validEndDate;
					}
				})
			},
			//导航
			seeloaction(e) {
				uni.openLocation({
					latitude: Number(e.latitude), //目的地的定位
					longitude: Number(e.longitude), //目的地的定位
					name: e.storeName,
					address: e.address
				})
			},

			/**
			 * 查询门店列表
			 */
			// getStoreListByCoupon() {
			// 	uni.showLoading({
			// 		title: '加载中...'
			// 	})

			// 	let params = {
			// 		couponId: this.menddesId,
			// 		longitude: app.globalData.longitude,
			// 		latitude: app.globalData.latitude
			// 	}
			// 	getStoreListByCoupon(params).then(res => {
			// 		if (res.return_code == '000000' && res.return_data.list != '') {
			// 			uni.hideLoading();
			// 			this.storeList = res.return_data;
			// 		} else {
			// 			this.storeList = [];
			// 			uni.hideLoading()
			// 		}
			// 	})
			// },
			//复制内容
			copycont(item) {
				uni.setClipboardData({
					data: item,
					success: function() {

					}
				})
			},
			//复制链接
			copycontmini() {
				uni.setClipboardData({
					data: '#小程序://中油好客e站/YCjV6saueaTanhF',
					success: function() {
			
					}
				})
			}
		}
	}
</script>

<style lang="scss">
	.loading-text {
		width: 100%;
		display: flex;
		justify-content: center;
		align-items: center;
		height: 60upx;
		color: #979797;
		font-size: 24upx;
	}

	.coupon-status {
		height: 35px;
		line-height: 35px;
	}

	.coupon-mes {
		margin-right: 90px;
	}

	.coupon-img {
		width: 80px;
		height: 80px;
	}

	.coupon-qr {
		width: 250px;
		height: 250px;
	}

	.coupon-des {
		width: 80px;
		height: 80px;
		text-align: center;
		color: white;
		font-size: 28px;
		border-radius: 10px;
		background-color: red;
	}

	.coupon-cont-dh {
		margin-left: 90px;
	}

	.coupon-map image {
		width: 45px;
		height: 45px;
	}

	.coupon-no {
		height: 80px;
		line-height: 80px;
		border: 1px solid #b2b2b2;
		border-radius: 10px;
	}

	.coupne-btn {
		position: fixed;
		bottom: 0px;
		background-color: red;
		color: #FFFFFF;
		border-radius: 0px;
	}

	.czlq {
		position: absolute;
		bottom: 0;
		background-color: red;
		color: #FFFFFF;
	}

	.btn90w {
		background-color: #089bf5;
		height: 90rpx;
		line-height: 90rpx;
		color: #FFFFFF;
		font-size: 15px;
		text-align: center;
	}
</style>
