123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159 |
- <template>
- <view class="choice-takePhoto-wrap" v-if="prop.isTakePhotoModeShow" @click="cancle">
- <view class="choice-takePhoto">
- <view @click.stop="takePhoto(prop.phoneType)" style="border-radius: 20rpx 20rpx 0 0;">拍照</view>
- <view @click.stop="xiangce(prop.phoneType)">从手机相册选择</view>
- <view @click.stop="cancle">取消</view>
- </view>
- </view>
-
- <viewfinder v-if="state.phoneType" :phoneType="state.phoneType" :images="state.images" :showStartPhoto="state.showImg"
- @confirmReturn="confirmReturn" @camera="camera"></viewfinder>
- </template>
-
- <script setup lang="ts">
- import {
- reactive,
- ref,
- onMounted
- } from "vue";
- import viewfinder from "./viewfinder.vue"
- import { idCardOcr,vehicleLicenseOcr} from "@/utils/network/api.js";
- import {
- uploadFile,
- compressImage,
- chooseImageCompress,
- compareDates
- } from "@/utils/utils";
-
- let prop = defineProps({
- phoneType: {
- type: Number,
- default: function () {
- return 0 //1 身份证正面 2 身份证反面 3 行驶证正面 4 行驶证反面
- }
- },
- isTakePhotoModeShow: {
- type: Boolean,
- default: function () {
- return false
- }
- },
- });
- const emit = defineEmits<{
- (e : "close", content : any) : void;
- (e : "ocrResult", content : any) : void;
- }>();
- const state = reactive({
- showImg: true,
- phoneType: 0, // 1 身份证正面 2 身份证反面 3行驶证正面 4行驶证反面
- choiceIndex: 1, // 1 身份证正面 2 身份证反面
- isTakePhotoModeShow:false, //选择拍照方式是否出来
- images: '',
- })
- const xiangce = (val) => {
- console.log("val", val)
- var imageType=""
- state.choiceIndex=val
- if(state.choiceIndex == 1 || state.choiceIndex == 2){
- imageType = val;
- }else{
- if (state.choiceIndex == 3) {
- imageType = '1';
- } else {
- imageType = '2';
- }
- }
-
- chooseImageCompress((res) => {
- console.log("res",res,state.choiceIndex)
- state.images = res.tempFilePath ? res.tempFilePath : res.tempFilePaths[0]
- state.showImg = false
- emit('close', false)
- if(state.choiceIndex==1 || state.choiceIndex==2){
- var issfz=idCardOcr
- }else{
- var issfz=vehicleLicenseOcr
- }
- uploadFile(state.images, imageType, issfz).then((data) => {
- console.log("身份证上传", data)
- emit('ocrResult', data)
- })
- })
- }
- const takePhoto = (val) => {
- state.showImg = true
- console.log("拍照", val)
- state.phoneType = val;
- state.choiceIndex=val
- }
- const confirmReturn = (val) => {
- console.log("图片地址val", val)
- state.phoneType = 0
- if(state.choiceIndex==1 || state.choiceIndex==2){
- var imageType = state.choiceIndex;
- var issfz=idCardOcr
- }else{
- if (state.choiceIndex == 3) {
- var imageType = 1;
- } else {
- var imageType = 2;
- }
- var issfz=vehicleLicenseOcr
- }
- uploadFile(val.tempImagePath, imageType, issfz).then((data) => {
- console.log("身份证上传", data)
- emit('close', false)
- emit('ocrResult', data)
- })
- }
- const cancle = () => {
- emit('close', false)
- }
- const camera = () => {
- state.phoneType = 0
- }
- </script>
-
- <style scoped>
- .choice-takePhoto {
- position: absolute;
- bottom: 0;
- background-color: white;
- width: 100%;
- border-radius: 20rpx 20rpx 0 0;
- }
-
- .choice-takePhoto>view:first-child {
- text-align: center;
- height: 80rpx;
- line-height: 80rpx;
- border-bottom: 1rpx solid rgba(127, 127, 127, 0.3);
- background-color: white;
- }
-
- .choice-takePhoto>view:last-child {
- text-align: center;
- height: 80rpx;
- line-height: 80rpx;
- border-top: 6rpx solid rgba(127, 127, 127, 0.1);
- background-color: white;
- }
-
- .choice-takePhoto>view {
- text-align: center;
- height: 80rpx;
- line-height: 80rpx;
- background-color: white;
- }
-
- .choice-takePhoto-wrap {
- width: 100%;
- height: 100vh;
- background-color: rgba(127, 127, 127, 0.2);
- position: fixed;
- left: 0;
- top: 0;
- z-index: 11111;
- }
- </style>
|