addGuest.vue 48 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680
  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: false,
  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 { data: ocrRes } = await uni.$http.post('/user/idCardOcr', {
  856. image: imgBase64,
  857. ocrType: _ocrType,
  858. imageType: 'BASE64'
  859. })
  860. // console.log("ocrRes", ocrRes);
  861. if (!ocrRes.success) {
  862. uni.showModal({
  863. content: '身份证信息识别失败,请重新选择照片或拍照上传。',
  864. showCancel: false
  865. })
  866. my.hideLoading()
  867. return
  868. }
  869. const {
  870. data
  871. } = ocrRes
  872. // console.log(data);
  873. if (_ocrType === ocrType.face) {
  874. if (!this.name) {
  875. this.name = data.name
  876. }
  877. if (!this.idNumber) {
  878. this.idNumber = data.cardNum
  879. }
  880. if (this.idNumber !== data.cardNum || this.name !== data.name) {
  881. uni.showModal({
  882. content: '身份信息不一致,请核实后重新操作',
  883. showCancel: false,
  884. complete: () => {
  885. this.step = "fillForm"
  886. this.idCardFrontPicPath = '/static/idcard_upload_front.png'
  887. this.backPassed = false
  888. my.hideLoading()
  889. }
  890. })
  891. return
  892. }
  893. this.idCardInfoInPage.name = data.name
  894. this.idCardInfoInPage.sex = data.sex
  895. this.idCardInfoInPage.nation = data.nation
  896. this.idCardInfoInPage.birth = data.birth
  897. this.idCardInfoInPage.address = data.address
  898. this.idCardInfoInPage.idNumber = data.cardNum
  899. this.idCardFrontBase64 = imgBase64
  900. this.frontPassed = true
  901. } else if (_ocrType === ocrType.emblem) {
  902. this.idCardInfoInPage.issuingAuthority = data.issuingAuthority
  903. this.idCardInfoInPage.issuingDate = data.issuingDate
  904. this.idCardInfoInPage.expiryDate = data.expiryDate
  905. this.idCardBackBase64 = imgBase64
  906. this.backPassed = true
  907. }
  908. my.hideLoading()
  909. },
  910. async checkFacePic() {
  911. const userSetting = await uni.getSetting()
  912. // console.log("userSetting", userSetting);
  913. let camAuth = userSetting[1].authSetting['camera'] ? userSetting[1].authSetting['camera'] : false
  914. while (!camAuth) {
  915. await new Promise(async (resolve, reject) => {
  916. await uni.showModal({
  917. title: "温馨提示",
  918. content: "身份核验功能需要使用您的相机,请授权后重新点击核验。",
  919. success: async (res) => {
  920. if (res.confirm) {
  921. await uni.openSetting().then(res => {
  922. console.log("openSetting", res);
  923. camAuth = res[1].authSetting['camera'] ? res[1]
  924. .authSetting['camera'] : false
  925. resolve()
  926. })
  927. }
  928. }
  929. })
  930. })
  931. setTimeout(() => {}, 200)
  932. }
  933. // console.log("进行了相机授权操作");
  934. this.checkPicTips = "身份核验中...."
  935. this.showTips = true
  936. this.isCheckingFace = true
  937. while (!this.faceCheckSucceed) {
  938. // console.log("开始takePhoto进行人脸检测", this.faceCheckCam);
  939. const photo = await this.faceCheckCam.takePhoto({
  940. quality: 'normal',
  941. })
  942. // console.log("完成takePhoto", photo.tempImagePath);
  943. const {
  944. data: photoBase64
  945. } = await this.fileSystem.readFile({
  946. filePath: photo.tempImagePath,
  947. encoding: "base64"
  948. })
  949. // console.log("photoBase64", photoBase64);
  950. const { data: checkPicRes } = await uni.$http.post('/user/faceCheckAll', {
  951. hotelId: this.currentHotel.hotelId,
  952. imageBase64: photoBase64,
  953. name: this.name,
  954. idNumber: this.idNumber
  955. })
  956. console.log("checkPicRes", checkPicRes);
  957. if (!checkPicRes.success) {
  958. // if (["活体检测失败", "人证比对失败"].includes(checkPicRes.msg)) {
  959. // this.checkPicTips = checkPicRes.msg
  960. // } else {
  961. // this.checkPicTips = checkPicRes.msg.split("原因:")[1] + "。请将面部完整放入拍摄区域。";
  962. // console.log("checkPicRes.data", this.checkPicTips);
  963. // }
  964. this.checkPicTips = checkPicRes.msg
  965. await new Promise(resolve => {
  966. setTimeout(() => {resolve()}, 100)
  967. })
  968. } else {
  969. this.checkPicTips = "人脸检测成功"
  970. this.faceCheckSucceed = true
  971. // 进行人脸检测成功的后继操作
  972. await this.afterSuccessCheckPicAlipay(photoBase64)
  973. }
  974. }
  975. },
  976. async afterSuccessCheckPicAlipay(photoBase64) {
  977. let infoFromIdCard = {}
  978. this.infoList.forEach(info => {
  979. infoFromIdCard[info] = this.idCardInfoInPage[info]
  980. })
  981. let currentCheckinInfo = {
  982. name: this.name,
  983. idNumber: this.idNumber,
  984. faceData: photoBase64,
  985. phone: this.phone,
  986. ...infoFromIdCard
  987. }
  988. //更新local storage 中的入住信息
  989. let checkinInfoToUpdate = this.checkinInfo
  990. checkinInfoToUpdate.push(currentCheckinInfo)
  991. this.updateCheckinInfo(checkinInfoToUpdate)
  992. //更新local storage 中的身份证信息
  993. let idCardInfoToUpdate = this.idCardInfo
  994. idCardInfoToUpdate.push(this.idCardInfoInPage)
  995. this.updateIdCardInfo(idCardInfoToUpdate)
  996. //如果上传过照片则更新服务器中的身份证信息
  997. if (this.frontPassed && this.backPassed) {
  998. uni.$http.post('/user/idCardInfo/add', {
  999. ...this.idCardInfoInPage,
  1000. birthday: this.idCardInfoInPage.birth,
  1001. idCardFrontBase64: this.idCardFrontBase64,
  1002. idCardBackBase64: this.idCardBackBase64
  1003. })
  1004. }
  1005. if (this.isMainCustomer) {
  1006. //如果是主入住人,且当前账号姓名和身份证号为空,则更新账号信息为主入住人信息
  1007. if (!this.userInfo.name || !this.userInfo.idNumber) {
  1008. this.userInfo.name = this.name
  1009. this.userInfo.idNumber = this.idNumber
  1010. this.updateUserInfo(this.userInfo)
  1011. uni.$http.put(`/user`, {
  1012. name: this.name,
  1013. idNumber: this.idNumber
  1014. })
  1015. }
  1016. //更新订单预定人信息为主入住人信息
  1017. let orderToUpdate = this.order
  1018. orderToUpdate.name = this.name
  1019. orderToUpdate.phone = this.phone
  1020. this.updateOrder(orderToUpdate)
  1021. }
  1022. this.checkPicTips = "身份核验通过!"
  1023. setTimeout(() => uni.reLaunch({
  1024. url: '/subpkg_checkin/confirmOrder/confirmOrder'
  1025. }), 1000)
  1026. },
  1027. // #endif
  1028. // #ifdef MP-WEIXIN
  1029. start() {
  1030. console.log('调用start');
  1031. this.idCardVKSession.destroy()
  1032. if (!this.duringCameraAuth && this.isVKSupport) {
  1033. this.getCameraAuth()
  1034. }
  1035. },
  1036. getCameraAuth() {
  1037. console.log('getCameraAuth')
  1038. this.duringCameraAuth = true
  1039. let that = this
  1040. wx.getSetting({
  1041. success: (res) => {
  1042. console.log('getSetting, res : ')
  1043. console.log(res)
  1044. if (!res.authSetting['scope.camera']) {
  1045. wx.authorize({
  1046. scope: 'scope.camera',
  1047. success(res) {
  1048. console.log('authorize success, res : ')
  1049. console.log(res)
  1050. that.showcamera = true
  1051. },
  1052. fail: (res) => {
  1053. console.log('authorize fail, res : ')
  1054. console.log(res)
  1055. wx.showModal({
  1056. title: '提示',
  1057. content: '尚未进行授权,功能将无法使用',
  1058. cancelText: '取消',
  1059. confirmText: '授权',
  1060. success(res) {
  1061. console.log(res);
  1062. if (res.confirm) {
  1063. wx.openSetting({
  1064. //这里的方法是调到一个添加权限的页面,这里可以测试在拒绝授权的情况下设置中是否存在相机选项
  1065. success: (res) => {
  1066. if (!res.authSetting[
  1067. 'scope.camera'
  1068. ]) {
  1069. this.getCameraAuth()
  1070. } else {
  1071. that.showcamera =
  1072. true
  1073. }
  1074. },
  1075. fail: function() {
  1076. console.log(
  1077. '相机授权设置失败');
  1078. },
  1079. });
  1080. } else if (res.cancel) {
  1081. console.log('用户点击取消');
  1082. wx.showToast({
  1083. title: '您已取消授权',
  1084. icon: 'error',
  1085. duration: 1000,
  1086. });
  1087. setTimeout(function() {
  1088. wx.navigateBack();
  1089. }, 1000);
  1090. }
  1091. }
  1092. })
  1093. }
  1094. })
  1095. } else {
  1096. that.showcamera = true
  1097. }
  1098. that.initData()
  1099. }
  1100. })
  1101. this.duringCameraAuth = false
  1102. },
  1103. //visionkit人脸必须函数
  1104. async detectFace(frame) {
  1105. console.log('frame', frame.data);
  1106. this.faceVKSession.detectFace({
  1107. frameBuffer: frame.data,
  1108. width: frame.width,
  1109. height: frame.height,
  1110. scoreThreshold: 0.8,
  1111. sourceType: 0,
  1112. modelMode: 1,
  1113. });
  1114. },
  1115. //初始化相机引擎
  1116. initData() {
  1117. let that = this;
  1118. console.log('before createCameraContext')
  1119. //使用visionkit
  1120. that.cameraEngine = wx.createCameraContext();
  1121. console.log('before createCameraContext')
  1122. let count = 0;
  1123. //初始化相机
  1124. const listener = that.cameraEngine.onCameraFrame((frame) => {
  1125. count++;
  1126. //每十帧分析一次
  1127. if (count === 10) {
  1128. this.detectFace(frame);
  1129. count = 0;
  1130. }
  1131. });
  1132. //开始监听数据帧
  1133. listener.start();
  1134. //创建VK对象
  1135. that.faceVKSession = wx.createVKSession({
  1136. version: 'v1',
  1137. track: {
  1138. plane: {
  1139. mode: 1,
  1140. },
  1141. face: {
  1142. mode: 2,
  1143. },
  1144. },
  1145. });
  1146. //启动VK对象
  1147. that.faceVKSession.start((errno) => {
  1148. console.log('faceVKSession.start errno', errno);
  1149. if (errno) {
  1150. wx.showModal({
  1151. title: '提示',
  1152. content: '网络错误,请退出后重试',
  1153. showCancel: false,
  1154. confirmText: '确定',
  1155. success(res) {
  1156. console.log(res);
  1157. if (res.confirm) {
  1158. wx.navigateBack();
  1159. }
  1160. },
  1161. });
  1162. return
  1163. }
  1164. console.log('faceVKSession start')
  1165. that.faceVKSession.on('updateAnchors', (anchors) => {
  1166. console.log('anchors', anchors);
  1167. console.log('anchors.length', anchors.length);
  1168. anchors.forEach((anchor) => {
  1169. console.log('anchor.points', anchor.points);
  1170. console.log('anchor.origin', anchor.origin);
  1171. console.log('anchor.size', anchor.size);
  1172. console.log('anchor.angle', anchor.angle);
  1173. console.log('anchor', anchor.confidence);
  1174. if (anchors.length > 1) {
  1175. that.tipsText = '请保证只有一个人';
  1176. } else {
  1177. const {
  1178. pitch,
  1179. roll,
  1180. yaw
  1181. } = anchor.angle;
  1182. const standard = 0.3;
  1183. if (
  1184. Math.abs(pitch) >= standard ||
  1185. Math.abs(roll) >= standard ||
  1186. Math.abs(yaw) >= standard
  1187. ) {
  1188. that.tipsText = '请平视摄像头';
  1189. } else if (
  1190. anchor.origin.x < 0.15 ||
  1191. anchor.origin.x > 0.3 ||
  1192. anchor.origin.y < 0.2 ||
  1193. anchor.origin.y > 0.45
  1194. ) {
  1195. this.tipsText = '请将人脸对准中心位置';
  1196. } else if (
  1197. anchor.confidence[0] <= 0.8 ||
  1198. anchor.confidence[1] <= 0.8 ||
  1199. anchor.confidence[2] <= 0.8 ||
  1200. anchor.confidence[3] <= 0.8 ||
  1201. anchor.confidence[4] <= 0.8
  1202. ) {
  1203. that.tipsText = '请勿遮挡五官';
  1204. } else {
  1205. listener.stop();
  1206. that.tipsText = '即将拍照,请保持!';
  1207. setTimeout(function() {
  1208. that.handleTakePhotoClick();
  1209. }, 1000);
  1210. return;
  1211. }
  1212. }
  1213. });
  1214. });
  1215. });
  1216. },
  1217. // 拍照
  1218. handleTakePhotoClick() {
  1219. this.tipsText = '';
  1220. uni.showLoading({
  1221. title: '正在身份核验,请稍后',
  1222. });
  1223. this.cameraEngine.takePhoto({
  1224. quality: 'normal',
  1225. success: ({
  1226. tempImagePath
  1227. }) => {
  1228. let mybase64 = wx
  1229. .getFileSystemManager()
  1230. .readFileSync(tempImagePath, 'base64');
  1231. this.afterRead(mybase64);
  1232. this.showcamera = false
  1233. },
  1234. });
  1235. },
  1236. //上传
  1237. async afterRead(mybase64) {
  1238. let that = this;
  1239. let res = await uni.$http.post('/user/faceCheckAll', {
  1240. hotelId: this.currentHotel.hotelId,
  1241. imageBase64: mybase64,
  1242. name: this.name,
  1243. idNumber: this.idNumber
  1244. })
  1245. if (res.data.code === 200 && res.data.success === true) {
  1246. let infoFromIdCard = {}
  1247. this.infoList.forEach(info => {
  1248. infoFromIdCard[info] = this.idCardInfoInPage[info]
  1249. })
  1250. let currentCheckinInfo = {
  1251. name: this.name,
  1252. idNumber: this.idNumber,
  1253. faceData: mybase64,
  1254. phone: this.phone,
  1255. ...infoFromIdCard
  1256. }
  1257. //更新local storage 中的入住信息
  1258. let checkinInfoToUpdate = this.checkinInfo
  1259. checkinInfoToUpdate.push(currentCheckinInfo)
  1260. this.updateCheckinInfo(checkinInfoToUpdate)
  1261. //更新local storage 中的身份证信息
  1262. let idCardInfoToUpdate = this.idCardInfo
  1263. idCardInfoToUpdate.push(this.idCardInfoInPage)
  1264. this.updateIdCardInfo(idCardInfoToUpdate)
  1265. //如果上传过照片则更新服务器中的身份证信息
  1266. if (this.idCardFrontDetectInfo.detected && this.idCardBackDetectInfo
  1267. .detected) {
  1268. uni.$http.post('/user/idCardInfo/add', {
  1269. ...this.idCardInfoInPage,
  1270. birthday: this.idCardInfoInPage.birth,
  1271. idCardFrontBase64: this.idCardFrontPicPath.split(',')[1],
  1272. idCardBackBase64: this.idCardBackPicPath.split(',')[1]
  1273. })
  1274. }
  1275. if (this.isMainCustomer) {
  1276. //如果是主入住人,且当前账号姓名和身份证号为空,则更新账号信息为主入住人信息
  1277. if (!this.userInfo.name || !this.userInfo.idNumber) {
  1278. this.userInfo.name = this.name
  1279. this.userInfo.idNumber = this.idNumber
  1280. this.updateUserInfo(this.userInfo)
  1281. uni.$http.put(`/user`, {
  1282. name: this.name,
  1283. idNumber: this.idNumber
  1284. })
  1285. }
  1286. //更新订单预定人信息为主入住人信息
  1287. let orderToUpdate = this.order
  1288. orderToUpdate.name = this.name
  1289. orderToUpdate.phone = this.phone
  1290. this.updateOrder(orderToUpdate)
  1291. }
  1292. uni.hideLoading();
  1293. uni.$showMsg('身份核验通过!')
  1294. setTimeout(() => uni.reLaunch({
  1295. url: '/subpkg_checkin/confirmOrder/confirmOrder'
  1296. }), 1000)
  1297. } else {
  1298. uni.hideLoading()
  1299. uni.showModal({
  1300. content: `身份核验失败,${res.data.msg},请重试`,
  1301. showCancel: false,
  1302. success: function(res) {
  1303. if (res.confirm) {
  1304. console.log('用户点击确定');
  1305. that.initData();
  1306. }
  1307. },
  1308. });
  1309. }
  1310. },
  1311. // #endif
  1312. },
  1313. async onLoad() {
  1314. let pages = getCurrentPages()
  1315. let beforePage = pages[pages.length - 2]
  1316. //不是从确定订单页面点击添加顾客跳转过来,设置信息为当前账户的信息,清空入住信息
  1317. if (beforePage.route !== 'subpkg_checkin/confirmOrder/confirmOrder') {
  1318. this.name = this.userInfo.name
  1319. this.idNumber = this.userInfo.idNumber
  1320. this.phone = this.userInfo.phone
  1321. this.updateCheckinInfo([])
  1322. this.isMainCustomer = true
  1323. } else {
  1324. this.isMainCustomer = false
  1325. }
  1326. //是主入住人且姓名和身份证号为空,判断为新用户,直接跳转至上传身份证照片页面
  1327. if (this.isMainCustomer && (!this.userInfo.name || !this.userInfo.idNumber)) {
  1328. this.step = 'uploadCard'
  1329. }
  1330. // #ifdef MP-WEIXIN
  1331. this.isVKSupport = wx.isVKSupport('v1')
  1332. if (!this.isVKSupport) {
  1333. uni.showModal({
  1334. content: '微信版本过低,请升级至最新版本',
  1335. showCancel: false,
  1336. })
  1337. }
  1338. // #endif
  1339. // #ifdef MP-ALIPAY
  1340. let alipaySystemInfo = await uni.getSystemInfo()
  1341. this.screenWidth = alipaySystemInfo[1].screen.width
  1342. // 设置身份证拍照相机显示区域距边界40px
  1343. this.cardCamWidth = alipaySystemInfo[1].screen.width - 40 * 2
  1344. this.cardCamHigh = Number(865 / 548 * this.cardCamWidth).toFixed(0)
  1345. const menuButton = await uni.getMenuButtonBoundingClientRect()
  1346. // 身份证拍照相机top距navBar底部10px
  1347. this.cardCamTopGap = menuButton.top + menuButton.height + 8 + 10
  1348. const factor = this.screenWidth / 750
  1349. const tipsHight = 106 * factor
  1350. this.faceCheckCamTopGap = menuButton.top + menuButton.height + 8 + tipsHight
  1351. this.fileSystem = my.getFileSystemManager();
  1352. // #endif
  1353. },
  1354. // #ifdef MP-WEIXIN
  1355. onShow() {
  1356. this.showAddGuest = true
  1357. this.pageTitle = '身份信息录入'
  1358. },
  1359. onReady() {
  1360. this.initIdCardVKSession()
  1361. },
  1362. onShareAppMessage(info) {
  1363. return {
  1364. title: '源享住',
  1365. path: 'pages/quickLogin/quickLogin',
  1366. imageUrl: '/static/logo.png'
  1367. }
  1368. },
  1369. // #endif
  1370. }
  1371. </script>
  1372. <style lang="scss">
  1373. .btn-container {
  1374. position: fixed;
  1375. bottom: 90rpx;
  1376. left: 30rpx;
  1377. right: 30rpx;
  1378. .u-button__text {
  1379. font-size: 30rpx !important;
  1380. }
  1381. }
  1382. page {
  1383. background: #EFEFF4;
  1384. .container {
  1385. .step-zero {
  1386. .tips {
  1387. margin: 30rpx;
  1388. }
  1389. .u-form {
  1390. margin-top: 10rpx;
  1391. background-color: #FFFFFF;
  1392. .u-form-item {
  1393. line-height: 50rpx;
  1394. .u-form-item__body {
  1395. margin-left: 32rpx;
  1396. border-bottom: 2rpx solid #E5E5E5;
  1397. .u-form-item__body__right__content__slot {
  1398. display: flex;
  1399. flex-direction: row;
  1400. justify-content: space-between;
  1401. margin-right: 20rpx;
  1402. align-items: center;
  1403. }
  1404. }
  1405. .u-form-item__body__left__content__label {
  1406. font-size: 30rpx;
  1407. }
  1408. }
  1409. }
  1410. }
  1411. .step-one {
  1412. .tips {
  1413. margin: 30rpx;
  1414. }
  1415. .upload-container {
  1416. width: 500rpx;
  1417. margin: 30rpx auto;
  1418. /* #ifdef MP-WEIXIN */
  1419. .u-upload {
  1420. image {
  1421. width: 500rpx;
  1422. height: 350rpx;
  1423. margin: 0 auto;
  1424. }
  1425. }
  1426. /* #endif */
  1427. /* #ifdef MP-ALIPAY */
  1428. image {
  1429. width: 500rpx;
  1430. height: 350rpx;
  1431. margin: 0 auto;
  1432. }
  1433. /* #endif */
  1434. }
  1435. }
  1436. .step-two {
  1437. display: flex;
  1438. flex-direction: column;
  1439. width: 100%;
  1440. height: 100%;
  1441. .face-area {
  1442. display: flex;
  1443. flex-direction: column;
  1444. background-color: #FFFFFF;
  1445. border-radius: 50rpx;
  1446. overflow: hidden;
  1447. .face-area--tips {
  1448. display: flex;
  1449. padding: 10rpx 20rpx;
  1450. height: 60rpx;
  1451. align-items: flex-end;
  1452. .face-area--tips--title {
  1453. margin: 10rpx;
  1454. }
  1455. .face-area--tips--context {
  1456. margin: 10rpx;
  1457. }
  1458. }
  1459. .face-area--line {
  1460. margin-left: 40rpx;
  1461. margin-bottom: 20rpx;
  1462. width: 30rpx;
  1463. border-bottom: solid 6rpx #9e97c3;
  1464. }
  1465. /* #ifdef MP-WEIXIN */
  1466. .camera-container {
  1467. width: 80%;
  1468. height: 80vw;
  1469. margin: 0 auto;
  1470. margin-bottom: 30rpx;
  1471. .camera {
  1472. width: 100%;
  1473. height: 80vw;
  1474. margin: 0 auto;
  1475. margin-bottom: 30rpx;
  1476. border: 2rpx solid black;
  1477. border-radius: 50%;
  1478. // box-sizing: border-box;
  1479. }
  1480. }
  1481. /* #endif */
  1482. /* #ifdef MP-ALIPAY */
  1483. .camera-container {
  1484. width: 100%;
  1485. display: flex;
  1486. align-items: center;
  1487. justify-content: center;
  1488. padding-bottom: 30rpx;
  1489. cover-image {
  1490. margin: 0;
  1491. padding: 0;
  1492. position: absolute;
  1493. }
  1494. }
  1495. .check-pic-result {
  1496. width: 100%;
  1497. padding: 10rpx 20rpx;
  1498. display: flex;
  1499. justify-content: center;
  1500. box-sizing: border-box;
  1501. color: red;
  1502. }
  1503. /* #endif */
  1504. }
  1505. .precautions {
  1506. overflow: hidden;
  1507. .precautions--tips {
  1508. display: flex;
  1509. padding: 10rpx 20rpx;
  1510. align-items: flex-end;
  1511. .precautions--tips--title {
  1512. margin: 10rpx;
  1513. }
  1514. .precautions--tips--context {
  1515. margin: 10rpx;
  1516. }
  1517. }
  1518. .precautions--line {
  1519. margin-left: 40rpx;
  1520. margin-bottom: 20rpx;
  1521. width: 30rpx;
  1522. border-bottom: solid 6rpx #9e97c3;
  1523. }
  1524. .precautions--context {
  1525. margin: 0 20rpx;
  1526. margin-bottom: 20rpx;
  1527. }
  1528. .img-list {
  1529. display: flex;
  1530. justify-content: space-around;
  1531. .img-list--item {
  1532. display: flex;
  1533. flex-direction: column;
  1534. align-items: center;
  1535. width: 20%;
  1536. .img {
  1537. display: flex;
  1538. flex-direction: row;
  1539. border-radius: 20rpx;
  1540. background-color: #dcdce9;
  1541. width: 100%;
  1542. height: 140rpx;
  1543. justify-content: center;
  1544. align-items: center;
  1545. }
  1546. }
  1547. }
  1548. }
  1549. /* #ifdef MP-ALIPAY */
  1550. .btn {
  1551. margin: 20rpx;
  1552. }
  1553. /* #endif */
  1554. }
  1555. /* #ifdef MP-ALIPAY */
  1556. .shoot-id-card {
  1557. width: 100%;
  1558. display: flex;
  1559. flex-direction: column;
  1560. align-items: center;
  1561. cover-image,
  1562. camera {
  1563. margin: 0;
  1564. padding: 0;
  1565. position: absolute;
  1566. }
  1567. .camera-btn {
  1568. width: 100%;
  1569. height: 200rpx;
  1570. position: absolute;
  1571. display: flex;
  1572. justify-content: center;
  1573. align-items: center;
  1574. bottom: 50rpx;
  1575. }
  1576. }
  1577. /* #endif */
  1578. }
  1579. }
  1580. </style>