staticFaceCheck.vue 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. <template>
  2. <view>
  3. <u-upload :fileList="fileList" @afterRead="afterRead" @delete="deletePic" :name="guest.id" :maxCount="1"
  4. :previewFullImage="true" :maxSize="1024*1024*1.5" @oversize="oversize"></u-upload>
  5. <u-toast ref="uToast"></u-toast>
  6. <u-button text="下一步" :disabled="disabled" @click="gotoConfirmOrder"></u-button>
  7. </view>
  8. </template>
  9. <script>
  10. import {
  11. mapState,
  12. mapMutations
  13. } from 'vuex'
  14. export default {
  15. data() {
  16. return {
  17. name: '',
  18. idNumber: '',
  19. phone: '',
  20. fileList: [],
  21. picBase64: '',
  22. disabled: false,
  23. picValid: false
  24. };
  25. },
  26. computed: {
  27. ...mapState('m_business', ['hotelParams', 'currentHotel', 'checkinInfo']),
  28. },
  29. methods: {
  30. ...mapMutations('m_business', ['updateCheckinInfo']),
  31. //上传图片
  32. async afterRead(event) {
  33. let _this = this
  34. this.disabled = true
  35. uni.showLoading({
  36. title: "上传中",
  37. });
  38. uni.getFileSystemManager().readFile({
  39. filePath: event.file.url, //选择图片返回的相对路径
  40. encoding: 'base64', //编码格式
  41. success: res => {
  42. console.log(res);
  43. _this.picBase64 = res.data
  44. uni.$http.post('/faceVerification/checkPic', {
  45. hotelId: _this.currentHotel.hotelId,
  46. faceData: _this.picBase64
  47. }).then((res) => {
  48. if (res.data.code === 200 && res.data.success ===
  49. true) {
  50. _this.fileList.push({
  51. url: event.file.url
  52. })
  53. uni.$showMsg('上传成功!')
  54. _this.picValid = true
  55. } else {
  56. uni.$showMsg('未检测到人脸,请重新上传!')
  57. }
  58. console.log(res)
  59. })
  60. },
  61. fail: (e) => {
  62. uni.$showMsg('图片转换失败,请重试!')
  63. console.log("图片转换失败!");
  64. console.log(e);
  65. },
  66. complete: (e) => {
  67. console.log(e);
  68. setTimeout(() => {
  69. uni.hideLoading()
  70. this.disabled = false
  71. }, 1000)
  72. }
  73. })
  74. },
  75. oversize() {
  76. uni.$showMsg('图片超出允许大小(1.5M)')
  77. },
  78. //删除图片
  79. deletePic(event) {
  80. console.log(event)
  81. this.fileList = []
  82. this.picBase64 = ''
  83. },
  84. gotoConfirmOrder() {
  85. if (this.picValid === true) {
  86. let guestInfo = {
  87. name: this.name,
  88. idNumber: this.idNumber,
  89. faceData: this.picBase64,
  90. phone: this.phone
  91. }
  92. this.checkinInfo.push(guestInfo)
  93. this.updateCheckinInfo(this.checkinInfo)
  94. uni.reLaunch({
  95. url: '/subpkg_checkin/confirmOrder/confirmOrder'
  96. })
  97. } else {
  98. uni.$showMsg('请检查图片!')
  99. }
  100. }
  101. },
  102. onLoad(options) {
  103. this.name = options.name
  104. this.idNumber = options.idNumber
  105. this.phone = options.phone
  106. },
  107. // #ifdef MP-WEIXIN
  108. onShareAppMessage(info) {
  109. return {
  110. title: '源享住',
  111. path: 'pages/login/login',
  112. imageUrl: "/static/logo.png"
  113. }
  114. }
  115. // #endif
  116. }
  117. </script>
  118. <style lang="scss">
  119. </style>