addGuest.vue 49 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742
  1. <template>
  2. <view class="container">
  3. <view>
  4. <!-- #ifdef MP-WEIXIN -->
  5. <NavigateBar :title="pageTitle" control="back" bgcolor="#a09cc4"></NavigateBar>
  6. <!-- #endif -->
  7. <!-- #ifdef MP-ALIPAY -->
  8. <NavigateBar :title="pageTitle" bgcolor="#a09cc4"></NavigateBar>
  9. <!-- #endif -->
  10. </view>
  11. <view class="step-zero" v-if="step==='fillForm'">
  12. <view class="tips">
  13. <u-text align="center" color="#333333" text="根据《治安管理处罚法》要求所有入住宾客和访客必须一人一证实名登记"></u-text>
  14. </view>
  15. <u-form labelPosition="left" labelWidth="180rpx">
  16. <u-form-item label="姓名" prop="name">
  17. <u-input v-model="name" border="none" clearable fontSize="36rpx" placeholder="请输入姓名"></u-input>
  18. </u-form-item>
  19. <u-form-item label="手机号" prop="phone">
  20. <u-input v-model="phone" border="none" clearable fontSize="36rpx" type="number"
  21. maxlength="11" placeholder="请输入手机号码"></u-input>
  22. </u-form-item>
  23. <u-form-item label="身份证" prop="idNumber">
  24. <u-input v-model="idNumber" border="none" clearable fontSize="36rpx" placeholder="请输入身份证号码"></u-input>
  25. </u-form-item>
  26. </u-form>
  27. <view class="btn-container">
  28. <u-button text="立即认证" color="#9e97c3" @click="finishInput"></u-button>
  29. </view>
  30. </view>
  31. <!-- #ifdef MP-ALIPAY -->
  32. <!-- 支付宝在上传完身份证照片后会跳转到人脸检测页面 -->
  33. <view class="step-one" v-else-if="step==='uploadCard' && !shootCard">
  34. <view class="tips" v-if="!name">
  35. <u-text align="center" color="#333333" text="根据《治安管理处罚法》要求所有入住宾客和访客必须一人一证实名登记"></u-text>
  36. </view>
  37. <view class="upload-container">
  38. <image :src="idCardFrontPicPath" mode="aspectFit" @click="handleUploadFront" :style="imageStyle">
  39. </image>
  40. </view>
  41. <view class="upload-container">
  42. <image :src="idCardBackPicPath" mode="aspectFit" @click="handleUploadBack"></image>
  43. </view>
  44. <view class="btn-container">
  45. <u-button :disabled="!getAllInfo" text="完成上传" color="#9e97c3" @click="finishIdCardUpload"></u-button>
  46. </view>
  47. <ant-action-sheet :visible="actionSheetVisible" :actions="actions" @action="handleAction"
  48. @close="handleSheetClose" />
  49. </view>
  50. <view class="shoot-id-card" v-if="shootCard">
  51. <camera id="card-camera" flash="off" device-position="back" @ready="cameraContext"
  52. :style="[cardCameraStyle]" />
  53. <cover-image
  54. :src="frontSelect ? '/static/mp-alipay/identity_info.png' : '/static/mp-alipay/national_emblem.png'"
  55. :style="[cardCameraStyle]"></cover-image>
  56. <view class="camera-btn">
  57. <image v-if="shot" src="/static/mp-alipay/camera.svg" style="width: 140rpx; height: 140rpx;"></image>
  58. <image v-else src="/static/mp-alipay/camera.svg" style="width: 140rpx; height: 140rpx;"
  59. @click="takePhotoAndGetInfo"></image>
  60. </view>
  61. </view>
  62. <!-- #endif -->
  63. <!-- #ifdef MP-WEIXIN -->
  64. <view class="step-one" v-else-if="step==='uploadCard'">
  65. <view class="tips" v-if="!name">
  66. <u-text align="center" color="#333333" text="根据《治安管理处罚法》要求所有入住宾客和访客必须一人一证实名登记"></u-text>
  67. </view>
  68. <view class="upload-container">
  69. <u-upload @afterRead="afterIdCardRead" name="Front" :maxCount="1" :maxSize="1024*1024*1.5"
  70. @oversize="oversize">
  71. <image :src="idCardFrontPicPath" mode="aspectFit"></image>
  72. </u-upload>
  73. </view>
  74. <view class="upload-container">
  75. <u-upload @afterRead="afterIdCardRead" name="Back" :maxCount="1" :maxSize="1024*1024*1.5"
  76. @oversize="oversize">
  77. <image :src="idCardBackPicPath" mode="aspectFit"></image>
  78. </u-upload>
  79. </view>
  80. <view class="btn-container">
  81. <u-button :disabled="!getAllInfo" text="完成上传" color="#9e97c3" @click="finishIdCardUpload"></u-button>
  82. </view>
  83. </view>
  84. <!-- #endif -->
  85. <view class="step-two" v-else-if="step==='checkIdentity'">
  86. <view class="face-area">
  87. <view class="face-area--tips">
  88. <view class="face-area--tips--title">
  89. <u-text text="身份核验" color="#333333" bold size="34rpx"></u-text>
  90. </view>
  91. <view class="face-area--tips--context">
  92. <u-text text="请根据页面提示进行操作" color="#CBCBCB" size="28rpx"></u-text>
  93. </view>
  94. </view>
  95. <view class="face-area--line"></view>
  96. <view class="camera-container">
  97. <!-- #ifdef MP-WEIXIN -->
  98. <camera v-if="showcamera" class="camera" device-position="front" flash="off" resolution="low">
  99. </camera>
  100. <!-- #endif -->
  101. <!-- #ifdef MP-ALIPAY -->
  102. <camera id="faceCheck-camera" flash="off" device-position="front" @ready="faceCheckCamera"
  103. :style="[faceCheckCameraStyle]" />
  104. <cover-image src="/static/mp-alipay/cover.png" :style="[faceCheckCoverImageStyle]"></cover-image>
  105. <!-- #endif -->
  106. </view>
  107. <!-- #ifdef MP-WEIXIN -->
  108. <view class="info">
  109. <u-text v-if="showcamera" :text="tipsText" align="center"></u-text>
  110. </view>
  111. <!-- #endif -->
  112. <!-- #ifdef MP-ALIPAY -->
  113. <view v-if="!showTips" class="check-pic-result">
  114. {{ checkPicTips }}
  115. </view>
  116. <!-- #endif -->
  117. </view>
  118. <view class="precautions">
  119. <view class="precautions--tips">
  120. <view class="precautions--tips--title">
  121. <u-text text="注意事项" color="#333333" bold size="34rpx"></u-text>
  122. </view>
  123. <view class="precautions--tips--context">
  124. <u-text text="请遵守需注意事项" color="#CBCBCB" size="28rpx"></u-text>
  125. </view>
  126. </view>
  127. <view class="precautions--line"></view>
  128. <view class="precautions--context">
  129. <u-text :text="'确认'+name+'本人操作;保持正脸在取景框中根据屏幕指示完成'" color="#666666" size="24rpx"></u-text>
  130. </view>
  131. <view class="img-list">
  132. <view class="img-list--item" v-for="img in imgList" :key="img.src">
  133. <view class="img">
  134. <u-image :src="img.src" :height="img.height" :width="img.width"></u-image>
  135. </view>
  136. <view class="tips">
  137. <u-text :text="img.tips" color="#666666" size="20rpx"></u-text>
  138. </view>
  139. </view>
  140. </view>
  141. </view>
  142. <!-- #ifdef MP-WEIXIN -->
  143. <view class="btn-container">
  144. <u-button text="同意并开始验证" @click="start" color="#9e97c3"></u-button>
  145. </view>
  146. <!-- #endif -->
  147. <!-- #ifdef MP-ALIPAY -->
  148. <view class="btn">
  149. <u-button text="同意并开始验证" @click="checkFacePic" :disabled="isCheckingFace" color="#9e97c3"></u-button>
  150. </view>
  151. <!-- #endif -->
  152. </view>
  153. </view>
  154. </template>
  155. <script>
  156. import {
  157. IMG_BASE_URL,
  158. BASE_URL,
  159. } from '../../config.js'
  160. import {
  161. mapState,
  162. mapMutations
  163. } from 'vuex'
  164. import NavigateBar from '../../components/navigateBar/navigate-bar.vue';
  165. // #ifdef MP-ALIPAY
  166. // 最大图片大小为2.0M
  167. const maxPhotoSize = 2 * 1024 * 1024
  168. // OCR类型,人像面为"0",国徽面为"1"
  169. const ocrType = {
  170. face: "0",
  171. emblem: "1"
  172. }
  173. // #endif
  174. export default {
  175. components: {
  176. NavigateBar
  177. },
  178. data() {
  179. return {
  180. isMainCustomer: false,
  181. //0展示输入姓名、身份证号、手机号页面
  182. //1展示上传身份证照片页面
  183. //2展示身份核验页面
  184. step: "fillForm",
  185. //步骤 0 需要填入的信息
  186. name: '',
  187. idNumber: '',
  188. phone: '',
  189. //步骤 1 需要从身份证获取的信息
  190. idCardInfoInPage: {
  191. name: '',
  192. sex: '',
  193. nation: '',
  194. birth: '',
  195. address: '',
  196. idNumber: '',
  197. issuingAuthority: '',
  198. issuingDate: '',
  199. expiryDate: ''
  200. },
  201. idCardFrontPicPath: '../../static/idcard_upload_front.png',
  202. idCardBackPicPath: '../../static/idcard_upload_back.png',
  203. infoList: ['address', 'nation', 'sex', 'birth', 'issuingAuthority', 'issuingDate', 'expiryDate'],
  204. userInfoId: 0,
  205. // #ifdef MP-WEIXIN
  206. idCardDirection: '',
  207. // img: null,
  208. // imgData: null,
  209. idCardVKSession: null,
  210. idCardFrontUploadInfo: {
  211. imgUrl: '',
  212. imgWidth: 0,
  213. imgHeight: 0,
  214. imgOriginWidth: 0,
  215. imgOriginHeight: 0,
  216. },
  217. idCardFrontDetectInfo: {
  218. detected: false, //检测是否完成
  219. detectSuccess: false, //检测是否成功
  220. isComplete: false, //身份证是否完整
  221. label: '', //身份证方向,0 人像面,1 国徽面
  222. orientation: 0, //身份证朝向 (0 朝上 1 朝下 2 朝下 3 朝左)
  223. box: [], //身份证坐标框点数组 (0 左上点 1 右上点 2 右下点 3 左下点)
  224. },
  225. idCardBackUploadInfo: {
  226. imgUrl: '',
  227. imgWidth: 0,
  228. imgHeight: 0,
  229. imgOriginWidth: 0,
  230. imgOriginHeight: 0,
  231. },
  232. idCardBackDetectInfo: {
  233. detected: false,
  234. detectSuccess: false,
  235. isComplete: false,
  236. label: '',
  237. orientation: 0,
  238. box: [],
  239. },
  240. // showAddGuest: true,
  241. cameraEngine: null,
  242. VKSession: null,
  243. showcamera: false,
  244. tipsText: '开始身份核验',
  245. duringCameraAuth: false,
  246. isVKSupport: false,
  247. imgList: [{
  248. src: '/static/check-face-phone.png',
  249. width: '48rpx',
  250. height: '70rpx',
  251. tips: '正对手机'
  252. },
  253. {
  254. src: '/static/check-face-light.png',
  255. width: '78rpx',
  256. height: '70rpx',
  257. tips: '光线充足'
  258. },
  259. {
  260. src: '/static/check-face-face.png',
  261. width: '80rpx',
  262. height: '80rpx',
  263. tips: '脸部无遮挡'
  264. }
  265. ],
  266. pageTitle: '身份信息录入',
  267. // #endif
  268. // #ifdef MP-ALIPAY
  269. actionSheetVisible: false,
  270. actions: [{
  271. text: "拍照",
  272. key: "shoot"
  273. },
  274. {
  275. text: "从相册选择",
  276. key: "choose"
  277. }
  278. ],
  279. shootCard: false,
  280. shot: false,
  281. frontSelect: false,
  282. cardCam: null,
  283. faceCheckCam: null,
  284. fileSystem: null,
  285. cardCamWidth: 0,
  286. cardCamHigh: 0,
  287. cardCamTopGap: 0,
  288. imageStyle: {
  289. width: "500rpx",
  290. height: "350rpx",
  291. margin: "0 auto"
  292. },
  293. frontPassed: false,
  294. idCardFrontBase64: null,
  295. idCardBackBase64: null,
  296. backPassed: false,
  297. checkPicTips: "身份核验中....",
  298. screenWidth: 0,
  299. faceCheckCamTopGap: 0,
  300. showTips: true,
  301. isCheckingFace: false,
  302. faceCheckSucceed: false,
  303. // #endif
  304. };
  305. },
  306. computed: {
  307. ...mapState('m_user', ['userInfo']),
  308. ...mapState('m_business', ['checkinInfo', 'currentHotel', 'idCardInfo', 'order']),
  309. getAllInfo() {
  310. for (const info of this.infoList) {
  311. if (!this.idCardInfoInPage[info]) {
  312. return false
  313. }
  314. }
  315. return true
  316. },
  317. // #ifdef MP-ALIPAY
  318. cardCameraStyle() {
  319. let style = {}
  320. // 设置相机显示区域左右边框距屏幕左右边框为40px
  321. style.width = this.cardCamWidth + 'px'
  322. style.height = this.cardCamHigh + 'px'
  323. style.left = "40px"
  324. style.top = this.cardCamTopGap + "px"
  325. return style
  326. },
  327. faceCheckCameraStyle() {
  328. let style = {}
  329. // 设置相机显示区域左右边框距屏幕左右边框为20px
  330. let camWidth = this.screenWidth === 0 ? 0 : this.screenWidth - 20 * 2
  331. style.width = camWidth + 'px'
  332. style.height = camWidth + 'px'
  333. return style
  334. },
  335. faceCheckCoverImageStyle() {
  336. let style = {}
  337. // 设置相机遮罩图片的左右边框距屏幕左右边框为16px
  338. let imgWidth = this.screenWidth === 0 ? 0 : this.screenWidth - 16 * 2
  339. style.width = imgWidth + 'px'
  340. style.height = imgWidth + 'px'
  341. style.left = "16px"
  342. style.top = this.faceCheckCamTopGap + "px"
  343. return style
  344. }
  345. // #endif
  346. },
  347. methods: {
  348. ...mapMutations('m_business', ['updateCheckinInfo', 'updateIdCardInfo', 'updateOrder']),
  349. ...mapMutations('m_user', ['updateUserInfo']),
  350. async finishInput() {
  351. //检查格式是否正确
  352. let nameReg = /\d/;
  353. if (this.name === '' || nameReg.test(this.name)) {
  354. uni.$showMsg('姓名格式错误!')
  355. return
  356. }
  357. let idNumberReg =
  358. /^[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]$/;
  359. if (!idNumberReg.test(this.idNumber)) {
  360. uni.$showMsg('身份证号格式错误!')
  361. return
  362. }
  363. 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}$/;
  364. if (!phoneReg.test(this.phone)) {
  365. uni.$showMsg('手机号格式错误!')
  366. return
  367. }
  368. //判断此顾客信息是否已添加
  369. if (JSON.stringify(this.checkinInfo) !== '{}' && this.checkinInfo.length > 0) {
  370. for (let info of this.checkinInfo) {
  371. if (info.idNumber === this.idNumber) {
  372. uni.$showMsg('已添加此顾客,请检查填写信息')
  373. return
  374. }
  375. }
  376. }
  377. //检查该顾客是否在当前酒店入住
  378. let res = await uni.$http.post('/user/isCheckin', {
  379. idNumber: this.idNumber,
  380. hotelId: this.currentHotel.hotelId
  381. })
  382. if (res.data.code === 200 && res.data.data === true) {
  383. uni.$showMsg('该顾客已入住!')
  384. return
  385. }
  386. //判断本地缓存是否有顾客身份证信息,有则checkIdentity
  387. for (const info of this.idCardInfo) {
  388. if (info.idNumber === this.idNumber && info.name === this.name) {
  389. this.idCardInfoInPage = info
  390. this.step = 'checkIdentity'
  391. return
  392. }
  393. }
  394. //本地缓存没有顾客身份信息,到后台查询
  395. let idCardInfoQueryRes = await uni.$http.post('/user/idCardInfo', {
  396. idNumber: this.idNumber,
  397. name: this.name
  398. })
  399. //查询到,写入local storage,跳转checkIdentity
  400. if (idCardInfoQueryRes.data.code === 200 && idCardInfoQueryRes.data.data) {
  401. let info = idCardInfoQueryRes.data.data
  402. info.birth = info.birthday
  403. let keys = Object.keys(this.idCardInfoInPage)
  404. for (const key of keys) {
  405. //有数据为空则需重新上传
  406. if (!info[key]) {
  407. this.step = "uploadCard"
  408. return
  409. }
  410. this.idCardInfoInPage[key] = info[key]
  411. }
  412. let idCardInfoToUpdate = this.idCardInfo
  413. idCardInfoToUpdate.push(this.idCardInfoInPage)
  414. this.updateIdCardInfo(idCardInfoToUpdate)
  415. this.step = 'checkIdentity'
  416. return
  417. }
  418. //没查询到,跳转uploadCard,上传身份证
  419. this.step = "uploadCard"
  420. },
  421. // #ifdef MP-WEIXIN
  422. initIdCardVKSession() {
  423. this.idCardVKSession = wx.createVKSession({
  424. track: {
  425. IDCard: {
  426. mode: 2 // 照片模式
  427. }
  428. },
  429. version: 'v1',
  430. gl: this.gl
  431. })
  432. // VKSession start
  433. this.idCardVKSession.start(err => {
  434. this.idCardVKSession.on('updateAnchors', anchors => {
  435. // console.log('updateAnchors')
  436. // 处理返回的身份证信息
  437. if (anchors && anchors[0]) {
  438. // 存在数组,证明存在身份证信息
  439. const anchor = anchors[0];
  440. // console.log(anchor.isComplete, anchor.label, anchor.orientation, anchor.box);
  441. let info = {
  442. detected: true,
  443. detectSuccess: true,
  444. isComplete: anchor.isComplete,
  445. label: anchor.label,
  446. orientation: anchor.orientation,
  447. box: anchor.box,
  448. }
  449. this['idCard' + this.idCardDirection + 'DetectInfo'] = info
  450. // 裁剪信息
  451. const affineImgWidth = anchor.affineImgWidth;
  452. const affineImgHeight = anchor.affineImgHeight;
  453. const affineMat = anchor.affineMat;
  454. // 存在裁剪信息,进行身份证裁剪处理
  455. if (affineImgWidth && affineImgHeight && affineMat) {
  456. // console.log(affineImgWidth, affineImgHeight, affineMat);
  457. const cropIDcardImg = this.getCropIDcard(affineImgWidth, affineImgHeight,
  458. affineMat);
  459. // console.log(cropIDcardImg)
  460. }
  461. }
  462. })
  463. this.idCardVKSession.on('removeAnchors', anchors => {
  464. // console.log("anchor remove")
  465. // 图片没有识别到身份证
  466. this['idCard' + this.idCardDirection + 'DetectInfo'].detected = true
  467. this['idCard' + this.idCardDirection + 'DetectInfo'].detectSuccess = false
  468. })
  469. });
  470. },
  471. async setImageUploadInfo(url) {
  472. const fixWidth = 300
  473. let imageInfo = await uni.getImageInfo({
  474. src: url
  475. // ,
  476. // success: (image) => {
  477. // console.log(image)
  478. // let height = image.height
  479. // let width = image.width
  480. // let info = {
  481. // imgUrl: url,
  482. // imgWidth: fixWidth,
  483. // imgHeight: (fixWidth / width) * height,
  484. // imgOriginWidth: width,
  485. // imgOriginHeight: height
  486. // }
  487. // this['idCard' + this.idCardDirection + 'UploadInfo'] = info
  488. // }
  489. })
  490. let height = imageInfo[1].height
  491. let width = imageInfo[1].width
  492. let uploadInfo = {
  493. imgUrl: url,
  494. imgWidth: fixWidth,
  495. imgHeight: (fixWidth / width) * height,
  496. imgOriginWidth: width,
  497. imgOriginHeight: height
  498. }
  499. this['idCard' + this.idCardDirection + 'UploadInfo'] = uploadInfo
  500. },
  501. getCropIDcard(affineImgWidth, affineImgHeight, affineMat) {
  502. // console.log('start getCropIDcard')
  503. let infoName = 'idCard' + this.idCardDirection + 'UploadInfo'
  504. const canvas = wx.createOffscreenCanvas({
  505. type: '2d',
  506. width: affineImgWidth,
  507. height: affineImgHeight,
  508. })
  509. const context = canvas.getContext('2d')
  510. context.clearRect(0, 0, affineImgWidth, affineImgHeight);
  511. /*
  512. * affineMat 3x3仿射变换矩阵,行主序
  513. * [0 1 2
  514. * 3 4 5
  515. * 6 7 8]
  516. */
  517. /*
  518. * canvas 2d setTransform
  519. * setTransform(a, b, c, d, e, f)
  520. * [a c e
  521. * b d f
  522. * 0 0 1]
  523. */
  524. context.setTransform(
  525. Number(affineMat[0]), Number(affineMat[3]), Number(affineMat[1]),
  526. Number(affineMat[4]), Number(affineMat[2]), Number(affineMat[5])
  527. );
  528. // console.log(this.img, this[infoName].imgOriginWidth, this[infoName].imgOriginHeight)
  529. context.drawImage(this.img, 0, 0, this[infoName].imgOriginWidth, this[infoName].imgOriginHeight)
  530. const imgUrl = canvas.toDataURL()
  531. this[infoName].imgUrl = imgUrl
  532. this['idCard' + this.idCardDirection + 'PicPath'] = imgUrl
  533. return imgUrl;
  534. },
  535. async detectIdCard() {
  536. let infoName = 'idCard' + this.idCardDirection + 'UploadInfo'
  537. if (this[infoName].imgUrl) {
  538. const canvas = wx.createOffscreenCanvas({
  539. type: '2d',
  540. width: this[infoName].imgOriginWidth,
  541. height: this[infoName].imgOriginHeight,
  542. })
  543. const context = canvas.getContext('2d')
  544. const img = canvas.createImage()
  545. // 使用中的 图片对象
  546. this.img = img;
  547. await new Promise(resolve => {
  548. img.onload = resolve
  549. img.src = this[infoName].imgUrl
  550. })
  551. context.clearRect(0, 0, this[infoName].imgOriginWidth, this[infoName].imgOriginHeight)
  552. context.drawImage(img, 0, 0, this[infoName].imgOriginWidth, this[infoName].imgOriginHeight)
  553. // 使用中的 image ArrayBuffer
  554. this.imgData = context.getImageData(0, 0, this[infoName].imgOriginWidth, this[infoName]
  555. .imgOriginHeight)
  556. // console.log('[frameBuffer] --> ', this.imgData.data.buffer)
  557. // console.log('this.session.detectIDCard', this.idCardVKSession.detectIDCard)
  558. // console.log('width', this[infoName].imgOriginWidth)
  559. // console.log('height', this[infoName].imgOriginHeight)
  560. this.idCardVKSession.detectIDCard({
  561. // 识别身份证图片的信息
  562. frameBuffer: this.imgData.data.buffer,
  563. width: this[infoName].imgOriginWidth,
  564. height: this[infoName].imgOriginHeight,
  565. // 是否获取裁剪图片信息
  566. getAffineImg: true,
  567. })
  568. }
  569. },
  570. async afterIdCardRead(event) {
  571. console.log('afterIdCardRead', event)
  572. //正面还是反面
  573. this.idCardDirection = event.name
  574. await this.setImageUploadInfo(event.file.url)
  575. await this.detectIdCard()
  576. let detectInfo = this['idCard' + this.idCardDirection + 'DetectInfo']
  577. //图片中不包含身份证
  578. if (!detectInfo.detectSuccess) {
  579. uni.showModal({
  580. title: '图片中不包含身份证,请重新上传',
  581. showCancel: false
  582. })
  583. return
  584. }
  585. if (!detectInfo.isComplete) {
  586. uni.showModal({
  587. title: '身份证照片不完整,请重新上传',
  588. showCancel: false
  589. })
  590. return
  591. }
  592. if ((this.idCardDirection === 'Front' && detectInfo.label !== 0) ||
  593. (this.idCardDirection === 'Back' && detectInfo.label !== 1)) {
  594. uni.showModal({
  595. title: '身份证面错误,请重新上传',
  596. showCancel: false
  597. })
  598. return
  599. }
  600. uni.showLoading({
  601. title: '上传中',
  602. mask: true
  603. })
  604. try {
  605. let filePath = this['idCard' + this.idCardDirection + 'PicPath']
  606. let res = await uni.$http.post('/user/idCardOcr', {
  607. image: filePath.split(',')[1],
  608. ocrType: detectInfo.label,
  609. imageType: 'BASE64'
  610. })
  611. if (res.data.data.imageStatus !== 'normal') {
  612. uni.showModal({
  613. content: '获取信息失败,请检查图片并重新上传',
  614. showCancel: false,
  615. })
  616. return
  617. }
  618. if (!this.name) {
  619. this.name = res.data.data.name
  620. }
  621. if (!this.idNumber) {
  622. this.idNumber = res.data.data.cardNum
  623. }
  624. if (event.name === 'Front') {
  625. if (res.data.data.cardNum != this.idNumber || res.data.data.name != this.name) {
  626. uni.showModal({
  627. content: '填写信息与身份证不一致',
  628. showCancel: false,
  629. complete: () => {
  630. this.step = "fillForm"
  631. this.idCardFrontPicPath =
  632. '../../static/upload_front.png'
  633. },
  634. })
  635. return
  636. }
  637. this.idCardFrontBase64 = filePath.split(',')[1]
  638. this.idCardInfoInPage.name = res.data.data.name
  639. this.idCardInfoInPage.sex = res.data.data.sex
  640. this.idCardInfoInPage.nation = res.data.data.nation
  641. this.idCardInfoInPage.birth = res.data.data.birth
  642. this.idCardInfoInPage.address = res.data.data.address
  643. this.idCardInfoInPage.idNumber = res.data.data.cardNum
  644. } else {
  645. this.idCardBackBase64 = filePath.split(',')[1]
  646. this.idCardInfoInPage.issuingAuthority = res.data.data.issuingAuthority
  647. this.idCardInfoInPage.issuingDate = res.data.data.issuingDate
  648. this.idCardInfoInPage.expiryDate = res.data.data.expiryDate
  649. }
  650. } catch (err) {
  651. uni.showModal({
  652. title: err.message
  653. })
  654. } finally {
  655. uni.hideLoading()
  656. }
  657. },
  658. oversize() {
  659. uni.$showMsg('图片超出允许大小(1.5M)')
  660. },
  661. // #endif
  662. async gotoCheckFace() {
  663. //静态检测
  664. if (this.userInfo.staticFaceCheck === true) {
  665. uni.navigateTo({
  666. url: `/subpkg_checkin/staticFaceCheck/staticFaceCheck?idNumber=${this.idNumber}&name=${this.name}&phone=${this.phone}`
  667. })
  668. } else {
  669. // #ifdef MP-WEIXIN
  670. // const accountInfo = wx.getAccountInfoSync();
  671. // const env = accountInfo.miniProgram.envVersion
  672. // if (env !== "release") {
  673. // let faceRes = await uni.request({
  674. // url: IMG_BASE_URL + '/test_face_base64.txt',
  675. // method: 'GET'
  676. // })
  677. // let faceBase64 = faceRes[1].data
  678. // this.checkinInfo[this.checkinInfo.length] = {
  679. // name: this.name,
  680. // idNumber: this.idNumber,
  681. // phone: this.phone,
  682. // faceData: faceBase64
  683. // }
  684. // this.updateCheckinInfo(this.checkinInfo)
  685. // uni.navigateTo({
  686. // url: '/subpkg_checkin/confirmOrder/confirmOrder'
  687. // })
  688. // }
  689. // #endif
  690. // #ifdef MP-ALIPAY
  691. this.step = 'checkIdentity'
  692. // #endif
  693. }
  694. },
  695. async finishIdCardUpload() {
  696. if (this.getAllInfo) {
  697. //判断此顾客信息是否已添加
  698. if (JSON.stringify(this.checkinInfo) !== '{}' && this.checkinInfo.length > 0) {
  699. for (let info of this.checkinInfo) {
  700. if (info.idNumber === this.idNumber) {
  701. uni.$showMsg('已添加此顾客,请检查填写信息')
  702. return
  703. }
  704. }
  705. }
  706. //检查该顾客是否在当前酒店入住
  707. let res = await uni.$http.post('/user/isCheckin', {
  708. idNumber: this.idNumber,
  709. hotelId: this.currentHotel.hotelId
  710. })
  711. if (res.data.code === 200 && res.data.data === true) {
  712. uni.$showMsg('该顾客已入住!')
  713. return
  714. }
  715. this.step = 'checkIdentity'
  716. } else {
  717. uni.$showMsg('请检查身份证照片')
  718. }
  719. },
  720. // #ifdef MP-ALIPAY
  721. async handleAction(item, e) {
  722. if (item.key === 'shoot') {
  723. this.shootCard = true
  724. } else if (item.key === 'choose') {
  725. await this.handleChooseImageAndGetInfo()
  726. }
  727. },
  728. handleSheetClose(e) {
  729. // console.log("handleSheetClose", e)
  730. this.actionSheetVisible = false
  731. },
  732. handleUploadFront() {
  733. if (this.frontPassed) {
  734. uni.$showMsg('身份证正面已核验通过')
  735. return
  736. }
  737. this.frontSelect = true
  738. this.actionSheetVisible = true
  739. },
  740. handleUploadBack() {
  741. if (this.backPassed) {
  742. uni.$showMsg('身份证背面已核验通过')
  743. return
  744. }
  745. this.frontSelect = false
  746. this.actionSheetVisible = true
  747. },
  748. async cameraContext() {
  749. this.cardCam = await my.createCameraContext('card-camera');
  750. },
  751. async faceCheckCamera() {
  752. this.faceCheckCam = await my.createCameraContext('faceCheck-camera');
  753. },
  754. async takePhotoAndGetInfo() {
  755. this.shot = true
  756. const photo = await this.cardCam.takePhoto({
  757. quality: 'normal',
  758. })
  759. console.log("photo", photo);
  760. const {
  761. picWidth,
  762. picHeight,
  763. size
  764. } = photo
  765. console.log("picWidth", picWidth, "picHeight", picHeight, "size", size);
  766. let picPath = photo.tempImagePath
  767. if (size > maxPhotoSize) {
  768. uni.showModal({
  769. content: '图片大小超过2MB,请重新拍照或选择照片上传。',
  770. showCancel: false
  771. })
  772. return
  773. }
  774. // picWidth < picHeight 需要旋转图片
  775. if (picWidth < picHeight) {
  776. const offCanvas = my.createOffscreenCanvas()
  777. const offCtx = offCanvas.getContext('2d')
  778. // console.log("offCtx", offCtx);
  779. // 用 离屏canvas 创建 Image
  780. const image = offCanvas.createImage()
  781. await new Promise((resolve, reject) => {
  782. image.src = photo.tempImagePath
  783. image.onload = function() {
  784. offCanvas.width = image.height
  785. offCanvas.height = image.width
  786. offCtx.rotate(270 * Math.PI / 180);
  787. offCtx.translate(-offCanvas.height, 0);
  788. // 将 Image 画到 离屏canvas 上
  789. offCtx.drawImage(image, 0, 0, image.width, image.height)
  790. resolve()
  791. }
  792. })
  793. // console.log("offCanvas", offCanvas);
  794. picPath = offCanvas.toDataURL("image/jpeg")
  795. // console.log("canDataUrl", picPath);
  796. }
  797. let _ocrType
  798. if (this.frontSelect) {
  799. this.idCardFrontPicPath = picPath
  800. _ocrType = ocrType.face
  801. } else {
  802. this.idCardBackPicPath = picPath
  803. _ocrType = ocrType.emblem
  804. }
  805. this.shootCard = false
  806. // 完成照片获取工作,开始和后端沟通获取照片上的信息
  807. this.shot = false
  808. // 打开loading模态框,处理图片
  809. const {
  810. data: photoBase64
  811. } = await this.fileSystem.readFile({
  812. filePath: photo.tempImagePath,
  813. encoding: "base64"
  814. })
  815. // console.log("photoBase64", photoBase64);
  816. await this.idCardOCR(photoBase64, _ocrType)
  817. },
  818. async handleChooseImageAndGetInfo() {
  819. const img = await my.chooseImage({
  820. sizeType: ['compressed'],
  821. sourceType: ['album'],
  822. })
  823. // console.log("ChooseImage", img);
  824. const imgSize = img.tempFiles[0].size
  825. if (imgSize > maxPhotoSize) {
  826. uni.showModal({
  827. content: '图片大小超过2MB,请重新选择照片或拍照上传。',
  828. showCancel: false
  829. })
  830. return
  831. }
  832. let _ocrType
  833. if (this.frontSelect) {
  834. this.idCardFrontPicPath = img.tempFilePaths[0]
  835. _ocrType = ocrType.face
  836. } else {
  837. this.idCardBackPicPath = img.tempFilePaths[0]
  838. _ocrType = ocrType.emblem
  839. }
  840. const {
  841. data: photoBase64
  842. } = await this.fileSystem.readFile({
  843. filePath: img.tempFilePaths[0],
  844. encoding: "base64"
  845. })
  846. // console.log("photoBase64", photoBase64);
  847. await this.idCardOCR(photoBase64, _ocrType)
  848. },
  849. async idCardOCR(imgBase64, _ocrType) {
  850. // 在进行身份证识别时,弹loading框,不让进行任何操作
  851. my.showLoading({
  852. content: "身份证信息识别中...",
  853. mask: true
  854. })
  855. const ocrBaseUrl = BASE_URL.slice(0, -11)
  856. const ocrData = {
  857. image: imgBase64,
  858. imageType: "BASE64",
  859. ocrType: _ocrType
  860. }
  861. const {
  862. data: ocrRes
  863. } = await my.request({
  864. url: ocrBaseUrl + "/verification/idCardOcr",
  865. method: "POST",
  866. data: ocrData
  867. })
  868. // console.log("ocrRes", ocrRes);
  869. if (!ocrRes.success) {
  870. uni.showModal({
  871. content: '身份证信息识别失败,请重新选择照片或拍照上传。',
  872. showCancel: false
  873. })
  874. my.hideLoading()
  875. return
  876. }
  877. const {
  878. data
  879. } = ocrRes
  880. // console.log(data);
  881. if (_ocrType === ocrType.face) {
  882. if (!this.name) {
  883. this.name = data.name
  884. }
  885. if (!this.idNumber) {
  886. this.idNumber = data.cardNum
  887. }
  888. if (this.idNumber !== data.cardNum || this.name !== data.name) {
  889. uni.showModal({
  890. content: '身份信息不一致,请核实后重新操作',
  891. showCancel: false,
  892. complete: () => {
  893. this.step = "fillForm"
  894. this.idCardFrontPicPath = '/static/idcard_upload_front.png'
  895. this.backPassed = false
  896. my.hideLoading()
  897. }
  898. })
  899. return
  900. }
  901. this.idCardInfoInPage.name = data.name
  902. this.idCardInfoInPage.sex = data.sex
  903. this.idCardInfoInPage.nation = data.nation
  904. this.idCardInfoInPage.birth = data.birth
  905. this.idCardInfoInPage.address = data.address
  906. this.idCardInfoInPage.idNumber = data.cardNum
  907. this.idCardFrontBase64 = imgBase64
  908. this.frontPassed = true
  909. } else if (_ocrType === ocrType.emblem) {
  910. this.idCardInfoInPage.issuingAuthority = data.issuingAuthority
  911. this.idCardInfoInPage.issuingDate = data.issuingDate
  912. this.idCardInfoInPage.expiryDate = data.expiryDate
  913. this.idCardBackBase64 = imgBase64
  914. this.backPassed = true
  915. }
  916. my.hideLoading()
  917. },
  918. async checkFacePic() {
  919. const userSetting = await uni.getSetting()
  920. // console.log("userSetting", userSetting);
  921. let camAuth = userSetting[1].authSetting['camera'] ? userSetting[1].authSetting['camera'] : false
  922. while (!camAuth) {
  923. await new Promise(async (resolve, reject) => {
  924. await uni.showModal({
  925. title: "温馨提示",
  926. content: "身份核验功能需要使用您的相机,请授权后重新点击核验。",
  927. success: async (res) => {
  928. if (res.confirm) {
  929. await uni.openSetting().then(res => {
  930. console.log("openSetting", res);
  931. camAuth = res[1].authSetting['camera'] ? res[1]
  932. .authSetting['camera'] : false
  933. resolve()
  934. })
  935. }
  936. }
  937. })
  938. })
  939. setTimeout(() => {}, 200)
  940. }
  941. // console.log("进行了相机授权操作");
  942. this.checkPicTips = "身份核验中...."
  943. this.showTips = false
  944. this.isCheckingFace = true
  945. let succeedImgBase64
  946. while (!this.faceCheckSucceed) {
  947. // console.log("开始takePhoto进行人脸检测", this.faceCheckCam);
  948. const photo = await this.faceCheckCam.takePhoto({
  949. quality: 'normal',
  950. })
  951. // console.log("完成takePhoto", photo.tempImagePath);
  952. const {
  953. data: photoBase64
  954. } = await this.fileSystem.readFile({
  955. filePath: photo.tempImagePath,
  956. encoding: "base64"
  957. })
  958. // console.log("photoBase64", photoBase64);
  959. let checkPicRes = await uni.$http.post("/faceVerification/checkPic", {
  960. hotelId: this.currentHotel.hotelId,
  961. faceData: photoBase64,
  962. })
  963. // console.log("checkPicRes", checkPicRes);
  964. if (!checkPicRes.data.success) {
  965. // console.log("checkPicRes.data", checkPicRes.data.msg.split("原因:")[1]);
  966. this.checkPicTips = checkPicRes.data.msg.split("原因:")[1] + "请将面部完整放入拍摄区域。"
  967. } else {
  968. succeedImgBase64 = photoBase64
  969. this.faceCheckSucceed = checkPicRes.data.success
  970. }
  971. setTimeout(() => {}, 100)
  972. }
  973. // 进行云极人证比对
  974. await this.afterSuccessCheckPicAlipay(succeedImgBase64)
  975. },
  976. async afterSuccessCheckPicAlipay(photoBase64) {
  977. if (this.userInfo.skipIdMatching === true) {
  978. this.checkPicTips = "身份核验成功,将跳转确认订单页面"
  979. let infoFromIdCard = {}
  980. this.infoList.forEach(info => {
  981. infoFromIdCard[info] = that[info]
  982. })
  983. let currentCheckinInfo = {
  984. name: this.name,
  985. idNumber: this.idNumber,
  986. phone: this.phone,
  987. faceData: photoBase64
  988. }
  989. currentCheckinInfo = {
  990. ...currentCheckinInfo,
  991. ...infoFromIdCard
  992. }
  993. this.checkinInfo.push(currentCheckinInfo)
  994. this.updateCheckinInfo(this.checkinInfo)
  995. let currentGuestInfo = {
  996. name: this.name,
  997. idNumber: this.idNumber,
  998. }
  999. let i
  1000. for (i = 0; i < this.guestInfo.length; i++) {
  1001. if (this.guestInfo[i].idNumber === this.idNumber) {
  1002. this.guestInfo[i] = {
  1003. ...currentGuestInfo,
  1004. ...infoFromIdCard
  1005. }
  1006. this.updateGuestInfo(this.guestInfo)
  1007. }
  1008. }
  1009. if (i === this.guestInfo.length) {
  1010. this.guestInfo.push({
  1011. ...currentGuestInfo,
  1012. ...infoFromIdCard
  1013. })
  1014. this.updateGuestInfo(this.guestInfo)
  1015. }
  1016. setTimeout(() => uni.reLaunch({
  1017. url: '/subpkg_checkin/confirmOrder/confirmOrder'
  1018. }), 1000);
  1019. } else {
  1020. uni.showLoading({
  1021. title: '正在身份核验,请稍后',
  1022. });
  1023. let yunjiFaceCheckInfo = {
  1024. idNo: this.idNumber,
  1025. name: this.name,
  1026. image: photoBase64,
  1027. };
  1028. let checkRes = await uni.$http.post(
  1029. '/faceVerification/yunjiVerification',
  1030. yunjiFaceCheckInfo
  1031. );
  1032. if (checkRes.data.success) {
  1033. let infoFromIdCard = {}
  1034. this.infoList.forEach(info => {
  1035. infoFromIdCard[info] = this.idCardInfoInPage[info]
  1036. })
  1037. let currentCheckinInfo = {
  1038. name: this.name,
  1039. idNumber: this.idNumber,
  1040. faceData: photoBase64,
  1041. phone: this.phone,
  1042. ...infoFromIdCard
  1043. }
  1044. //更新local storage 中的入住信息
  1045. let checkinInfoToUpdate = this.checkinInfo
  1046. checkinInfoToUpdate.push(currentCheckinInfo)
  1047. this.updateCheckinInfo(checkinInfoToUpdate)
  1048. //更新local storage 中的身份证信息
  1049. let idCardInfoToUpdate = this.idCardInfo
  1050. idCardInfoToUpdate.push(this.idCardInfoInPage)
  1051. this.updateIdCardInfo(idCardInfoToUpdate)
  1052. //如果上传过照片则更新服务器中的身份证信息
  1053. if (this.frontPassed && this.backPassed) {
  1054. uni.$http.post('/idCardInfo', {
  1055. ...this.idCardInfoInPage,
  1056. birthday: this.idCardInfoInPage.birth,
  1057. idCardFrontBase64: this.idCardFrontBase64,
  1058. idCardBackBase64: this.idCardBackBase64
  1059. })
  1060. }
  1061. if (this.isMainCustomer) {
  1062. //如果是主入住人,且当前账号姓名和身份证号为空,则更新账号信息为主入住人信息
  1063. if (!this.userInfo.name || !this.userInfo.idNumber) {
  1064. this.userInfo.name = this.name
  1065. this.userInfo.idNumber = this.idNumber
  1066. this.updateUserInfo(this.userInfo)
  1067. uni.$http.put(`/userInfo/${this.userInfo.id}`, this.userInfo)
  1068. }
  1069. //更新订单预定人信息为主入住人信息
  1070. let orderToUpdate = this.order
  1071. orderToUpdate.name = this.name
  1072. orderToUpdate.phone = this.phone
  1073. this.updateOrder(orderToUpdate)
  1074. }
  1075. uni.hideLoading();
  1076. uni.$showMsg('身份核验通过!')
  1077. setTimeout(() => uni.reLaunch({
  1078. url: '/subpkg_checkin/confirmOrder/confirmOrder'
  1079. }), 1000)
  1080. } else {
  1081. uni.hideLoading()
  1082. this.isCheckingFace = false
  1083. this.checkPicTips = "身份核验失败,请重新进行"
  1084. }
  1085. }
  1086. },
  1087. // #endif
  1088. // #ifdef MP-WEIXIN
  1089. start() {
  1090. console.log('调用start');
  1091. this.idCardVKSession.destroy()
  1092. if (!this.duringCameraAuth && this.isVKSupport) {
  1093. this.getCameraAuth()
  1094. }
  1095. },
  1096. getCameraAuth() {
  1097. console.log('getCameraAuth')
  1098. this.duringCameraAuth = true
  1099. let that = this
  1100. wx.getSetting({
  1101. success: (res) => {
  1102. console.log('getSetting, res : ')
  1103. console.log(res)
  1104. if (!res.authSetting['scope.camera']) {
  1105. wx.authorize({
  1106. scope: 'scope.camera',
  1107. success(res) {
  1108. console.log('authorize success, res : ')
  1109. console.log(res)
  1110. that.showcamera = true
  1111. },
  1112. fail: (res) => {
  1113. console.log('authorize fail, res : ')
  1114. console.log(res)
  1115. wx.showModal({
  1116. title: '提示',
  1117. content: '尚未进行授权,功能将无法使用',
  1118. cancelText: '取消',
  1119. confirmText: '授权',
  1120. success(res) {
  1121. console.log(res);
  1122. if (res.confirm) {
  1123. wx.openSetting({
  1124. //这里的方法是调到一个添加权限的页面,这里可以测试在拒绝授权的情况下设置中是否存在相机选项
  1125. success: (res) => {
  1126. if (!res.authSetting[
  1127. 'scope.camera'
  1128. ]) {
  1129. this.getCameraAuth()
  1130. } else {
  1131. that.showcamera =
  1132. true
  1133. }
  1134. },
  1135. fail: function() {
  1136. console.log(
  1137. '相机授权设置失败');
  1138. },
  1139. });
  1140. } else if (res.cancel) {
  1141. console.log('用户点击取消');
  1142. wx.showToast({
  1143. title: '您已取消授权',
  1144. icon: 'error',
  1145. duration: 1000,
  1146. });
  1147. setTimeout(function() {
  1148. wx.navigateBack();
  1149. }, 1000);
  1150. }
  1151. }
  1152. })
  1153. }
  1154. })
  1155. } else {
  1156. that.showcamera = true
  1157. }
  1158. that.initData()
  1159. }
  1160. })
  1161. this.duringCameraAuth = false
  1162. },
  1163. //visionkit人脸必须函数
  1164. async detectFace(frame) {
  1165. console.log('frame', frame.data);
  1166. this.faceVKSession.detectFace({
  1167. frameBuffer: frame.data,
  1168. width: frame.width,
  1169. height: frame.height,
  1170. scoreThreshold: 0.8,
  1171. sourceType: 0,
  1172. modelMode: 1,
  1173. });
  1174. },
  1175. //初始化相机引擎
  1176. initData() {
  1177. let that = this;
  1178. console.log('before createCameraContext')
  1179. //使用visionkit
  1180. that.cameraEngine = wx.createCameraContext();
  1181. console.log('before createCameraContext')
  1182. let count = 0;
  1183. //初始化相机
  1184. const listener = that.cameraEngine.onCameraFrame((frame) => {
  1185. count++;
  1186. //每十帧分析一次
  1187. if (count === 10) {
  1188. this.detectFace(frame);
  1189. count = 0;
  1190. }
  1191. });
  1192. //开始监听数据帧
  1193. listener.start();
  1194. //创建VK对象
  1195. that.faceVKSession = wx.createVKSession({
  1196. version: 'v1',
  1197. track: {
  1198. plane: {
  1199. mode: 1,
  1200. },
  1201. face: {
  1202. mode: 2,
  1203. },
  1204. },
  1205. });
  1206. //启动VK对象
  1207. that.faceVKSession.start((errno) => {
  1208. console.log('faceVKSession.start errno', errno);
  1209. if (errno) {
  1210. wx.showModal({
  1211. title: '提示',
  1212. content: '网络错误,请退出后重试',
  1213. showCancel: false,
  1214. confirmText: '确定',
  1215. success(res) {
  1216. console.log(res);
  1217. if (res.confirm) {
  1218. wx.navigateBack();
  1219. }
  1220. },
  1221. });
  1222. return
  1223. }
  1224. console.log('faceVKSession start')
  1225. that.faceVKSession.on('updateAnchors', (anchors) => {
  1226. console.log('anchors', anchors);
  1227. console.log('anchors.length', anchors.length);
  1228. anchors.forEach((anchor) => {
  1229. console.log('anchor.points', anchor.points);
  1230. console.log('anchor.origin', anchor.origin);
  1231. console.log('anchor.size', anchor.size);
  1232. console.log('anchor.angle', anchor.angle);
  1233. console.log('anchor', anchor.confidence);
  1234. if (anchors.length > 1) {
  1235. that.tipsText = '请保证只有一个人';
  1236. } else {
  1237. const {
  1238. pitch,
  1239. roll,
  1240. yaw
  1241. } = anchor.angle;
  1242. const standard = 0.3;
  1243. if (
  1244. Math.abs(pitch) >= standard ||
  1245. Math.abs(roll) >= standard ||
  1246. Math.abs(yaw) >= standard
  1247. ) {
  1248. that.tipsText = '请平视摄像头';
  1249. } else if (
  1250. anchor.origin.x < 0.15 ||
  1251. anchor.origin.x > 0.3 ||
  1252. anchor.origin.y < 0.2 ||
  1253. anchor.origin.y > 0.45
  1254. ) {
  1255. this.tipsText = '请将人脸对准中心位置';
  1256. } else if (
  1257. anchor.confidence[0] <= 0.8 ||
  1258. anchor.confidence[1] <= 0.8 ||
  1259. anchor.confidence[2] <= 0.8 ||
  1260. anchor.confidence[3] <= 0.8 ||
  1261. anchor.confidence[4] <= 0.8
  1262. ) {
  1263. that.tipsText = '请勿遮挡五官';
  1264. } else {
  1265. listener.stop();
  1266. that.tipsText = '即将拍照,请保持!';
  1267. setTimeout(function() {
  1268. that.handleTakePhotoClick();
  1269. }, 1000);
  1270. return;
  1271. }
  1272. }
  1273. });
  1274. });
  1275. });
  1276. },
  1277. // 拍照
  1278. handleTakePhotoClick() {
  1279. this.tipsText = '';
  1280. uni.showLoading({
  1281. title: '正在身份核验,请稍后',
  1282. });
  1283. this.cameraEngine.takePhoto({
  1284. quality: 'normal',
  1285. success: ({
  1286. tempImagePath
  1287. }) => {
  1288. let mybase64 = wx
  1289. .getFileSystemManager()
  1290. .readFileSync(tempImagePath, 'base64');
  1291. this.afterRead(mybase64);
  1292. this.showcamera = false
  1293. },
  1294. });
  1295. },
  1296. //上传
  1297. async afterRead(mybase64) {
  1298. let that = this;
  1299. let res = await uni.$http.post('/user/faceCheckAll', {
  1300. hotelId: this.currentHotel.hotelId,
  1301. imageBase64: mybase64,
  1302. name: this.name,
  1303. idNumber: this.idNumber
  1304. })
  1305. if (res.data.code === 200 && res.data.success === true) {
  1306. let infoFromIdCard = {}
  1307. this.infoList.forEach(info => {
  1308. infoFromIdCard[info] = this.idCardInfoInPage[info]
  1309. })
  1310. let currentCheckinInfo = {
  1311. name: this.name,
  1312. idNumber: this.idNumber,
  1313. faceData: mybase64,
  1314. phone: this.phone,
  1315. ...infoFromIdCard
  1316. }
  1317. //更新local storage 中的入住信息
  1318. let checkinInfoToUpdate = this.checkinInfo
  1319. checkinInfoToUpdate.push(currentCheckinInfo)
  1320. this.updateCheckinInfo(checkinInfoToUpdate)
  1321. //更新local storage 中的身份证信息
  1322. let idCardInfoToUpdate = this.idCardInfo
  1323. idCardInfoToUpdate.push(this.idCardInfoInPage)
  1324. this.updateIdCardInfo(idCardInfoToUpdate)
  1325. //如果上传过照片则更新服务器中的身份证信息
  1326. if (this.idCardFrontDetectInfo.detected && this.idCardBackDetectInfo
  1327. .detected) {
  1328. uni.$http.post('/user/idCardInfo/add', {
  1329. ...this.idCardInfoInPage,
  1330. birthday: this.idCardInfoInPage.birth,
  1331. idCardFrontBase64: this.idCardFrontPicPath.split(',')[1],
  1332. idCardBackBase64: this.idCardBackPicPath.split(',')[1]
  1333. })
  1334. }
  1335. if (this.isMainCustomer) {
  1336. //如果是主入住人,且当前账号姓名和身份证号为空,则更新账号信息为主入住人信息
  1337. if (!this.userInfo.name || !this.userInfo.idNumber) {
  1338. this.userInfo.name = this.name
  1339. this.userInfo.idNumber = this.idNumber
  1340. this.updateUserInfo(this.userInfo)
  1341. uni.$http.put(`/user`, {
  1342. name: this.name,
  1343. idNumber: this.idNumber
  1344. })
  1345. }
  1346. //更新订单预定人信息为主入住人信息
  1347. let orderToUpdate = this.order
  1348. orderToUpdate.name = this.name
  1349. orderToUpdate.phone = this.phone
  1350. this.updateOrder(orderToUpdate)
  1351. }
  1352. uni.hideLoading();
  1353. uni.$showMsg('身份核验通过!')
  1354. setTimeout(() => uni.reLaunch({
  1355. url: '/subpkg_checkin/confirmOrder/confirmOrder'
  1356. }), 1000)
  1357. } else {
  1358. uni.hideLoading()
  1359. uni.showModal({
  1360. content: `身份核验失败,${res.data.msg},请重试`,
  1361. showCancel: false,
  1362. success: function(res) {
  1363. if (res.confirm) {
  1364. console.log('用户点击确定');
  1365. that.initData();
  1366. }
  1367. },
  1368. });
  1369. }
  1370. },
  1371. // #endif
  1372. },
  1373. async onLoad() {
  1374. let pages = getCurrentPages()
  1375. let beforePage = pages[pages.length - 2]
  1376. //不是从确定订单页面点击添加顾客跳转过来,设置信息为当前账户的信息,清空入住信息
  1377. if (beforePage.route !== 'subpkg_checkin/confirmOrder/confirmOrder') {
  1378. this.name = this.userInfo.name
  1379. this.idNumber = this.userInfo.idNumber
  1380. this.phone = this.userInfo.phone
  1381. this.updateCheckinInfo([])
  1382. this.isMainCustomer = true
  1383. } else {
  1384. this.isMainCustomer = false
  1385. }
  1386. //是主入住人且姓名和身份证号为空,判断为新用户,直接跳转至上传身份证照片页面
  1387. if (this.isMainCustomer && (!this.userInfo.name || !this.userInfo.idNumber)) {
  1388. this.step = 'uploadCard'
  1389. }
  1390. // #ifdef MP-WEIXIN
  1391. this.isVKSupport = wx.isVKSupport('v1')
  1392. if (!this.isVKSupport) {
  1393. uni.showModal({
  1394. content: '微信版本过低,请升级至最新版本',
  1395. showCancel: false,
  1396. })
  1397. }
  1398. // #endif
  1399. // #ifdef MP-ALIPAY
  1400. let alipaySystemInfo = await uni.getSystemInfo()
  1401. this.screenWidth = alipaySystemInfo[1].screen.width
  1402. // 设置身份证拍照相机显示区域距边界40px
  1403. this.cardCamWidth = alipaySystemInfo[1].screen.width - 40 * 2
  1404. this.cardCamHigh = Number(865 / 548 * this.cardCamWidth).toFixed(0)
  1405. const menuButton = await uni.getMenuButtonBoundingClientRect()
  1406. // 身份证拍照相机top距navBar底部10px
  1407. this.cardCamTopGap = menuButton.top + menuButton.height + 8 + 10
  1408. const factor = this.screenWidth / 750
  1409. const tipsHight = 106 * factor
  1410. this.faceCheckCamTopGap = menuButton.top + menuButton.height + 8 + tipsHight
  1411. this.fileSystem = my.getFileSystemManager();
  1412. // #endif
  1413. },
  1414. // #ifdef MP-WEIXIN
  1415. onShow() {
  1416. this.showAddGuest = true
  1417. this.pageTitle = '身份信息录入'
  1418. },
  1419. onReady() {
  1420. this.initIdCardVKSession()
  1421. },
  1422. onShareAppMessage(info) {
  1423. return {
  1424. title: '源享住',
  1425. path: 'pages/quickLogin/quickLogin',
  1426. imageUrl: '/static/logo.png'
  1427. }
  1428. },
  1429. // #endif
  1430. }
  1431. </script>
  1432. <style lang="scss">
  1433. .btn-container {
  1434. position: fixed;
  1435. bottom: 90rpx;
  1436. left: 30rpx;
  1437. right: 30rpx;
  1438. .u-button__text {
  1439. font-size: 30rpx !important;
  1440. }
  1441. }
  1442. page {
  1443. background: #EFEFF4;
  1444. .container {
  1445. .step-zero {
  1446. .tips {
  1447. margin: 30rpx;
  1448. }
  1449. .u-form {
  1450. margin-top: 10rpx;
  1451. background-color: #FFFFFF;
  1452. .u-form-item {
  1453. line-height: 50rpx;
  1454. .u-form-item__body {
  1455. margin-left: 32rpx;
  1456. border-bottom: 2rpx solid #E5E5E5;
  1457. .u-form-item__body__right__content__slot {
  1458. display: flex;
  1459. flex-direction: row;
  1460. justify-content: space-between;
  1461. margin-right: 20rpx;
  1462. align-items: center;
  1463. }
  1464. }
  1465. .u-form-item__body__left__content__label {
  1466. font-size: 30rpx;
  1467. }
  1468. }
  1469. }
  1470. }
  1471. .step-one {
  1472. .tips {
  1473. margin: 30rpx;
  1474. }
  1475. .upload-container {
  1476. width: 500rpx;
  1477. margin: 30rpx auto;
  1478. /* #ifdef MP-WEIXIN */
  1479. .u-upload {
  1480. image {
  1481. width: 500rpx;
  1482. height: 350rpx;
  1483. margin: 0 auto;
  1484. }
  1485. }
  1486. /* #endif */
  1487. /* #ifdef MP-ALIPAY */
  1488. image {
  1489. width: 500rpx;
  1490. height: 350rpx;
  1491. margin: 0 auto;
  1492. }
  1493. /* #endif */
  1494. }
  1495. }
  1496. .step-two {
  1497. display: flex;
  1498. flex-direction: column;
  1499. width: 100%;
  1500. height: 100%;
  1501. .face-area {
  1502. display: flex;
  1503. flex-direction: column;
  1504. background-color: #FFFFFF;
  1505. border-radius: 50rpx;
  1506. overflow: hidden;
  1507. .face-area--tips {
  1508. display: flex;
  1509. padding: 10rpx 20rpx;
  1510. height: 60rpx;
  1511. align-items: flex-end;
  1512. .face-area--tips--title {
  1513. margin: 10rpx;
  1514. }
  1515. .face-area--tips--context {
  1516. margin: 10rpx;
  1517. }
  1518. }
  1519. .face-area--line {
  1520. margin-left: 40rpx;
  1521. margin-bottom: 20rpx;
  1522. width: 30rpx;
  1523. border-bottom: solid 6rpx #9e97c3;
  1524. }
  1525. /* #ifdef MP-WEIXIN */
  1526. .camera-container {
  1527. width: 80%;
  1528. height: 80vw;
  1529. margin: 0 auto;
  1530. margin-bottom: 30rpx;
  1531. .camera {
  1532. width: 100%;
  1533. height: 80vw;
  1534. margin: 0 auto;
  1535. margin-bottom: 30rpx;
  1536. border: 2rpx solid black;
  1537. border-radius: 50%;
  1538. // box-sizing: border-box;
  1539. }
  1540. }
  1541. /* #endif */
  1542. /* #ifdef MP-ALIPAY */
  1543. .camera-container {
  1544. width: 100%;
  1545. display: flex;
  1546. align-items: center;
  1547. justify-content: center;
  1548. padding-bottom: 30rpx;
  1549. cover-image {
  1550. margin: 0;
  1551. padding: 0;
  1552. position: absolute;
  1553. }
  1554. }
  1555. .check-pic-result {
  1556. width: 100%;
  1557. padding: 10rpx 20rpx;
  1558. display: flex;
  1559. justify-content: center;
  1560. box-sizing: border-box;
  1561. color: red;
  1562. }
  1563. /* #endif */
  1564. }
  1565. .precautions {
  1566. overflow: hidden;
  1567. .precautions--tips {
  1568. display: flex;
  1569. padding: 10rpx 20rpx;
  1570. align-items: flex-end;
  1571. .precautions--tips--title {
  1572. margin: 10rpx;
  1573. }
  1574. .precautions--tips--context {
  1575. margin: 10rpx;
  1576. }
  1577. }
  1578. .precautions--line {
  1579. margin-left: 40rpx;
  1580. margin-bottom: 20rpx;
  1581. width: 30rpx;
  1582. border-bottom: solid 6rpx #9e97c3;
  1583. }
  1584. .precautions--context {
  1585. margin: 0 20rpx;
  1586. margin-bottom: 20rpx;
  1587. }
  1588. .img-list {
  1589. display: flex;
  1590. justify-content: space-around;
  1591. .img-list--item {
  1592. display: flex;
  1593. flex-direction: column;
  1594. align-items: center;
  1595. width: 20%;
  1596. .img {
  1597. display: flex;
  1598. flex-direction: row;
  1599. border-radius: 20rpx;
  1600. background-color: #dcdce9;
  1601. width: 100%;
  1602. height: 140rpx;
  1603. justify-content: center;
  1604. align-items: center;
  1605. }
  1606. }
  1607. }
  1608. }
  1609. /* #ifdef MP-ALIPAY */
  1610. .btn {
  1611. margin: 20rpx;
  1612. }
  1613. /* #endif */
  1614. }
  1615. /* #ifdef MP-ALIPAY */
  1616. .shoot-id-card {
  1617. width: 100%;
  1618. display: flex;
  1619. flex-direction: column;
  1620. align-items: center;
  1621. cover-image,
  1622. camera {
  1623. margin: 0;
  1624. padding: 0;
  1625. position: absolute;
  1626. }
  1627. .camera-btn {
  1628. width: 100%;
  1629. height: 200rpx;
  1630. position: absolute;
  1631. display: flex;
  1632. justify-content: center;
  1633. align-items: center;
  1634. bottom: 50rpx;
  1635. }
  1636. }
  1637. /* #endif */
  1638. }
  1639. }
  1640. </style>