<template>
	<view>
		<cshaptx4869-scancode
		  v-if="h5ScanCode"
		  @success="handleSuccess"
		  @fail="handleFail"
		  @close="handleClose"
		></cshaptx4869-scancode>
	</view>
</template>

<script setup lang="ts">
import { showConfirmDialog } from 'vant';
import { onMounted, ref } from 'vue';

onMounted(()=>{
	scanCode()
})
	const h5ScanCode = ref(false);
	function scanCode() {
	  // #ifdef H5
	  h5ScanCode.value = true;
	  // #endif
	  // #ifndef H5
	  uni.scanCode({
	    success: (res) => {
	      uni.showToast({
	        icon: "none",
	        title: res.result,
	      });
		  
		  // TODO
	    },
	    faile: (err) => {
	      console.log("err", err);
	    },
	  });
	  // #endif
	}
	function handleSuccess(res) {
	  h5ScanCode.value = false;
	  uni.showToast({
	    icon: "none",
	    title: res,
	  });
	  // TODO
	  showConfirmDialog({
	    title: '标题',
	    message:
	      '如果解决方法是丑陋的，那就肯定还有更好的解决方法，只是还没有发现而已。',
	  })
	    .then(() => {
	      // on confirm
	    })
	    .catch(() => {
	      // on cancel
	    });
	}
	function handleFail(err) {
	  uni.showModal({
	    title: err.errName,
	    content: err.errMsg,
	    complete: () => {
	      h5ScanCode.value = false;
	    },
	  });
	  // TODO
	  
	}
	function handleClose() {
	  h5ScanCode.value = false;
	}
	
</script>

<style lang="scss" scoped>
	       
</style>
