<template>
	<view class="body">
		<image :src="form.thumbnail" mode=""></image>
		<view class="title">
			<view class="a">
				{{form.collectionName}}
				<text class="b">#{{form.numberSales}}</text>
			</view>
			<view class="c">
				<image v-if="!form.whetherCollection" class="collect" src="../../static/365.png" @click="collect(form.id)" mode=""></image>
				<image v-if="form.whetherCollection" class="collect" src="../../static/277.png" @click="uncollect(form.id)" mode=""></image>
				<image v-if="!form.whetherLike" @click="like(form.id)" src="../../static/heat.png" mode=""></image>
				<image v-if="form.whetherLike" @click="unlike(form.id)" src="../../static/278.png" mode=""></image>
			</view>
			
		</view>
		<view class="name-content" @click="artist(form.artistId)">
			<image :src="form.writerAvatar" mode=""></image>
			<view class="name">
				{{form.artistName}}
			</view>
		</view>
		<view class="price">
			<view class="name">
				販売価額
			</view>
			<view class="value">
				￥{{form.price}}
			</view>
		</view>
		<view class="title-two">
			ブロックチェーン情報
		</view>
		<view class="title-three">
			<view class="">
				コントラクトアドレス
			</view>
			<view class="three-content">
				<view class="">
					{{form.contractAddress}}
				</view>
				<image src="../../static/342.png" mode=""></image>
			</view>
		</view>
		<view class="title-three">
			<view class="">
				コレクション名
			</view>
			<view class="three-content">
				<view class="">
					{{form.seriesName}}
				</view>
			</view>
		</view>
		<view class="title-three">
			<view class="">
				ブロックチェーン
			</view>
			<view class="three-content">
				<view class="">
					{{form.numberRemaining}}
				</view>
			</view>
		</view>
		<button class="btn" type="default">購入</button>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				form: {}
			}
		},
		onLoad(option) {
			if (option.id) {
				this.id = option.id
				this.worksShow(option.id);
			}
		},
		methods: {
			//作品展示
			async worksShow(id) {
				const res = await this.$myRequest({
					url: '/api/foreignAuth/worksShow?id=' + id,
					header: {
						token: uni.getStorageSync("token"),
						Authorization: uni.getStorageSync("Authorization"),
					},
				})
				if (res.data.code == 200) {
					this.form = res.data.data
				}
			},
			//收藏
			async collect(id) {
				const res = await this.$myRequest({
					url: '/api/foreignAuth/star?id=' + id,
					header: {
						token: uni.getStorageSync("token"),
						Authorization: uni.getStorageSync("Authorization"),
					},
				})
				if (res.data.code == 200) {
					uni.showToast({
						title: "收藏成功"
					})
					this.worksShow(this.id);
				}
			},
			//取消收藏
			async uncollect(id) {
				const res = await this.$myRequest({
					url: '/api/foreignAuth/cancel?id=' + id,
					header: {
						token: uni.getStorageSync("token"),
						Authorization: uni.getStorageSync("Authorization"),
					},
				})
				if (res.data.code == 200) {
					uni.showToast({
						title: "取消收藏成功"
					})
					this.worksShow(this.id);
				}
			},
			//点赞
			async like(id) {
				const res = await this.$myRequest({
					url: '/api/foreignAuth/giveLike?id=' + id,
					header: {
						token: uni.getStorageSync("token"),
						Authorization: uni.getStorageSync("Authorization"),
					},
				})
				if (res.data.code == 200) {
					uni.showToast({
						title:"点赞成功"
					})
					this.worksShow(this.id);
				}
			},
			//取消点赞
			async unlike(id) {
				const res = await this.$myRequest({
					url: '/api/foreignAuth/donPraise?id=' + id,
					header: {
						token: uni.getStorageSync("token"),
						Authorization: uni.getStorageSync("Authorization"),
					},
				})
				if (res.data.code == 200) {
					uni.showToast({
						title: "取消点赞成功"
					})
					this.worksShow(this.id);
				}
			},
			//跳转作者详情页
			artist(id) {
				uni.navigateTo({
					url: "./details?id=" + id
				})
			}
		}
	}
</script>

<style lang="scss">
	.body {
		padding-top: 0rpx;
		display: flex;
		min-height: 95vh;
		flex-direction: column;
		background-color: #000000;
		// min-height: 1340rpx;
		font-family: Arial-Regular;
		align-items: center;
		color: #FFFFFF;

		image {
			width: 678rpx;
			height: 678rpx;
			border-radius:44rpx;
		}

		.title {
			display: flex;
			justify-content: space-between;
			width: 678rpx;
			font-size: 36rpx;
			margin-top: 60rpx;
			.a {
				.b {
					margin-left: 24rpx;
				}
			}
			image {
				width: 48rpx;
				height: 48rpx;
				margin-right: 24rpx;
			}
		}

		.name-content {
			width: 678rpx;
			display: flex;
			font-size: 28rpx;
			align-items: center;
			margin-top: 32rpx;

			image {
				margin-right: 24rpx;
				width: 64rpx;
				height: 64rpx;
				border-radius:32rpx;
			}
		}

		.price {
			width: 678rpx;
			display: flex;
			font-size: 28rpx;
			align-items: center;
			margin-top: 32rpx;
			border-bottom: 1rpx solid #545454;
			padding-bottom: 60rpx;

			.name {
				margin-right: 40rpx;
			}

			.value {
				font-weight: bold;
			}
		}

		.title-two {
			display: flex;
			justify-content: space-between;
			width: 678rpx;
			font-size: 32rpx;
			margin-top: 60rpx;
		}

		.title-three {
			font-size: 28rpx;
			display: flex;
			justify-content: space-between;
			width: 678rpx;
			margin-top: 36rpx;

			.three-content {
				display: flex;
				width: 337rpx;

				image {
					margin-left: 18rpx;
					width: 32rpx;
					height: 32rpx;
				}
			}
		}

		.btn {
			position: fixed;
			bottom: 50upx;
			left: 50%;
			transform: translate(-50%);
			background-color: #E84779;
			color: #FFFFFF;
			width: 582rpx;
			height: 80rpx;
			border-radius: 40rpx;
			font-size: 28rpx;
			margin-top: 130rpx;
		}
	}
</style>
