<template>
	<view class="park" :style="{backgroundImage:`url(${indexBackgroundImage})`}">
		<view class="park-navbar">
			<u-navbar title="" :border-bottom="false" :background="background"></u-navbar>
		</view>
		<view style="margin-top:714rpx;overflow: hidden;height: 800rpx;">
			<view class="report" v-if="list.length>0">
				<view class="report-content" v-for="(a,index) in list">
					<view class="report-box report-box1">
						{{a.channel_name}}
					</view>
					<view class="report-box" @click="onClickReport(a,1)">
						预览
					</view>
					<view class="report-box" @click="onClickReport(a,2)">
						复制
					</view>
				</view>
			</view>
		</view>
	</view>
	<!-- 催单弹框 -->
	<view class="dia" v-if="cdDia" @touchmove.stop.prevent="">
		<view class="diaMain">
			<view class="ld" @click="cdDia=false">
				<u-icon name="close" color="#999" size="32"></u-icon>
			</view>
			<view class="report-name">今天 {{today}}，{{fromData.header_content}}</view>
			<!-- <view class="cdInfo"> -->
			<scroll-view class="cdInfo" scroll-y="true">
				<view class="report-line" v-for="(item) in shortList">
					<view class="" v-if="item.goods_name">
						{{'★'+item.goods_name}}
					</view>
					<view class="" v-if="item.goods_price_min">
						市场价:{{item.goods_price_min}}
					</view>
					<view class="" v-if="item.membership_price">
						推广价:{{item.membership_price}}
					</view>
					<view class="" v-if="item.goods_no">
						SKU:{{item.goods_no}}
					</view>
					<view class="" v-if="item.jd_short_url">
						{{item.jd_short_url}}
					</view>
					<view class="" v-if="item.applet_short_url">
						👉抢购链接：<text style="color:blue">{{item.applet_short_url}}</text>
					</view>
				</view>
			</scroll-view>
			<view class="report-name" v-if="fromData.tail">{{fromData.tail}}</view>
			<!-- </view> -->
		</view>
	</view>
</template>

<script>
	import * as help from '@/api/help'
	export default {
		data() {
			return {
				background: {
					background: 'none'
				},
				cdDia: false,
				list: [],
				shortList: [],
				today: '',
				fromData: '',
				indexBackgroundImage: 'https://www.amiami.com.cn/static/openshop.png?t=' + new Date().getTime(),
			}
		},
		onLoad() {
			this.getTipOffList()
		},
		methods: {
			getCurrentDate() {
				let now = new Date()
				let year = now.getFullYear()
				let month = now.getMonth() + 1
				let day = now.getDate()
				this.today = year + '年' + month + '月' + day + '日'
			},
			onClickReport(item, type) {
				this.fromData = item
				uni.showLoading({
					title: type == 1 ? '加载中' : '复制中'
				});
				this.getJDShortLinks(item.id, type)
				this.getCurrentDate()
			},
			getJDShortLinks(id, type) {
				help.JDShortLinks({
					id: id
				}).then(result => {
					if (result.status == 200) {
						this.shortList = result.data.goodsList
						if (type == 1) {
							this.cdDia = true
						}
						if (type == 2) {
							this.copyData()
						}
						uni.hideLoading();
					}
				})
			},
			copyData() {
				let that = this
				let text = ''
				that.shortList.forEach(function(obj) {
					text +=
						text +=
						'★' +
				  obj.goods_name +
						'\n' +
						'市场价:' +
						obj.goods_price_min +
						'\n' +
						'推广价:' +
						obj.membership_price +
						'\n' +
						(obj.goods_no ? 'SKU:' + obj.goods_no + '\n' : '') +
						(obj.jd_short_url ? obj.jd_short_url + '\n' : '') +
						(obj.applet_short_url ? '👉抢购链接：' + obj.applet_short_url + '\n' : '') +
						' \n'
				})
				console.log('今天' + that.today + '，' + this.fromData.header_content + '\n' + ' \n' + text + '\n' +
						this.fromData.tail)
				uni.setClipboardData({
					data: '今天' + that.today + '，' + this.fromData.header_content + '\n' + ' \n' + text  +
						this.fromData.tail,
					success: () => {
						// 可以添加用户友好的提示，例如使用uni.showToast提示复制成功
						uni.showToast({
							title: '复制成功',
							icon: 'none'
						});
					},
					fail: () => {
						uni.showToast({
							title: '复制成功',
							icon: 'none'
						});
					}
				});
			},
			getTipOffList() {
				help.tipOffList().then(result => {
					if (result.status == 200) {
						this.list = result.data.list.data
					}
				})
			}
		}
	}
</script>

<style>
	page {
		background: #fff;
		width: 100%;
	}
</style>
<style lang="scss" scoped>
	.dia {
		position: fixed;
		top: 0;
		left: 0;
		width: 100%;
		height: 100%;
		background: rgba(0, 0, 0, 0.7);
		z-index: 99;
		display: flex;
		align-items: center;
		justify-content: center;

		.report-name {
			font-size: 28rpx;
			color: #000;
			font-weight: 700;
			margin: 40rpx 0 16rpx 0;
		}

		.report-line {
			font-size: 28rpx;
			color: #000;
			padding-top: 16rpx;
			margin-top: 16rpx;
			// border-top: 1rpx dashed #999;
		}

		.report-line:nth-child(1) {
			border-top: none !important;
			margin-top: 0 !important;
			padding-top: 0 !important;
		}

		.diaMain {
			width: 680rpx;
			min-height: 500rpx;
			background: #fff;
			border-radius: 12rpx 12rpx 12rpx 12rpx;
			opacity: 1;
			position: relative;
			padding: 24rpx;
			overflow: hidden;

			.ld {
				width: 40rpx;
				height: 40rpx;
				position: absolute;
				top: 24rpx;
				right: 24rpx;
			}

			.cdInfo {
				height: 1000rpx;
				font-size: 28rpx;
				font-family: PingFang SC, PingFang SC;
				font-weight: 400;
				color: #727272;
				line-height: 38rpx;
				margin-top: 20rpx;
			}
		}
	}

	.park {
		width: 100%;
		background-size: 100% auto;
		height: 1720rpx;
		background-size: cover;

		.report {
			box-shadow: 0 5rpx 10rpx 5rpx #fff;
			border-radius: 8rpx;
			margin: 20rpx 50rpx 0rpx 50rpx;
			padding: 12rpx;
			max-height: 570rpx;
			overflow-y: auto;

			.report-content {
				overflow: hidden;
				display: flex;
				justify-content: center;

				.report-box {
					display: inline-block;
					background: #3d84f2;
					height: 60rpx;
					text-align: center;
					width: 120rpx;
					padding: 0 24rpx;
					color: #fff;
					font-family: PingFang SC, PingFang SC;
					font-weight: 400;
					font-size: 26rpx;
					color: #fff;
					line-height: 60rpx;
					border-radius: 16rpx;
					margin: 12rpx 18rpx;
				}

				.report-box1 {
					width: 200rpx;
					max-width: 200rpx;
					display: -webkit-box;
					-webkit-box-orient: vertical;
					overflow: hidden;
					-webkit-line-clamp: 1;
					border-radius: 32rpx !important;
				}
			}
		}

		.wenan {
			font-size: 54rpx;
			color: #000;
			font-family: PingFang SC, PingFang SC;
			font-weight: 800;
			margin: 30rpx 100rpx 60rpx 100rpx;
			text-align: center;
		}
	}
</style>
