123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845 |
- <template>
- <view class="container">
- <view>
- <!-- #ifdef MP-WEIXIN -->
- <NavigateBar :title="pageTitle" control="back" bgcolor="#a09cc4"></NavigateBar>
- <!-- #endif -->
- <!-- #ifdef MP-ALIPAY -->
- <NavigateBar :title="pageTitle" bgcolor="#a09cc4"></NavigateBar>
- <!-- #endif -->
- </view>
- <view class="step-zero" v-if="step==='fillForm'">
- <view class="tips">
- <u-text align="center" color="#333333" text="根据《治安管理处罚法》要求所有入住宾客和访客必须一人一证实名登记"></u-text>
- </view>
- <u-form labelPosition="left" labelWidth="180rpx">
- <u-form-item label="姓名" prop="name">
- <u-input v-model="name" border="none" clearable fontSize="36rpx"></u-input>
- </u-form-item>
- <u-form-item label="手机号" prop="phone">
- <u-input v-model="phone" border="none" clearable fontSize="36rpx" type="number" maxlength="11"></u-input>
- </u-form-item>
- <u-form-item label="身份证" prop="idNumber">
- <u-input v-model="idNumber" border="none" clearable fontSize="36rpx"></u-input>
- </u-form-item>
- </u-form>
- <view class="btn-container">
- <u-button text="立即认证" color="#9e97c3" @click="finishInput"></u-button>
- </view>
- </view>
- <!-- #ifdef MP-ALIPAY -->
- <!-- 支付宝在上传完身份证照片后会跳转到人脸检测页面 -->
- <view class="step-one" v-else-if="step==='uploadCard' && !shootCard">
- <view class="tips" v-if="!name">
- <u-text align="center" color="#333333" text="根据《治安管理处罚法》要求所有入住宾客和访客必须一人一证实名登记"></u-text>
- </view>
- <view class="upload-container">
- <image :src="idCardFrontPicPath" mode="aspectFit" @click="handleUploadFront" :style="imageStyle">
- </image>
- </view>
- <view class="upload-container">
- <image :src="idCardBackPicPath" mode="aspectFit" @click="handleUploadBack"></image>
- </view>
- <view class="btn-container">
- <u-button :disabled="!getAllInfo" text="完成上传" color="#9e97c3" @click="finishIdCardUpload"></u-button>
- </view>
- <ant-action-sheet :visible="actionSheetVisible" :actions="actions" @action="handleAction"
- @close="handleSheetClose" />
- </view>
- <view class="shoot-id-card" v-if="shootCard">
- <camera id="card-camera" flash="off" device-position="back" @ready="cameraContext"
- :style="[cardCameraStyle]" />
- <cover-image :src="frontSelect ? '/static/mp-alipay/identity_info.png' : '/static/mp-alipay/national_emblem.png'"
- :style="[cardCameraStyle]"></cover-image>
- <view class="camera-btn">
- <image v-if="shot" src="/static/mp-alipay/camera.svg" style="width: 140rpx; height: 140rpx;"></image>
- <image v-else src="/static/mp-alipay/camera.svg" style="width: 140rpx; height: 140rpx;"
- @click="takePhotoAndGetInfo"></image>
- </view>
- </view>
- <!-- #endif -->
- <!-- #ifdef MP-WEIXIN -->
- <view class="step-one" v-else-if="step==='uploadCard'">
- <view class="tips" v-if="!name">
- <u-text align="center" color="#333333" text="根据《治安管理处罚法》要求所有入住宾客和访客必须一人一证实名登记"></u-text>
- </view>
- <view class="upload-container">
- <u-upload @afterRead="afterIdCardRead" name="Front" :maxCount="1" :maxSize="1024*1024*1.5"
- @oversize="oversize">
- <image :src="idCardFrontPicPath" mode="aspectFit"></image>
- </u-upload>
- </view>
- <view class="upload-container">
- <u-upload @afterRead="afterIdCardRead" name="Back" :maxCount="1" :maxSize="1024*1024*1.5"
- @oversize="oversize">
- <image :src="idCardBackPicPath" mode="aspectFit"></image>
- </u-upload>
- </view>
- <view class="btn-container">
- <u-button :disabled="!getAllInfo" text="完成上传" color="#9e97c3" @click="finishIdCardUpload"></u-button>
- </view>
- </view>
- <!-- #endif -->
- <view class="step-two" v-else-if="step==='checkIdentity'">
- <view class="face-area">
- <view class="face-area--tips">
- <view class="face-area--tips--title">
- <u-text text="身份核验" color="#333333" bold size="34rpx"></u-text>
- </view>
- <view class="face-area--tips--context">
- <u-text text="请根据页面提示进行操作" color="#CBCBCB" size="28rpx"></u-text>
- </view>
- </view>
- <view class="face-area--line"></view>
- <view class="camera-container">
- <!-- #ifdef MP-WEIXIN -->
- <camera v-if="showcamera" class="camera" device-position="front" flash="off" resolution="low">
- </camera>
- <!-- #endif -->
- <!-- #ifdef MP-ALIPAY -->
- <camera id="faceCheck-camera" flash="off" device-position="front" @ready="faceCheckCamera"
- :style="[faceCheckCameraStyle]" />
- <cover-image src="/static/mp-alipay/cover.png" :style="[faceCheckCoverImageStyle]"></cover-image>
- <!-- #endif -->
- </view>
- <!-- #ifdef MP-WEIXIN -->
- <view class="info">
- <u-text v-if="showcamera" :text="tipsText" align="center"></u-text>
- </view>
- <!-- #endif -->
- <!-- #ifdef MP-ALIPAY -->
- <view v-if="!showTips" class="check-pic-result">
- {{ checkPicTips }}
- </view>
- <!-- #endif -->
- </view>
- <view class="precautions">
- <view class="precautions--tips">
- <view class="precautions--tips--title">
- <u-text text="注意事项" color="#333333" bold size="34rpx"></u-text>
- </view>
- <view class="precautions--tips--context">
- <u-text text="请遵守需注意事项" color="#CBCBCB" size="28rpx"></u-text>
- </view>
- </view>
- <view class="precautions--line"></view>
- <view class="precautions--context">
- <u-text :text="'确认'+name+'本人操作;保持正脸在取景框中根据屏幕指示完成'" color="#666666" size="24rpx"></u-text>
- </view>
- <view class="img-list">
- <view class="img-list--item" v-for="img in imgList" :key="img.src">
- <view class="img">
- <u-image :src="img.src" :height="img.height" :width="img.width"></u-image>
- </view>
- <view class="tips">
- <u-text :text="img.tips" color="#666666" size="20rpx"></u-text>
- </view>
- </view>
- </view>
- </view>
- <!-- #ifdef MP-WEIXIN -->
- <view class="btn-container">
- <u-button text="同意并开始验证" @click="start" color="#9e97c3"></u-button>
- </view>
- <!-- #endif -->
- <!-- #ifdef MP-ALIPAY -->
- <view class="btn">
- <u-button text="同意并开始验证" @click="checkFacePic" :disabled="isCheckingFace" color="#9e97c3"></u-button>
- </view>
- <!-- #endif -->
- </view>
- </view>
- </template>
- <script>
- import {
- IMG_BASE_URL,
- BASE_URL,
- } from '../../config.js'
- import {
- mapState,
- mapMutations
- } from 'vuex'
- import NavigateBar from '../../components/navigateBar/navigate-bar.vue';
- // #ifdef MP-ALIPAY
- // 最大图片大小为2.0M
- const maxPhotoSize = 2097152
- // OCR类型,人像面为"0",国徽面为"1"
- const ocrType = {
- face: "0",
- emblem: "1"
- }
- // #endif
- export default {
- components: {
- NavigateBar
- },
- data() {
- return {
- isMainCustomer: false,
- //0展示输入姓名、身份证号、手机号页面
- //1展示上传身份证照片页面
- //2展示身份核验页面
- step: "fillForm",
- //步骤 0 需要填入的信息
- name: '',
- idNumber: '',
- phone: '',
- //步骤 1 需要从身份证获取的信息
- idCardInfoInPage: {
- name: '',
- sex: '',
- nation: '',
- birth: '',
- address: '',
- idNumber: '',
- issuingAuthority: '',
- issuingDate: '',
- expiryDate: ''
- },
- idCardFrontPicPath: '../../static/idcard_upload_front.png',
- idCardBackPicPath: '../../static/idcard_upload_back.png',
- infoList: ['address', 'nation', 'sex', 'birth', 'issuingAuthority', 'issuingDate', 'expiryDate'],
- userInfoId: 0,
- // #ifdef MP-WEIXIN
- idCardDirection: '',
- // img: null,
- // imgData: null,
- idCardVKSession: null,
- idCardFrontUploadInfo: {
- imgUrl: '',
- imgWidth: 0,
- imgHeight: 0,
- imgOriginWidth: 0,
- imgOriginHeight: 0,
- },
- idCardFrontDetectInfo: {
- detected: false, //检测是否完成
- detectSuccess: false, //检测是否成功
- isComplete: false, //身份证是否完整
- label: '', //身份证方向,0 人像面,1 国徽面
- orientation: 0, //身份证朝向 (0 朝上 1 朝下 2 朝下 3 朝左)
- box: [], //身份证坐标框点数组 (0 左上点 1 右上点 2 右下点 3 左下点)
- },
- idCardBackUploadInfo: {
- imgUrl: '',
- imgWidth: 0,
- imgHeight: 0,
- imgOriginWidth: 0,
- imgOriginHeight: 0,
- },
- idCardBackDetectInfo: {
- detected: false,
- detectSuccess: false,
- isComplete: false,
- label: '',
- orientation: 0,
- box: [],
- },
- // showAddGuest: true,
- cameraEngine: null,
- VKSession: null,
- showcamera: false,
- tipsText: '开始身份核验',
- duringCameraAuth: false,
- isVKSupport: false,
- imgList: [{
- src: '/static/check-face-phone.png',
- width: '48rpx',
- height: '70rpx',
- tips: '正对手机'
- },
- {
- src: '/static/check-face-light.png',
- width: '78rpx',
- height: '70rpx',
- tips: '光线充足'
- },
- {
- src: '/static/check-face-face.png',
- width: '80rpx',
- height: '80rpx',
- tips: '脸部无遮挡'
- }
- ],
- pageTitle: '身份信息录入',
- // #endif
- // #ifdef MP-ALIPAY
- actionSheetVisible: false,
- actions: [{
- text: "拍照",
- key: "shoot"
- },
- {
- text: "从相册选择",
- key: "choose"
- }
- ],
- shootCard: false,
- shot: false,
- frontSelect: false,
- cardCam: null,
- faceCheckCam: null,
- fileSystem: null,
- cardCamWidth: 0,
- cardCamHigh: 0,
- cardCamTopGap: 0,
- imageStyle: {
- width: "500rpx",
- height: "350rpx",
- margin: "0 auto"
- },
- frontPassed: false,
- idCardFrontBase64: null,
- idCardBackBase64: null,
- backPassed: false,
- checkPicTips: "身份核验中....",
- screenWidth: 0,
- faceCheckCamTopGap: 0,
- showTips: true,
- isCheckingFace: false,
- faceCheckSucceed: false,
- // #endif
- };
- },
- computed: {
- ...mapState('m_user', ['userInfo']),
- ...mapState('m_business', ['checkinInfo', 'currentHotel', 'idCardInfo', 'order']),
- getAllInfo() {
- let getAll = true
- for (const info of this.infoList) {
- if (!this.idCardInfoInPage[info]) {
- getAll = false
- break
- }
- }
- return getAll
- },
- // #ifdef MP-ALIPAY
- cardCameraStyle() {
- let style = {}
- // 设置相机显示区域左右边框距屏幕左右边框为40px
- style.width = this.cardCamWidth + 'px'
- style.height = this.cardCamHigh + 'px'
- style.left = "40px"
- style.top = this.cardCamTopGap + "px"
- return style
- },
- faceCheckCameraStyle() {
- let style = {}
- // 设置相机显示区域左右边框距屏幕左右边框为20px
- let camWidth = this.screenWidth === 0 ? 0 : this.screenWidth - 20 * 2
- style.width = camWidth + 'px'
- style.height = camWidth + 'px'
- return style
- },
- faceCheckCoverImageStyle() {
- let style = {}
- // 设置相机遮罩图片的左右边框距屏幕左右边框为16px
- let imgWidth = this.screenWidth === 0 ? 0 : this.screenWidth - 16 * 2
- style.width = imgWidth + 'px'
- style.height = imgWidth + 'px'
- style.left = "16px"
- style.top = this.faceCheckCamTopGap + "px"
- return style
- }
- // #endif
- },
- methods: {
- ...mapMutations('m_business', ['updateCheckinInfo', 'updateIdCardInfo', 'updateOrder']),
- ...mapMutations('m_user', ['updateUserInfo']),
- async finishInput() {
- //检查格式是否正确
- let nameReg = /\d/;
- if (this.name === '' || nameReg.test(this.name)) {
- uni.$showMsg('姓名格式错误!')
- return
- }
- let idNumberReg =
- /^[1-9]\d{5}(18|19|20)\d{2}((0[1-9])|(1[0-2]))(([0-2][1-9])|10|20|30|31)\d{3}[0-9Xx]$/;
- if (!idNumberReg.test(this.idNumber)) {
- uni.$showMsg('身份证号格式错误!')
- return
- }
- let phoneReg = /^(13[0-9]|14[01456879]|15[0-35-9]|16[2567]|17[0-8]|18[0-9]|19[0-35-9])\d{8}$/;
- if (!phoneReg.test(this.phone)) {
- uni.$showMsg('手机号格式错误!')
- return
- }
- //判断此顾客信息是否已添加
- if (JSON.stringify(this.checkinInfo) !== '{}' && this.checkinInfo.length > 0) {
- for (let info of this.checkinInfo) {
- if (info.idNumber === this.idNumber) {
- uni.$showMsg('已添加此顾客,请检查填写信息')
- return
- }
- }
- }
- //检查该顾客是否在当前酒店入住
- let res = await uni.$http.post('/checkinInfo/queryByCondition', {
- userIdNumber: this.idNumber,
- status: 1,
- hotelId: this.currentHotel.hotelId,
- pageNo: 1,
- pageSize: 1
- })
- if (res.data.code == 200 && res.data.data.records.length > 0) {
- uni.$showMsg('该顾客已入住!')
- return
- }
- //判断本地缓存是否有顾客身份证信息,有则checkIdentity
- for (const info of this.idCardInfo) {
- if (info.idNumber === this.idNumber && info.name === this.name) {
- this.idCardInfoInPage = info
- this.step = 'checkIdentity'
- return
- }
- }
- //本地缓存没有顾客身份信息,到后台查询
- let idCardInfoQueryRes = await uni.$http.post('/idCardInfo/queryByCondition', {
- pageNo: 1,
- pageSize: 1,
- idNumber: this.idNumber,
- name: this.name
- })
- //查询到,写入local storage,跳转checkIdentity
- if (idCardInfoQueryRes.data.data.records.length === 1) {
- let info = idCardInfoQueryRes.data.data.records[0]
- info.birth = info.birthday
- let keys = Object.keys(this.idCardInfoInPage)
- for (const key of keys) {
- //有数据为空则需重新上传
- if (!info[key]) {
- this.step = "uploadCard"
- return
- }
- this.idCardInfoInPage[key] = info[key]
- }
- let idCardInfoToUpdate = this.idCardInfo
- idCardInfoToUpdate.push(this.idCardInfoInPage)
- this.updateIdCardInfo(idCardInfoToUpdate)
- this.step = 'checkIdentity'
- return
- }
- //没查询到,跳转step 1,上传身份证
- this.step = "uploadCard"
- },
- // #ifdef MP-WEIXIN
- initIdCardVKSession() {
- this.idCardVKSession = wx.createVKSession({
- track: {
- IDCard: {
- mode: 2 // 照片模式
- }
- },
- version: 'v1',
- gl: this.gl
- })
- // VKSession start
- this.idCardVKSession.start(err => {
- this.idCardVKSession.on('updateAnchors', anchors => {
- // console.log('updateAnchors')
- // 处理返回的身份证信息
- if (anchors && anchors[0]) {
- // 存在数组,证明存在身份证信息
- const anchor = anchors[0];
- // console.log(anchor.isComplete, anchor.label, anchor.orientation, anchor.box);
- let info = {
- detected: true,
- detectSuccess: true,
- isComplete: anchor.isComplete,
- label: anchor.label,
- orientation: anchor.orientation,
- box: anchor.box,
- }
- this['idCard' + this.idCardDirection + 'DetectInfo'] = info
- // 裁剪信息
- const affineImgWidth = anchor.affineImgWidth;
- const affineImgHeight = anchor.affineImgHeight;
- const affineMat = anchor.affineMat;
- // 存在裁剪信息,进行身份证裁剪处理
- if (affineImgWidth && affineImgHeight && affineMat) {
- // console.log(affineImgWidth, affineImgHeight, affineMat);
- const cropIDcardImg = this.getCropIDcard(affineImgWidth, affineImgHeight,
- affineMat);
- // console.log(cropIDcardImg)
- }
- }
- })
- this.idCardVKSession.on('removeAnchors', anchors => {
- // console.log("anchor remove")
- // 图片没有识别到身份证
- this['idCard' + this.idCardDirection + 'DetectInfo'].detected = true
- this['idCard' + this.idCardDirection + 'DetectInfo'].detectSuccess = false
- })
- });
- },
- async setImageUploadInfo(url) {
- const fixWidth = 300
- let imageInfo = await uni.getImageInfo({
- src: url
- // ,
- // success: (image) => {
- // console.log(image)
- // let height = image.height
- // let width = image.width
- // let info = {
- // imgUrl: url,
- // imgWidth: fixWidth,
- // imgHeight: (fixWidth / width) * height,
- // imgOriginWidth: width,
- // imgOriginHeight: height
- // }
- // this['idCard' + this.idCardDirection + 'UploadInfo'] = info
- // }
- })
- let height = imageInfo[1].height
- let width = imageInfo[1].width
- let uploadInfo = {
- imgUrl: url,
- imgWidth: fixWidth,
- imgHeight: (fixWidth / width) * height,
- imgOriginWidth: width,
- imgOriginHeight: height
- }
- this['idCard' + this.idCardDirection + 'UploadInfo'] = uploadInfo
- },
- getCropIDcard(affineImgWidth, affineImgHeight, affineMat) {
- // console.log('start getCropIDcard')
- let infoName = 'idCard' + this.idCardDirection + 'UploadInfo'
- const canvas = wx.createOffscreenCanvas({
- type: '2d',
- width: affineImgWidth,
- height: affineImgHeight,
- })
- const context = canvas.getContext('2d')
- context.clearRect(0, 0, affineImgWidth, affineImgHeight);
- /*
- * affineMat 3x3仿射变换矩阵,行主序
- * [0 1 2
- * 3 4 5
- * 6 7 8]
- */
- /*
- * canvas 2d setTransform
- * setTransform(a, b, c, d, e, f)
- * [a c e
- * b d f
- * 0 0 1]
- */
- context.setTransform(
- Number(affineMat[0]), Number(affineMat[3]), Number(affineMat[1]),
- Number(affineMat[4]), Number(affineMat[2]), Number(affineMat[5])
- );
- // console.log(this.img, this[infoName].imgOriginWidth, this[infoName].imgOriginHeight)
- context.drawImage(this.img, 0, 0, this[infoName].imgOriginWidth, this[infoName].imgOriginHeight)
- const imgUrl = canvas.toDataURL()
- this[infoName].imgUrl = imgUrl
- this['idCard' + this.idCardDirection + 'PicPath'] = imgUrl
- return imgUrl;
- },
- async detectIdCard() {
- let infoName = 'idCard' + this.idCardDirection + 'UploadInfo'
- if (this[infoName].imgUrl) {
- const canvas = wx.createOffscreenCanvas({
- type: '2d',
- width: this[infoName].imgOriginWidth,
- height: this[infoName].imgOriginHeight,
- })
- const context = canvas.getContext('2d')
- const img = canvas.createImage()
- // 使用中的 图片对象
- this.img = img;
- await new Promise(resolve => {
- img.onload = resolve
- img.src = this[infoName].imgUrl
- })
- context.clearRect(0, 0, this[infoName].imgOriginWidth, this[infoName].imgOriginHeight)
- context.drawImage(img, 0, 0, this[infoName].imgOriginWidth, this[infoName].imgOriginHeight)
- // 使用中的 image ArrayBuffer
- this.imgData = context.getImageData(0, 0, this[infoName].imgOriginWidth, this[infoName]
- .imgOriginHeight)
- // console.log('[frameBuffer] --> ', this.imgData.data.buffer)
- // console.log('this.session.detectIDCard', this.idCardVKSession.detectIDCard)
- // console.log('width', this[infoName].imgOriginWidth)
- // console.log('height', this[infoName].imgOriginHeight)
- this.idCardVKSession.detectIDCard({
- // 识别身份证图片的信息
- frameBuffer: this.imgData.data.buffer,
- width: this[infoName].imgOriginWidth,
- height: this[infoName].imgOriginHeight,
- // 是否获取裁剪图片信息
- getAffineImg: true,
- })
- }
- },
- async afterIdCardRead(event) {
- console.log(event)
- //正面还是反面
- this.idCardDirection = event.name
- await this.setImageUploadInfo(event.file.url)
- await this.detectIdCard()
- let detectInfo = this['idCard' + this.idCardDirection + 'DetectInfo']
- //图片中不包含身份证
- if (!detectInfo.detectSuccess) {
- uni.showModal({
- title: '图片中不包含身份证,请重新上传',
- showCancel: false
- })
- return
- }
- if (!detectInfo.isComplete) {
- uni.showModal({
- title: '身份证照片不完整,请重新上传',
- showCancel: false
- })
- return
- }
- if ((this.idCardDirection === 'Front' && detectInfo.label !== 0) ||
- (this.idCardDirection === 'Back' && detectInfo.label !== 1)) {
- uni.showModal({
- title: '身份证面错误,请重新上传',
- showCancel: false
- })
- return
- }
- let baseUrl = BASE_URL.slice(0, -11)
- uni.showLoading({
- title: '上传中',
- mask: true
- })
- let filePath = this['idCard' + this.idCardDirection + 'PicPath']
- // uni.getFileSystemManager().readFile({
- // filePath: filePath, //选择图片返回的相对路径
- // encoding: 'base64',
- // success: res => {
- let data = {
- image: filePath.split(',')[1],
- imageType: 'BASE64',
- }
- data.ocrType = detectInfo.label
- uni.request({
- url: baseUrl + '/verification/idCardOcr',
- method: 'POST',
- data: data,
- success: res => {
- console.log(res)
- if (res.data.data.imageStatus !== 'normal') {
- uni.showModal({
- content: '获取信息失败,请检查图片并重新上传',
- showCancel: false,
- })
- }
- if (!this.name) {
- this.name = res.data.data.name
- }
- if (!this.idNumber) {
- this.idNumber = res.data.data.cardNum
- }
- if (event.name === 'Front' && (res.data.data.cardNum != this.idNumber || res.data
- .data.name != this.name)) {
- uni.showModal({
- content: '填写信息与身份证不一致',
- showCancel: false,
- complete: () => {
- this.step = "fillForm"
- this.idCardFrontPicPath =
- '../../static/upload_front.png'
- return
- }
- })
- }
- this['idCard' + this.idCardDirection + 'Base64'] = data.image
- if (event.name === 'Front') {
- this.idCardInfoInPage.name = res.data.data.name
- this.idCardInfoInPage.sex = res.data.data.sex
- this.idCardInfoInPage.nation = res.data.data.nation
- this.idCardInfoInPage.birth = res.data.data.birth
- this.idCardInfoInPage.address = res.data.data.address
- this.idCardInfoInPage.idNumber = res.data.data.cardNum
- } else {
- this.idCardInfoInPage.issuingAuthority = res.data.data.issuingAuthority
- this.idCardInfoInPage.issuingDate = res.data.data.issuingDate
- this.idCardInfoInPage.expiryDate = res.data.data.expiryDate
- }
- },
- fail: err => {
- uni.$showMsg('上传失败')
- },
- complete: () => {
- console.log('complete')
- uni.hideLoading()
- }
- })
- // },
- // complete: () => {
- // uni.hideLoading()
- // }
- // })
- },
- oversize() {
- uni.$showMsg('图片超出允许大小(1.5M)')
- },
- // #endif
- async gotoCheckFace() {
- //静态检测
- if (this.userInfo.staticFaceCheck === true) {
- uni.navigateTo({
- url: `/subpkg_checkin/staticFaceCheck/staticFaceCheck?idNumber=${this.idNumber}&name=${this.name}&phone=${this.phone}`
- })
- } else {
- // #ifdef MP-WEIXIN
- // const accountInfo = wx.getAccountInfoSync();
- // const env = accountInfo.miniProgram.envVersion
- // if (env !== "release") {
- // let faceRes = await uni.request({
- // url: IMG_BASE_URL + '/test_face_base64.txt',
- // method: 'GET'
- // })
- // let faceBase64 = faceRes[1].data
- // this.checkinInfo[this.checkinInfo.length] = {
- // name: this.name,
- // idNumber: this.idNumber,
- // phone: this.phone,
- // faceData: faceBase64
- // }
- // this.updateCheckinInfo(this.checkinInfo)
- // uni.navigateTo({
- // url: '/subpkg_checkin/confirmOrder/confirmOrder'
- // })
- // }
- // #endif
- // #ifdef MP-ALIPAY
- this.step = 'checkIdentity'
- // #endif
- }
- },
- async finishIdCardUpload() {
- if (this.getAllInfo) {
- //判断此顾客信息是否已添加
- if (JSON.stringify(this.checkinInfo) !== '{}' && this.checkinInfo.length > 0) {
- for (let info of this.checkinInfo) {
- if (info.idNumber === this.idNumber) {
- uni.$showMsg('已添加此顾客,请检查填写信息')
- return
- }
- }
- }
- //检查该顾客是否在当前酒店入住
- let res = await uni.$http.post('/checkinInfo/queryByCondition', {
- userIdNumber: this.idNumber,
- status: 1,
- hotelId: this.currentHotel.hotelId,
- pageNo: 1,
- pageSize: 1
- })
- if (res.data.code == 200 && res.data.data.records.length > 0) {
- uni.$showMsg('该顾客已入住!')
- return
- }
- this.step = 'checkIdentity'
- } else {
- uni.$showMsg('请检查身份证照片')
- }
- },
- // #ifdef MP-ALIPAY
- async handleAction(item, e) {
- if (item.key === 'shoot') {
- this.shootCard = true
- } else if (item.key === 'choose') {
- await this.handleChooseImageAndGetInfo()
- }
- },
- handleSheetClose(e) {
- // console.log("handleSheetClose", e)
- this.actionSheetVisible = false
- },
- handleUploadFront() {
- if (this.frontPassed) {
- uni.$showMsg('身份证正面已核验通过')
- return
- }
- this.frontSelect = true
- this.actionSheetVisible = true
- },
- handleUploadBack() {
- if (this.backPassed) {
- uni.$showMsg('身份证背面已核验通过')
- return
- }
- this.frontSelect = false
- this.actionSheetVisible = true
- },
- async cameraContext() {
- this.cardCam = await my.createCameraContext('card-camera');
- },
- async faceCheckCamera() {
- this.faceCheckCam = await my.createCameraContext('faceCheck-camera');
- },
- async takePhotoAndGetInfo() {
- this.shot = true
- const photo = await this.cardCam.takePhoto({
- quality: 'normal',
- })
- console.log("photo", photo);
- const {
- picWidth,
- picHeight,
- size
- } = photo
- console.log("picWidth", picWidth, "picHeight", picHeight, "size", size);
- let picPath = photo.tempImagePath
- if (size > maxPhotoSize) {
- uni.showModal({
- content: '图片大小超过2MB,请重新拍照或选择照片上传。',
- showCancel: false
- })
- return
- }
- // picWidth < picHeight 需要旋转图片
- if (picWidth < picHeight) {
- const offCanvas = my.createOffscreenCanvas()
- const offCtx = offCanvas.getContext('2d')
- // console.log("offCtx", offCtx);
- // 用 离屏canvas 创建 Image
- const image = offCanvas.createImage()
- await new Promise((resolve, reject) => {
- image.src = photo.tempImagePath
- image.onload = function() {
- offCanvas.width = image.height
- offCanvas.height = image.width
- offCtx.rotate(270 * Math.PI / 180);
- offCtx.translate(-offCanvas.height, 0);
- // 将 Image 画到 离屏canvas 上
- offCtx.drawImage(image, 0, 0, image.width, image.height)
- resolve()
- }
- })
- // console.log("offCanvas", offCanvas);
- picPath = offCanvas.toDataURL("image/jpeg")
- // console.log("canDataUrl", picPath);
- }
- let _ocrType
- if (this.frontSelect) {
- this.idCardFrontPicPath = picPath
- _ocrType = ocrType.face
- } else {
- this.idCardBackPicPath = picPath
- _ocrType = ocrType.emblem
- }
- this.shootCard = false
- // 完成照片获取工作,开始和后端沟通获取照片上的信息
- this.shot = false
- // 打开loading模态框,处理图片
- const {
- data: photoBase64
- } = await this.fileSystem.readFile({
- filePath: photo.tempImagePath,
- encoding: "base64"
- })
- // console.log("photoBase64", photoBase64);
- await this.idCardOCR(photoBase64, _ocrType)
- },
- async handleChooseImageAndGetInfo() {
- const img = await my.chooseImage({
- sizeType: ['compressed'],
- sourceType: ['album'],
- })
- // console.log("ChooseImage", img);
- const imgSize = img.tempFiles[0].size
- if (imgSize > maxPhotoSize) {
- uni.showModal({
- content: '图片大小超过2MB,请重新选择照片或拍照上传。',
- showCancel: false
- })
- return
- }
- let _ocrType
- if (this.frontSelect) {
- this.idCardFrontPicPath = img.tempFilePaths[0]
- _ocrType = ocrType.face
- } else {
- this.idCardBackPicPath = img.tempFilePaths[0]
- _ocrType = ocrType.emblem
- }
- const {
- data: photoBase64
- } = await this.fileSystem.readFile({
- filePath: img.tempFilePaths[0],
- encoding: "base64"
- })
- // console.log("photoBase64", photoBase64);
- await this.idCardOCR(photoBase64, _ocrType)
- },
- async idCardOCR(imgBase64, _ocrType) {
- // 在进行身份证识别时,弹loading框,不让进行任何操作
- my.showLoading({
- content: "身份证信息识别中...",
- mask: true
- })
- const ocrBaseUrl = BASE_URL.slice(0, -11)
- const ocrData = {
- image: imgBase64,
- imageType: "BASE64",
- ocrType: _ocrType
- }
- const {
- data: ocrRes
- } = await my.request({
- url: ocrBaseUrl + "/verification/idCardOcr",
- method: "POST",
- data: ocrData
- })
- // console.log("ocrRes", ocrRes);
- if (!ocrRes.success) {
- uni.showModal({
- content: '身份证信息识别失败,请重新选择照片或拍照上传。',
- showCancel: false
- })
- my.hideLoading()
- return
- }
- const {
- data
- } = ocrRes
- // console.log(data);
- if (_ocrType === ocrType.face) {
- if (!this.name) {
- this.name = data.name
- }
- if (!this.idNumber) {
- this.idNumber = data.cardNum
- }
- if (this.idNumber !== data.cardNum || this.name !== data.name) {
- uni.showModal({
- content: '身份信息不一致,请核实后重新操作',
- showCancel: false,
- complete: () => {
- this.step = "fillForm"
- this.idCardFrontPicPath = '/static/idcard_upload_front.png'
- this.backPassed = false
- my.hideLoading()
- }
- })
- return
- }
- this.idCardInfoInPage.name = data.name
- this.idCardInfoInPage.sex = data.sex
- this.idCardInfoInPage.nation = data.nation
- this.idCardInfoInPage.birth = data.birth
- this.idCardInfoInPage.address = data.address
- this.idCardInfoInPage.idNumber = data.cardNum
- this.idCardFrontBase64 = imgBase64
- this.frontPassed = true
- } else if (_ocrType === ocrType.emblem) {
- this.idCardInfoInPage.issuingAuthority = data.issuingAuthority
- this.idCardInfoInPage.issuingDate = data.issuingDate
- this.idCardInfoInPage.expiryDate = data.expiryDate
- this.idCardBackBase64 = imgBase64
- this.backPassed = true
- }
- my.hideLoading()
- },
- async checkFacePic() {
- const userSetting = await uni.getSetting()
- // console.log("userSetting", userSetting);
- let camAuth = userSetting[1].authSetting['camera'] ? userSetting[1].authSetting['camera'] : false
- while (!camAuth) {
- await new Promise(async (resolve, reject) => {
- await uni.showModal({
- title: "温馨提示",
- content: "身份核验功能需要使用您的相机,请授权后重新点击核验。",
- success: async (res) => {
- if (res.confirm) {
- await uni.openSetting().then(res => {
- console.log("openSetting", res);
- camAuth = res[1].authSetting['camera'] ? res[1]
- .authSetting['camera'] : false
- resolve()
- })
- }
- }
- })
- })
- setTimeout(() => {}, 200)
- }
- // console.log("进行了相机授权操作");
- this.checkPicTips = "身份核验中...."
- this.showTips = false
- this.isCheckingFace = true
- let succeedImgBase64
- while (!this.faceCheckSucceed) {
- // console.log("开始takePhoto进行人脸检测", this.faceCheckCam);
- const photo = await this.faceCheckCam.takePhoto({
- quality: 'normal',
- })
- // console.log("完成takePhoto", photo.tempImagePath);
- const {
- data: photoBase64
- } = await this.fileSystem.readFile({
- filePath: photo.tempImagePath,
- encoding: "base64"
- })
- // console.log("photoBase64", photoBase64);
- let checkPicRes = await uni.$http.post("/faceVerification/checkPic", {
- hotelId: this.currentHotel.hotelId,
- faceData: photoBase64,
- })
- // console.log("checkPicRes", checkPicRes);
- if (!checkPicRes.data.success) {
- // console.log("checkPicRes.data", checkPicRes.data.msg.split("原因:")[1]);
- this.checkPicTips = checkPicRes.data.msg.split("原因:")[1] + "请将面部完整放入拍摄区域。"
- } else {
- succeedImgBase64 = photoBase64
- this.faceCheckSucceed = checkPicRes.data.success
- }
- setTimeout(() => {}, 100)
- }
- // 进行云极人证比对
- await this.afterSuccessCheckPicAlipay(succeedImgBase64)
- },
- async afterSuccessCheckPicAlipay(photoBase64) {
- if (this.userInfo.skipIdMatching === true) {
- this.checkPicTips = "身份核验成功,将跳转确认订单页面"
- let infoFromIdCard = {}
- this.infoList.forEach(info => {
- infoFromIdCard[info] = that[info]
- })
- let currentCheckinInfo = {
- name: this.name,
- idNumber: this.idNumber,
- phone: this.phone,
- faceData: photoBase64
- }
- currentCheckinInfo = {
- ...currentCheckinInfo,
- ...infoFromIdCard
- }
- this.checkinInfo.push(currentCheckinInfo)
- this.updateCheckinInfo(this.checkinInfo)
- let currentGuestInfo = {
- name: this.name,
- idNumber: this.idNumber,
- }
- let i
- for (i = 0; i < this.guestInfo.length; i++) {
- if (this.guestInfo[i].idNumber === this.idNumber) {
- this.guestInfo[i] = {
- ...currentGuestInfo,
- ...infoFromIdCard
- }
- this.updateGuestInfo(this.guestInfo)
- }
- }
- if (i === this.guestInfo.length) {
- this.guestInfo.push({
- ...currentGuestInfo,
- ...infoFromIdCard
- })
- this.updateGuestInfo(this.guestInfo)
- }
- setTimeout(() => uni.reLaunch({
- url: '/subpkg_checkin/confirmOrder/confirmOrder'
- }), 1000);
- } else {
- uni.showLoading({
- title: '正在身份核验,请稍后',
- });
- let yunjiFaceCheckInfo = {
- idNo: this.idNumber,
- name: this.name,
- image: photoBase64,
- };
- let checkRes = await uni.$http.post(
- '/faceVerification/yunjiVerification',
- yunjiFaceCheckInfo
- );
- if (checkRes.data.success) {
- let infoFromIdCard = {}
- this.infoList.forEach(info => {
- infoFromIdCard[info] = this.idCardInfoInPage[info]
- })
- let currentCheckinInfo = {
- name: this.name,
- idNumber: this.idNumber,
- faceData: photoBase64,
- phone: this.phone,
- ...infoFromIdCard
- }
- //更新local storage 中的入住信息
- let checkinInfoToUpdate = this.checkinInfo
- checkinInfoToUpdate.push(currentCheckinInfo)
- this.updateCheckinInfo(checkinInfoToUpdate)
- //更新local storage 中的身份证信息
- let idCardInfoToUpdate = this.idCardInfo
- idCardInfoToUpdate.push(this.idCardInfoInPage)
- this.updateIdCardInfo(idCardInfoToUpdate)
- //如果上传过照片则更新服务器中的身份证信息
- if (this.frontPassed && this.backPassed) {
- uni.$http.post('/idCardInfo', {
- ...this.idCardInfoInPage,
- birthday: this.idCardInfoInPage.birth,
- idCardFrontBase64: this.idCardFrontBase64,
- idCardBackBase64: this.idCardBackBase64
- })
- }
- if (this.isMainCustomer) {
- //如果是主入住人,且当前账号姓名和身份证号为空,则更新账号信息为主入住人信息
- if (!this.userInfo.name || !this.userInfo.idNumber) {
- this.userInfo.name = this.name
- this.userInfo.idNumber = this.idNumber
- this.updateUserInfo(this.userInfo)
- uni.$http.put(`/userInfo/${this.userInfo.id}`, this.userInfo)
- }
- //更新订单预定人信息为主入住人信息
- let orderToUpdate = this.order
- orderToUpdate.name = this.name
- orderToUpdate.phone = this.phone
- this.updateOrder(orderToUpdate)
- }
- uni.hideLoading();
- uni.$showMsg('身份核验通过!')
- setTimeout(() => uni.reLaunch({
- url: '/subpkg_checkin/confirmOrder/confirmOrder'
- }), 1000)
- } else {
- uni.hideLoading()
- this.isCheckingFace = false
- this.checkPicTips = "身份核验失败,请重新进行"
- }
- }
- },
- // #endif
- // #ifdef MP-WEIXIN
- start() {
- console.log('调用start');
- this.idCardVKSession.destroy()
- if (!this.duringCameraAuth && this.isVKSupport) {
- this.getCameraAuth()
- }
- },
- getCameraAuth() {
- console.log('getCameraAuth')
- this.duringCameraAuth = true
- let that = this
- wx.getSetting({
- success: (res) => {
- console.log('getSetting, res : ')
- console.log(res)
- if (!res.authSetting['scope.camera']) {
- wx.authorize({
- scope: 'scope.camera',
- success(res) {
- console.log('authorize success, res : ')
- console.log(res)
- that.showcamera = true
- },
- fail: (res) => {
- console.log('authorize fail, res : ')
- console.log(res)
- wx.showModal({
- title: '提示',
- content: '尚未进行授权,功能将无法使用',
- cancelText: '取消',
- confirmText: '授权',
- success(res) {
- console.log(res);
- if (res.confirm) {
- wx.openSetting({
- //这里的方法是调到一个添加权限的页面,这里可以测试在拒绝授权的情况下设置中是否存在相机选项
- success: (res) => {
- if (!res.authSetting[
- 'scope.camera'
- ]) {
- this.getCameraAuth()
- } else {
- that.showcamera =
- true
- }
- },
- fail: function() {
- console.log(
- '相机授权设置失败');
- },
- });
- } else if (res.cancel) {
- console.log('用户点击取消');
- wx.showToast({
- title: '您已取消授权',
- icon: 'error',
- duration: 1000,
- });
- setTimeout(function() {
- wx.navigateBack();
- }, 1000);
- }
- }
- })
- }
- })
- } else {
- that.showcamera = true
- }
- that.initData()
- }
- })
- this.duringCameraAuth = false
- },
- //visionkit人脸必须函数
- async detectFace(frame) {
- console.log('frame', frame.data);
- this.faceVKSession.detectFace({
- frameBuffer: frame.data,
- width: frame.width,
- height: frame.height,
- scoreThreshold: 0.8,
- sourceType: 0,
- modelMode: 1,
- });
- },
- //初始化相机引擎
- initData() {
- let that = this;
- console.log('before createCameraContext')
- //使用visionkit
- that.cameraEngine = wx.createCameraContext();
- console.log('before createCameraContext')
- let count = 0;
- //初始化相机
- const listener = that.cameraEngine.onCameraFrame((frame) => {
- count++;
- //每十帧分析一次
- if (count === 10) {
- this.detectFace(frame);
- count = 0;
- }
- });
- //开始监听数据帧
- listener.start();
- //创建VK对象
- that.faceVKSession = wx.createVKSession({
- version: 'v1',
- track: {
- plane: {
- mode: 1,
- },
- face: {
- mode: 2,
- },
- },
- });
- //启动VK对象
- that.faceVKSession.start((errno) => {
- console.log('faceVKSession.start errno', errno);
- if (errno) {
- wx.showModal({
- title: '提示',
- content: '网络错误,请退出后重试',
- showCancel: false,
- confirmText: '确定',
- success(res) {
- console.log(res);
- if (res.confirm) {
- wx.navigateBack();
- }
- },
- });
- return
- }
- console.log('faceVKSession start')
- that.faceVKSession.on('updateAnchors', (anchors) => {
- console.log('anchors', anchors);
- console.log('anchors.length', anchors.length);
- anchors.forEach((anchor) => {
- console.log('anchor.points', anchor.points);
- console.log('anchor.origin', anchor.origin);
- console.log('anchor.size', anchor.size);
- console.log('anchor.angle', anchor.angle);
- console.log('anchor', anchor.confidence);
- if (anchors.length > 1) {
- that.tipsText = '请保证只有一个人';
- } else {
- const {
- pitch,
- roll,
- yaw
- } = anchor.angle;
- const standard = 0.3;
- if (
- Math.abs(pitch) >= standard ||
- Math.abs(roll) >= standard ||
- Math.abs(yaw) >= standard
- ) {
- that.tipsText = '请平视摄像头';
- } else if (
- anchor.origin.x < 0.15 ||
- anchor.origin.x > 0.3 ||
- anchor.origin.y < 0.2 ||
- anchor.origin.y > 0.45
- ) {
- this.tipsText = '请将人脸对准中心位置';
- } else if (
- anchor.confidence[0] <= 0.8 ||
- anchor.confidence[1] <= 0.8 ||
- anchor.confidence[2] <= 0.8 ||
- anchor.confidence[3] <= 0.8 ||
- anchor.confidence[4] <= 0.8
- ) {
- that.tipsText = '请勿遮挡五官';
- } else {
- listener.stop();
- that.tipsText = '即将拍照,请保持!';
- setTimeout(function() {
- that.handleTakePhotoClick();
- }, 1000);
- return;
- }
- }
- });
- });
- });
- },
- // 拍照
- handleTakePhotoClick() {
- this.tipsText = '';
- uni.showLoading({
- title: '正在身份核验,请稍后',
- });
- this.cameraEngine.takePhoto({
- quality: 'normal',
- success: ({
- tempImagePath
- }) => {
- let mybase64 = wx
- .getFileSystemManager()
- .readFileSync(tempImagePath, 'base64');
- this.afterRead(mybase64);
- this.showcamera = false
- },
- });
- },
- //上传
- async afterRead(mybase64) {
- let that = this;
- uni.$http.post('/faceVerification/checkPic', {
- hotelId: that.currentHotel.hotelId,
- faceData: mybase64,
- })
- .then(async (res) => {
- uni.hideLoading();
- console.log('mybase64', mybase64);
- if (res.data.code === 200 && res.data.success === true) {
- if (that.userInfo.skipIdMatching === true) {
- uni.showModal({
- content: '图片检查通过!',
- showCancel: false,
- success: function(res) {
- if (res.confirm) {
- console.log('用户点击确定');
- let infoFromIdCard = {}
- that.infoList.forEach(info => {
- infoFromIdCard[info] = that[info]
- })
- let currentCheckinInfo = {
- name: that.name,
- idNumber: that.idNumber,
- phone: that.phone,
- faceData: mybase64
- }
- currentCheckinInfo = {
- ...currentCheckinInfo,
- ...infoFromIdCard
- }
- that.checkinInfo.push(currentCheckinInfo)
- that.updateCheckinInfo(that.checkinInfo)
- let currentGuestInfo = {
- name: that.name,
- idNumber: that.idNumber,
- }
- let i
- for (i = 0; i < that.guestInfo.length; i++) {
- if (that.guestInfo[i].idNumber == that.idNumber) {
- that.guestInfo[i] = {
- ...currentGuestInfo,
- ...infoFromIdCard
- }
- that.updateGuestInfo(that.guestInfo)
- }
- }
- if (i === that.guestInfo.length) {
- that.guestInfo.push({
- ...currentGuestInfo,
- ...infoFromIdCard
- })
- that.updateGuestInfo(that.guestInfo)
- }
- setTimeout(() => uni.reLaunch({
- url: '/subpkg_checkin/confirmOrder/confirmOrder'
- }), 1000);
- }
- },
- });
- } else {
- uni.showLoading({
- title: '正在身份核验,请稍后',
- });
- let yunjiFaceCheckInfo = {
- idNo: that.idNumber,
- name: that.name,
- image: mybase64,
- };
- let checkRes = await uni.$http.post(
- '/faceVerification/yunjiVerification',
- yunjiFaceCheckInfo
- );
- if (checkRes.data.success === true) {
- let infoFromIdCard = {}
- that.infoList.forEach(info => {
- infoFromIdCard[info] = that.idCardInfoInPage[info]
- })
- let currentCheckinInfo = {
- name: that.name,
- idNumber: that.idNumber,
- faceData: mybase64,
- phone: that.phone,
- ...infoFromIdCard
- }
- //更新local storage 中的入住信息
- let checkinInfoToUpdate = that.checkinInfo
- checkinInfoToUpdate.push(currentCheckinInfo)
- that.updateCheckinInfo(checkinInfoToUpdate)
- //更新local storage 中的身份证信息
- let idCardInfoToUpdate = that.idCardInfo
- idCardInfoToUpdate.push(that.idCardInfoInPage)
- that.updateIdCardInfo(idCardInfoToUpdate)
- //如果上传过照片则更新服务器中的身份证信息
- if (that.idCardFrontDetectInfo.detected && that.idCardBackDetectInfo
- .detected) {
- uni.$http.post('/idCardInfo', {
- ...that.idCardInfoInPage,
- birthday: that.idCardInfoInPage.birth,
- idCardFrontBase64: that.idCardFrontPicPath.split(',')[1],
- idCardBackBase64: that.idCardBackPicPath.split(',')[1]
- })
- }
- if (this.isMainCustomer) {
- //如果是主入住人,且当前账号姓名和身份证号为空,则更新账号信息为主入住人信息
- if (!this.userInfo.name || !this.userInfo.idNumber) {
- this.userInfo.name = this.name
- this.userInfo.idNumber = this.idNumber
- this.updateUserInfo(this.userInfo)
- uni.$http.put(`/userInfo/${this.userInfo.id}`, this.userInfo)
- }
- //更新订单预定人信息为主入住人信息
- let orderToUpdate = this.order
- orderToUpdate.name = this.name
- orderToUpdate.phone = this.phone
- this.updateOrder(orderToUpdate)
- }
- uni.hideLoading();
- uni.$showMsg('身份核验通过!')
- setTimeout(() => uni.reLaunch({
- url: '/subpkg_checkin/confirmOrder/confirmOrder'
- }), 1000)
- } else {
- uni.hideLoading()
- uni.showModal({
- content: '身份核验失败,请重试',
- showCancel: false,
- success: function(res) {
- if (res.confirm) {
- console.log('用户点击确定');
- that.initData();
- }
- },
- });
- }
- }
- } else {
- uni.hideLoading()
- uni.showModal({
- content: '身份核验失败,请重试',
- showCancel: false,
- success: function(res) {
- if (res.confirm) {
- console.log('用户点击确定');
- that.initData();
- }
- },
- });
- }
- console.log('checkPicRes', res);
- });
- },
- // #endif
- },
- async onLoad() {
- let pages = getCurrentPages()
- let beforePage = pages[pages.length - 2]
- //不是从确定订单页面点击添加顾客跳转过来,设置信息为当前账户的信息,清空入住信息
- if (beforePage.route !== 'subpkg_checkin/confirmOrder/confirmOrder') {
- this.name = this.userInfo.name
- this.idNumber = this.userInfo.idNumber
- this.phone = this.userInfo.phone
- this.updateCheckinInfo([])
- this.isMainCustomer = true
- } else {
- this.isMainCustomer = false
- }
- //是主入住人且姓名和身份证号为空,判断为新用户,直接跳转至上传身份证照片页面
- if (this.isMainCustomer && (!this.userInfo.name || !this.userInfo.idNumber)) {
- this.step = 'uploadCard'
- }
- // #ifdef MP-WEIXIN
- this.isVKSupport = wx.isVKSupport('v1')
- if (!this.isVKSupport) {
- uni.showModal({
- content: '微信版本过低,请升级至最新版本',
- showCancel: false,
- })
- }
- // #endif
- // #ifdef MP-ALIPAY
- let alipaySystemInfo = await uni.getSystemInfo()
- this.screenWidth = alipaySystemInfo[1].screen.width
- // 设置身份证拍照相机显示区域距边界40px
- this.cardCamWidth = alipaySystemInfo[1].screen.width - 40 * 2
- this.cardCamHigh = Number(865 / 548 * this.cardCamWidth).toFixed(0)
- const menuButton = await uni.getMenuButtonBoundingClientRect()
- // 身份证拍照相机top距navBar底部10px
- this.cardCamTopGap = menuButton.top + menuButton.height + 8 + 10
- const factor = this.screenWidth / 750
- const tipsHight = 106 * factor
- this.faceCheckCamTopGap = menuButton.top + menuButton.height + 8 + tipsHight
- this.fileSystem = my.getFileSystemManager();
- // #endif
- },
- // #ifdef MP-WEIXIN
- onShow() {
- this.showAddGuest = true
- this.pageTitle = '身份信息录入'
- },
- onReady() {
- this.initIdCardVKSession()
- },
- onShareAppMessage(info) {
- return {
- title: '源享住',
- path: 'pages/quickLogin/quickLogin',
- imageUrl: '/static/logo.png'
- }
- },
- // #endif
- }
- </script>
- <style lang="scss">
- .btn-container {
- position: fixed;
- bottom: 90rpx;
- left: 30rpx;
- right: 30rpx;
- .u-button__text {
- font-size: 30rpx !important;
- }
- }
- page {
- background: #EFEFF4;
- .container {
- .step-zero {
- .tips {
- margin: 30rpx;
- }
- .u-form {
- margin-top: 10rpx;
- background-color: #FFFFFF;
- .u-form-item {
- line-height: 50rpx;
- .u-form-item__body {
- margin-left: 32rpx;
- border-bottom: 2rpx solid #E5E5E5;
- .u-form-item__body__right__content__slot {
- display: flex;
- flex-direction: row;
- justify-content: space-between;
- margin-right: 20rpx;
- align-items: center;
- }
- }
- .u-form-item__body__left__content__label {
- font-size: 30rpx;
- }
- }
- }
- }
- .step-one {
- .tips {
- margin: 30rpx;
- }
- .upload-container {
- width: 500rpx;
- margin: 30rpx auto;
- /* #ifdef MP-WEIXIN */
- .u-upload {
- image {
- width: 500rpx;
- height: 350rpx;
- margin: 0 auto;
- }
- }
- /* #endif */
- /* #ifdef MP-ALIPAY */
- image {
- width: 500rpx;
- height: 350rpx;
- margin: 0 auto;
- }
- /* #endif */
- }
- }
- .step-two {
- display: flex;
- flex-direction: column;
- width: 100%;
- height: 100%;
- .face-area {
- display: flex;
- flex-direction: column;
- background-color: #FFFFFF;
- border-radius: 50rpx;
- overflow: hidden;
- .face-area--tips {
- display: flex;
- padding: 10rpx 20rpx;
- height: 60rpx;
- align-items: flex-end;
- .face-area--tips--title {
- margin: 10rpx;
- }
- .face-area--tips--context {
- margin: 10rpx;
- }
- }
- .face-area--line {
- margin-left: 40rpx;
- margin-bottom: 20rpx;
- width: 30rpx;
- border-bottom: solid 6rpx #9e97c3;
- }
- /* #ifdef MP-WEIXIN */
- .camera-container {
- width: 80%;
- height: 80vw;
- margin: 0 auto;
- margin-bottom: 30rpx;
- .camera {
- width: 100%;
- height: 80vw;
- margin: 0 auto;
- margin-bottom: 30rpx;
- border: 2rpx solid black;
- border-radius: 50%;
- // box-sizing: border-box;
- }
- }
- /* #endif */
- /* #ifdef MP-ALIPAY */
- .camera-container {
- width: 100%;
- display: flex;
- align-items: center;
- justify-content: center;
- padding-bottom: 30rpx;
- cover-image {
- margin: 0;
- padding: 0;
- position: absolute;
- }
- }
- .check-pic-result {
- width: 100%;
- padding: 10rpx 20rpx;
- display: flex;
- justify-content: center;
- box-sizing: border-box;
- color: red;
- }
- /* #endif */
- }
- .precautions {
- overflow: hidden;
- .precautions--tips {
- display: flex;
- padding: 10rpx 20rpx;
- align-items: flex-end;
- .precautions--tips--title {
- margin: 10rpx;
- }
- .precautions--tips--context {
- margin: 10rpx;
- }
- }
- .precautions--line {
- margin-left: 40rpx;
- margin-bottom: 20rpx;
- width: 30rpx;
- border-bottom: solid 6rpx #9e97c3;
- }
- .precautions--context {
- margin: 0 20rpx;
- margin-bottom: 20rpx;
- }
- .img-list {
- display: flex;
- justify-content: space-around;
- .img-list--item {
- display: flex;
- flex-direction: column;
- align-items: center;
- width: 20%;
- .img {
- display: flex;
- flex-direction: row;
- border-radius: 20rpx;
- background-color: #dcdce9;
- width: 100%;
- height: 140rpx;
- justify-content: center;
- align-items: center;
- }
- }
- }
- }
- /* #ifdef MP-ALIPAY */
- .btn {
- margin: 20rpx;
- }
- /* #endif */
- }
- /* #ifdef MP-ALIPAY */
- .shoot-id-card {
- width: 100%;
- display: flex;
- flex-direction: column;
- align-items: center;
- cover-image,
- camera {
- margin: 0;
- padding: 0;
- position: absolute;
- }
- .camera-btn {
- width: 100%;
- height: 200rpx;
- position: absolute;
- display: flex;
- justify-content: center;
- align-items: center;
- bottom: 50rpx;
- }
- }
- /* #endif */
- }
- }
- </style>
|