addGuest.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503
  1. <template>
  2. <view>
  3. <view class="is-debug" v-if="needInitHotelList">
  4. <view class="guest-list" v-for="guest in guestList">
  5. <u-form class="guest-form" :model="guestModel" labelAlign="center" :ref="'form' + guest.id">
  6. <u-form-item class="guest-form-item" label="姓名:" prop="guest.name" labelWidth="160rpx">
  7. <u-input placeholder="请输入姓名" border="surround" v-model="guest.name" clearable></u-input>
  8. </u-form-item>
  9. <u-form-item class="guest-form-item" label="证件号:" prop="guest.idNumber" labelWidth="160rpx">
  10. <u-input placeholder="请输入证件号" border="surround" v-model="guest.idNumber" clearable></u-input>
  11. </u-form-item>
  12. <view class="guest-form-bottom">
  13. <view class="guest-form-bottom-left">
  14. <u-form-item class="" :label="uploadPicTip" prop="guest.pic" labelWidth="160rpx">
  15. <image v-if="userInfo.facePreCheck" style="width: 160rpx; height: 160rpx; "
  16. :src="'data:image/jpeg;base64,' + guest.picBase64" @click="gotoPreCheck(guest)">
  17. </image>
  18. <u-upload v-else :fileList="guest.pic" @afterRead="afterRead" @delete="deletePic"
  19. :name="guest.id" :maxCount="1" :previewFullImage="true" :maxSize="1024*1024*1.5"
  20. @oversize="oversize"></u-upload>
  21. </u-form-item>
  22. </view>
  23. <view class="delete-guest-btn">
  24. <u-button v-if="guestList.length>1" type="error"
  25. @click="deleteGuest(guest.id)">删除入住人</u-button>
  26. </view>
  27. </view>
  28. </u-form>
  29. </view>
  30. <view class="bottom">
  31. <view class="add-guest-btn">
  32. <u-button type="primary" :disabled="this.guestList.length >= 3" @click="addGuest">添加入住人</u-button>
  33. </view>
  34. <view class="checkin-btn">
  35. <u-button type="primary" @click="checkin" :loading="checkinButtonLoading"
  36. :loadingText="checkinButtonLoadingText">入住</u-button>
  37. </view>
  38. </view>
  39. </view>
  40. <view class="" v-else>
  41. <view class="guest-list" v-for="guest in guestList">
  42. <u-form class="guest-form" :model="guestModel" labelAlign="center" :ref="'form' + guest.id">
  43. <u-form-item class="guest-form-item" label="姓名:" prop="guest.name" labelWidth="160rpx">
  44. <u-input placeholder="请输入姓名" border="surround" v-model="guest.name"></u-input>
  45. </u-form-item>
  46. <u-form-item class="guest-form-item" label="证件号:" prop="guest.idNumber" labelWidth="160rpx">
  47. <u-input placeholder="请输入证件号" border="surround" v-model="guest.idNumber"></u-input>
  48. </u-form-item>
  49. <view class="guest-form-bottom">
  50. <view class="delete-guest-btn">
  51. <u-button v-if="guestList.length>1" type="error"
  52. @click="deleteGuest(guest.id)">删除入住人</u-button>
  53. </view>
  54. </view>
  55. </u-form>
  56. </view>
  57. <view class="add-guest-btn">
  58. <u-button type="primary" :disabled="this.guestList.length >= 3 && addGuestButtonDisabled"
  59. @click="authentication">添加入住人</u-button>
  60. </view>
  61. <view class="checkin-btn">
  62. <u-button type="primary" @click="checkin" :disabled="checkinButtonDisabled">入住</u-button>
  63. </view>
  64. </view>
  65. <u-toast ref="uToast"></u-toast>
  66. </view>
  67. </template>
  68. <script>
  69. import {
  70. startEid
  71. } from '../../mp_ecard_sdk/main.js'
  72. import {
  73. mapState,
  74. mapMutations
  75. } from 'vuex'
  76. import moment from 'moment'
  77. export default {
  78. data() {
  79. return {
  80. nameTip: '姓名:',
  81. idNumberTip: '证件号:',
  82. uploadPicTip: '上传人脸:',
  83. guestList: [],
  84. guestModel: {
  85. guestInfo: {
  86. name: '',
  87. idNumber: '',
  88. pic: []
  89. }
  90. },
  91. reservation: {},
  92. checkinButtonLoading: false,
  93. checkinButtonLoadingText: '办理中',
  94. needInitHotelList: false,
  95. addGuestButtonDisabled: false,
  96. checkinButtonDisabled: false,
  97. pic: '',
  98. guestIdNavigateToPreCheck: 0
  99. };
  100. },
  101. computed: {
  102. ...mapState('m_user', ['userInfo']),
  103. ...mapState('m_business', ['hotelParams']),
  104. },
  105. methods: {
  106. setGuestPicBase64ById(id, base64) {
  107. this.guestList.forEach(guest => {
  108. if (guest.id == id) {
  109. guest.picBase64 = base64
  110. guest.picValid = true
  111. return
  112. }
  113. })
  114. },
  115. gotoPreCheck(guest) {
  116. console.log(guest)
  117. this.guestIdNavigateToPreCheck = guest.id
  118. console.log("id", id, "guestId", this.guestIdNavigateToPreCheck)
  119. uni.navigateTo({
  120. url: '/subpkg/dynamicFaceCheck/dynamicFaceCheck?guestId=' + guest.id + "&idNumber=" + guest.idNumber + "&name=" + guest.name
  121. })
  122. },
  123. addGuest() {
  124. if (this.guestList.length < 3) {
  125. this.guestList.push({
  126. id: this.guestList[this.guestList.length - 1].id + 1,
  127. name: '',
  128. idNumber: '',
  129. pic: [],
  130. picBase64: '',
  131. picValid: false
  132. })
  133. console.log(this.guestList[this.guestList.length - 1].id)
  134. } else {
  135. uni.$showMsg('入住人数已达到上限!')
  136. }
  137. },
  138. oversize() {
  139. uni.$showMsg('图片超出允许大小(1.5M)')
  140. },
  141. gotoCheck() {
  142. console.log('!!!!!!!!!!!')
  143. },
  144. //删除图片
  145. deletePic(event) {
  146. console.log(event.name)
  147. this.guestList.forEach(guest => {
  148. console.log(guest)
  149. if (guest.id == event.name) {
  150. guest.pic = []
  151. guest.picBase64 = ''
  152. return
  153. }
  154. })
  155. },
  156. //上传图片
  157. async afterRead(event) {
  158. try {
  159. this.addGuestButtonDisabled = true
  160. this.checkinButtonDisabled = true
  161. let _this = this
  162. let params = {
  163. type: 'loading',
  164. message: "正在加载",
  165. duration: '500'
  166. }
  167. this.$refs.uToast.show({
  168. ...params,
  169. complete() {
  170. console.log(event)
  171. _this.guestList.forEach(guest => {
  172. console.log(guest.id)
  173. console.log(guest.id == event.name)
  174. if (guest.id == event.name) {
  175. guest.pic.push(event.file)
  176. uni.getFileSystemManager().readFile({
  177. filePath: guest.pic[0].url, //选择图片返回的相对路径
  178. encoding: 'base64', //编码格式
  179. success: res => {
  180. console.log(res);
  181. guest.picBase64 = res.data
  182. uni.$http.post('/faceVerification/checkPic', {
  183. hotelId: _this.reservation.hotelId,
  184. faceData: guest.picBase64
  185. }).then((res) => {
  186. if (res.data.code === 200 && res
  187. .data
  188. .success ===
  189. true) {
  190. uni.$showMsg('上传成功!')
  191. guest.picValid = true
  192. } else {
  193. uni.$showMsg('未检测到人脸,请重新上传!')
  194. }
  195. console.log(res)
  196. })
  197. },
  198. fail: (e) => {
  199. uni.$showMsg('图片转换失败,请重试!')
  200. console.log("图片转换失败!");
  201. console.log(e);
  202. }
  203. })
  204. }
  205. })
  206. }
  207. })
  208. } finally {
  209. this.addGuestButtonDisabled = false
  210. this.checkinButtonDisabled = false
  211. }
  212. },
  213. deleteGuest(id) {
  214. console.log(id)
  215. this.guestList = this.guestList.filter(guest => guest.id != id)
  216. },
  217. async checkin() {
  218. //云极
  219. if (this.hotelParams.wx === null || this.hotelParams.wx === undefined || this.hotelParams.wx === 0) {
  220. //检查姓名、证件号是否填入,上传图片是否通过检查
  221. if (this.guestList.length < 1) {
  222. uni.$showMsg('请添加入住人!')
  223. return
  224. } else {
  225. let isEmpty = false;
  226. let allPicValid = true;
  227. this.guestList.forEach((guest) =>
  228. Object.keys(guest).forEach(key => {
  229. console.log(key + ' + ' + guest[key])
  230. if (!guest.picValid) {
  231. allPicValid = false
  232. }
  233. if (guest[key] === null || guest[key] === undefined || guest[
  234. key] === '') {
  235. isEmpty = true;
  236. return
  237. }
  238. })
  239. )
  240. if (isEmpty) {
  241. uni.$showMsg('请正确填写信息!')
  242. return
  243. }
  244. if (!allPicValid) {
  245. uni.$showMsg('请检查图片!')
  246. return
  247. }
  248. }
  249. this.checkinButtonLoading = true
  250. try {
  251. //检查人脸与姓名身份证号是否匹配
  252. for (let guest of this.guestList) {
  253. let yunjiFaceCheckInfo = {
  254. idNo: guest.idNumber,
  255. name: guest.name,
  256. image: guest.picBase64
  257. }
  258. let res = await uni.$http.post('/faceVerification/yunjiVerification', yunjiFaceCheckInfo)
  259. if (res.data.success === false) {
  260. uni.$showMsg('顾客' + guest.name + '身份验证未通过')
  261. return
  262. }
  263. }
  264. let start = new Date(this.reservation.startTime)
  265. let checkinInfo = {
  266. hotelId: this.reservation.hotelId,
  267. building: this.reservation.building,
  268. floorId: this.reservation.floor,
  269. roomId: this.reservation.room,
  270. startTime: moment(this.reservation.startTime).format('YYMMDDHHmmss'),
  271. endTime: moment(this.reservation.endTime).format('YYMMDDHHmmss'),
  272. cardId: '0',
  273. userType: 1,
  274. isDebug: this.userInfo.isDebug
  275. }
  276. let checkinResult = new Array(this.guestList.length).fill(false)
  277. console.log(checkinResult)
  278. for (let i = 0; i < this.guestList.length; i++) {
  279. checkinInfo.userName = this.guestList[i].name;
  280. checkinInfo.userId = this.guestList[i].idNumber;
  281. checkinInfo.faceData = this.guestList[i].picBase64;
  282. let res = await uni.$http.post('/checkin', checkinInfo)
  283. console.log(res)
  284. if (res.data.code == 200 && res.data.success === true) {
  285. checkinResult[i] = true
  286. console.log('checkinResult[' + i + '] = true')
  287. }
  288. }
  289. if (checkinResult.indexOf(false) < 0) {
  290. uni.$showMsg('办理成功!')
  291. setTimeout(() => {
  292. uni.switchTab({
  293. url: '/pages/home/home'
  294. })
  295. }, 1500)
  296. } else {
  297. let failMsg = '办理失败!'
  298. uni.$showMsg(failMsg)
  299. }
  300. } catch (e) {
  301. console.log(e)
  302. let failMsg = '办理失败!'
  303. uni.$showMsg(failMsg)
  304. } finally {
  305. this.checkinButtonLoading = false
  306. }
  307. }
  308. //E证通
  309. else {
  310. if (this.guestList.length < 1) {
  311. uni.$showMsg('请添加入住人!')
  312. return
  313. } else {
  314. let start = new Date(this.reservation.startTime)
  315. let checkinInfo = {
  316. hotelId: this.reservation.hotelId,
  317. building: this.reservation.building,
  318. floorId: this.reservation.floor,
  319. roomId: this.reservation.room,
  320. startTime: moment(this.reservation.startTime).format('YYMMDDHHmmss'),
  321. endTime: moment(this.reservation.endTime).format('YYMMDDHHmmss'),
  322. cardId: '0',
  323. userType: 1,
  324. }
  325. this.guestList.forEach(guest => {
  326. this.eidTokens.push(guest.eidToken)
  327. });
  328. checkinInfo.eidTokens = this.eidTokens;
  329. console.log("checkinInfo:" + checkinInfo)
  330. let res = await uni.$http.post('/checkin', checkinInfo)
  331. console.log(res)
  332. if (res.data.code === 200 && res.data.success === true) {
  333. uni.$showMsg('办理成功!')
  334. setTimeout(() => {
  335. uni.switchTab({
  336. url: '/pages/home/home'
  337. })
  338. }, 1500)
  339. } else {
  340. let failMsg = '办理失败!'
  341. uni.$showMsg(failMsg)
  342. }
  343. }
  344. }
  345. this.checkinButtonLoading = false
  346. },
  347. async authentication() {
  348. if (this.guestList.length > 3) {
  349. uni.$showMsg('入住人数已达上限!')
  350. return
  351. }
  352. let _this = this;
  353. //#ifdef MP-WEIXIN
  354. if (!(this.hotelParams.wx === null || this.hotelParams.wx === undefined || this.hotelParams.wx ===
  355. 0)) {
  356. let eidTokenRes = await uni.$http.get('/faceVerification/eidToken')
  357. let eidToken = eidTokenRes.data.data
  358. console.log("eidToken" + eidToken)
  359. startEid({
  360. data: {
  361. token: eidToken,
  362. needJumpPage: false
  363. },
  364. async verifyDoneCallback(res) {
  365. const {
  366. token,
  367. verifyDone
  368. } = res;
  369. console.log('收到核身完成的res:', res);
  370. console.log('核身的token是:', token);
  371. console.log('是否完成核身:', verifyDone);
  372. let eidResult = await uni.$http.get('/faceVerification/eidResult/' + eidToken)
  373. console.log('=========eidResult===========')
  374. console.log(eidResult)
  375. console.log('=========eidResult===========')
  376. if (eidResult.data.code === 200) {
  377. let guest = {
  378. verificated: true,
  379. name: eidResult.data.data.name,
  380. idNumber: eidResult.data.data.idNumber,
  381. eidToken: eidToken
  382. }
  383. _this.guestList.push(guest)
  384. } else {
  385. uni.$showMsg('身份验证失败,请重试!')
  386. }
  387. }
  388. });
  389. }
  390. //#endif
  391. },
  392. async getReservationInfo() {
  393. let res = await uni.$http.post('/userPicRoomInfo/queryByCondition', {
  394. userId: this.userInfo.userId,
  395. // userId: 29,
  396. status: true,
  397. pageNo: 1,
  398. pageSize: 1
  399. })
  400. console.log(res)
  401. if (res.data.data.records?.length > 0) {
  402. this.reservation = res.data.data.records[0]
  403. this.reservation.startTime = moment(this.reservation.startTime).format('YYYY/MM/DD HH:mm:ss')
  404. this.reservation.endTime = moment(this.reservation.endTime).format('YYYY/MM/DD HH:mm:ss')
  405. } else {
  406. this.reservation = {}
  407. }
  408. console.log(this.reservation)
  409. }
  410. },
  411. onLoad() {
  412. this.getReservationInfo()
  413. //#ifdef MP-WEIXIN
  414. this.needInitHotelList = this.hotelParams.wx === 0 || this.hotelParams.wx === null || this.hotelParams.wx ===
  415. undefined
  416. console.log(this.needInitHotelList)
  417. if (this.needInitHotelList) {
  418. this.guestList.push({
  419. id: 0,
  420. name: '',
  421. idNumber: '',
  422. pic: [],
  423. picBase64: '',
  424. picValid: false
  425. })
  426. this.guestList[0].idNumber = this.userInfo.idNumber
  427. this.guestList[0].name = this.userInfo.name
  428. }
  429. //#endif
  430. },
  431. onShow() {
  432. console.log('onshow', this.pic)
  433. let pages = getCurrentPages();
  434. console.log("pages", pages);
  435. }
  436. }
  437. </script>
  438. <style lang="scss">
  439. .is-debug {
  440. height: 900rpx;
  441. overflow: scroll;
  442. }
  443. .guest-list {
  444. border: 1rpx solid grey;
  445. margin: 20rpx;
  446. }
  447. .guest-form-item {
  448. display: flex;
  449. width: 80%;
  450. }
  451. .guest-form-item-tip {
  452. width: 160rpx;
  453. display: flex;
  454. margin-left: 20rpx;
  455. }
  456. .add-guest-btn,
  457. .checkin-btn {
  458. width: 80%;
  459. height: 72rpx;
  460. margin: 40rpx auto;
  461. }
  462. .u-input {
  463. width: 80%;
  464. }
  465. .guest-form-bottom {
  466. display: flex;
  467. }
  468. .delete-guest-btn {
  469. margin: 0 auto;
  470. position: relative;
  471. top: 30%;
  472. /*偏移*/
  473. transform: translateY(30%);
  474. text-align: center;
  475. }
  476. .bottom {
  477. z-index: 999;
  478. position: fixed;
  479. bottom: 0;
  480. background-color: white;
  481. width: 100%;
  482. height: 300rpx;
  483. }
  484. .guest-form-bottom-left {
  485. height: 216rpx;
  486. width: 336rpx;
  487. }
  488. </style>