<template>
	<view>
		<slot name="top"></slot>
		<VueSignaturePad width="100%" height="600rpx" ref="signaturePad" :options="options" disable-scroll="true" class="my-canvas-cls" />
		<slot name="footer"></slot>
		<view class="footer" v-if="footerShow">
			<u-button type="success" @click.stop="finish" size="mini">保存</u-button>
			<u-button type="warning" @click.stop="clear" size="mini">清除</u-button>
			<u-button type="error" @click.stop="close" size="mini">关闭</u-button>
			<!-- <view class="left" @click.stop="finish">保存</view> -->
			<!-- <view class="right" @click="clear">清除</view> -->
			<!-- <view class="close" @click="close">关闭</view> -->
		</view>
	</view>
</template>
<script>
	export default {
		data() {
			return {
				//绘图图像
				ctx: '',
				//路径点集合
				points: [],
				//签名图片
				SignatureImg: '',
				options: {
					penColor: "#000",
					minWidth: 1, //控制画笔最小宽度
					maxWidth: 1, //控制画笔最大宽度
				},
			};
		},
		props: {
			footerShow: {
				type: Boolean,
				default: true
			}
		},
		watch: {},
		methods: {
			clear() {
				this.$refs.signaturePad.clearSignature();
				this.$emit("clear", '')

			},
			finish() {
				const {
					data
				} = this.$refs.signaturePad.saveSignature()
				this.$emit("save", data)
			},
			close() {
				this.$emit("close")
			}
		}
	};
</script>
<style lang="less" scoped>
	.bigbox {
		touch-action: none
	}

	.my-canvas-cls {
		height: 500rpx;
		width: 100%;
		display: block;
		position: relative;
		background: #F6F6F6;
		z-index: 9999;
		border-radius: 8rpx;
	}

	.footer {
		font-size: 14px;
		height: 150upx;
		display: flex;
		justify-content: space-around;
		align-items: center;
		padding-left: 40rpx;

		.left {
			background-color: #ecf5ff;
			color: #a0cfff;
			border-radius: 8rpx;
			padding: 10rpx 15rpx;
			border: 1px solid #a0cfff;
		}

		.right {
			background-color: #fdf6ec;
			color: #fcbd71;
			border-radius: 8rpx;
			padding: 10rpx 15rpx;
			border: 1px solid #fcbd71;
		}

		.close {
			background-color: #fef0f0;
			color: #fab6b6;
			border-radius: 8rpx;
			padding: 10rpx 15rpx;
			border: 1px solid #fab6b6;
		}
	}

	.but-class {
		margin-right: 40rpx;
	}
</style>