<script setup lang="ts">
import XSignature from '@af-mobile-client-vue3/components/data/XSignature/index.vue'
import NormalDataLayout from '@af-mobile-client-vue3/components/layout/NormalDataLayout/index.vue'
import { showToast, Image as VanImage } from 'vant'
import { ref } from 'vue'

const signatureImage = ref('')

function handleSave() {
  showToast('签名已保存')
}

function handleClear() {
  showToast('签名已清除')
}
</script>

<template>
  <NormalDataLayout title="签名组件">
    <template #layout_content>
      基础使用
      <div class="signature-demo">
        <XSignature v-model="signatureImage" @save="handleSave" @clear="handleClear" />
        <div v-if="signatureImage" class="preview">
          <h3>预览签名</h3>
          <VanImage v-if="signatureImage" :src="signatureImage" />
        </div>
      </div>
    </template>
  </NormalDataLayout>
</template>

<style scoped lang="less">
.signature-demo {
  padding: 16px;
  .preview {
    margin-top: 20px;
    h3 {
      margin: 0 0 10px;
      font-size: 16px;
      color: #323233;
    }
    img {
      max-width: 100%;
      border: 1px solid #ebedf0;
      border-radius: 8px;
    }
  }
}
</style>
