addGuest.vue 52 KB

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