<template>
	<view class="seal-list">
		<view class="seal-item" v-for="(item,index) in sealData" :key="item.id" @click="requestSeal(item)">
			<image class="seal-image" :src="item.fileNode.node.url" mode="aspectFit"></image>
			<view class="content">
				<view class="title">
					{{item.name}}
				</view>
				<view class="article">
					{{item.comment}}
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		getSealList,
		requestSeal
	} from '@/request/api/organization.js'
	import {
		insertDocumentData
	} from '@/request/api/contract.js'
	export default {
		data() {
			return {
				sealData: [],
				userInfo: {},
				body: {}
			}
		},
		onLoad(body) {
			this.body = body;
			this.userInfo = this.$store.getters.user;
			console.log(this.userInfo);
			getSealList(this.$store.getters.organization.id).then(res => {
				if (res.code === 200) {
					this.sealData = res.data;
					console.log(this.sealData);
				}
			})
		},
		onShow() {

		},
		methods: {
			requestSeal(item) {
				uni.showModal({
					title: '有极提示',
					content: '确实使用该印章？',
					success: res => {
						if (res.confirm) {
							uni.showLoading();
							requestSeal({
								sealId: item.id,
								requestUserName: this.userInfo.userName,
								requestUserId: this.userInfo.userId,
								documentId: this.body.documentId,
								keyWord: this.body.sealDomId,
								projectId: this.$store.getters.project.id
							}).then(data => {
								if (data.code === 200) {
									let seal = {};
									seal[this.body.sealDomId] = this.body.sealDomId;
									insertDocumentData({
										data: JSON.stringify({
											seal: seal
										}),
										documentId: this.body.documentId,
										userId: this.userInfo.userId
									}).then(res => {
										if (res.code === 200) {
											this.$toast('申请成功');
											uni.$emit('reloadElement');
											setTimeout(() => {
												uni.hideLoading();
												this.$navigateBack();
											}, 400)
										} else {
											uni.hideLoading();
										}
									})
								} else {
									uni.hideLoading();
								}
							});
						}
					}
				});
			}
		}
	}
</script>

<style lang="scss">
	.seal-list {
		padding: 30rpx;

		.seal-item {
			height: 140rpx;
			background-color: #ffffff;
			border-radius: 16rpx;
			box-shadow: 0px 1px 12px rgba(3, 3, 3, 0.08);
			display: flex;
			align-items: center;
			padding: 0 30rpx;
			margin-bottom: 20rpx;
		}

		.seal-image {
			width: 100rpx;
			height: 100rpx;
		}

		.content {
			flex: 1;
			width: 0;
			margin-left: 20rpx;
		}

		.title {
			font-weight: 500;
			font-size: 32rpx;
		}

		.article {
			color: $uni-secondary-color;
			margin-top: 10rpx;
		}
	}
</style>