addGuest.vue 51 KB

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