	
<template>
	<view class="signContainer">
		<view style="width:100%;height: calc(100vh - 100rpx);">
		    <l-signature disableScroll 
			backgroundColor="#ddd" 
			ref="signatureRef" 
			:penColor="penColor" 
			:penSize="penSize" 
			:landscape="true"
			:openSmooth="openSmooth" ></l-signature>
		</view>
		<view class="btnGroup">
		    <button @click="toolHandle('clear')">清空</button>
		    <button @click="toolHandle('undo')">撤消</button>
		    <button @click="toolHandle('save')">保存</button>
		    <!-- <button @click="toolHandle('openSmooth')">压感{{openSmooth?'开':'关'}}</button> -->
		</view>
	</view>
</template>

<script>
	import {getToken} from '@/common/auth.js'
export default{
	data(){
		return{
			penColor:'#000000',
			penSize:2,
			openSmooth:true,
			url:''
			
		}
	},
	methods:{
		//签名
		toolHandle(type) {
			 if(type == 'openSmooth') {
				 this.openSmooth = !this.openSmooth
				 return
			 }
			if (type == 'save') {
				this.$refs.signatureRef.canvasToTempFilePath({
					success: (res) => {
						console.log(res,"ooooooo")
						// 是否为空画板 无签名
						console.log(res.isEmpty)
						// 生成图片的临时路径
						// H5 生成的是base64
						let url = res.tempFilePath;
						uni.uploadFile({
							url: this.baseUrl+'/api/common/upload', // 仅为示例，非真实的接口地址
							filePath: url,
							name: 'file',
							formData: {
								user: 'test',
								token:getToken()
							},
							success: (res) => {
								console.log(res,"iiiiiii");
								uni.reLaunch({
									url:'/pages/index/sign?url='+res.data.fullurl+'&isSign='+true
								})
							},
							fail: (res) => {
								console.log(res,"rrr")
							}
						});
					}
				})
				return
			}
			if (this.$refs.signatureRef)
				this.$refs.signatureRef[type]()
		}
	}
}
</script>

<style lang="scss" scoped>
.btnGroup{
	display: flex;
	height: 100rpx;
}
</style>