addGuestDebug.vue 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320
  1. <template>
  2. <view>
  3. <view class="is-debug">
  4. <view class="guest-list" v-for="guest in guestListDebug">
  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. <u-form-item class="" :label="uploadPicTip" prop="guest.pic" labelWidth="160rpx">
  14. <u-upload :fileList="guest.pic" @afterRead="afterRead" @delete="deletePic" :name="guest.id"
  15. :maxCount="1" :previewFullImage="true" :maxSize="1024*1024*1.5" @oversize="oversize"></u-upload>
  16. </u-form-item>
  17. <view class="delete-guest-btn">
  18. <u-button v-if="guestListDebug.length>1" type="error"
  19. @click="deleteGuest(guest.id)">删除入住人</u-button>
  20. </view>
  21. </view>
  22. </u-form>
  23. </view>
  24. <view class="bottom">
  25. <view class="add-guest-btn">
  26. <u-button type="primary" :disabled="this.guestListDebug.length >= 3 && addGuestButtonDisabled"
  27. @click="addGuest">添加入住人</u-button>
  28. </view>
  29. <view class="checkin-btn">
  30. <u-button type="primary" @click="checkin" :loading="debugCheckinButtonLoading"
  31. :loadingText="debugCheckinButtonLoadingText" :disabled="checkinButtonDisabled">入住</u-button>
  32. </view>
  33. </view>
  34. </view>
  35. <u-toast ref="uToast"></u-toast>
  36. </view>
  37. </template>
  38. <script>
  39. import {
  40. mapState,
  41. mapMutations
  42. } from 'vuex'
  43. import moment from 'moment'
  44. export default {
  45. data() {
  46. return {
  47. nameTip: '姓名:',
  48. idNumberTip: '证件号:',
  49. uploadPicTip: '上传人脸:',
  50. guestListDebug: [{
  51. id: 0,
  52. name: '',
  53. idNumber: '',
  54. pic: [],
  55. picBase64: '',
  56. picValid: false,
  57. checkinButtonDisabled: false
  58. }],
  59. guestModel: {
  60. guestInfo: {
  61. name: '',
  62. idNumber: '',
  63. pic: []
  64. }
  65. },
  66. reservation: {},
  67. debugCheckinButtonLoading: false,
  68. debugCheckinButtonLoadingText: '办理中',
  69. addGuestButtonDisabled: false
  70. };
  71. },
  72. computed: {
  73. ...mapState('m_user', ['userInfo']),
  74. ...mapState('m_business', ['hotelParams']),
  75. },
  76. methods: {
  77. addGuest() {
  78. if (this.guestListDebug.length < 3) {
  79. this.guestListDebug.push({
  80. id: this.guestListDebug[this.guestListDebug.length - 1].id + 1,
  81. name: '',
  82. idNumber: '',
  83. pic: [],
  84. picBase64: '',
  85. picValid: false
  86. })
  87. console.log(this.guestListDebug[this.guestListDebug.length - 1].id)
  88. } else {
  89. uni.$showMsg('入住人数已达到上限!')
  90. }
  91. },
  92. oversize(){
  93. uni.$showMsg('图片超出允许大小(1.5M)')
  94. },
  95. //删除图片
  96. deletePic(event) {
  97. console.log(event.name)
  98. this.guestListDebug.forEach(guest => {
  99. console.log(guest)
  100. if (guest.id == event.name) {
  101. guest.pic = []
  102. guest.picBase64 = ''
  103. return
  104. }
  105. })
  106. },
  107. //上传图片
  108. async afterRead(event) {
  109. let _this = this
  110. let params = {
  111. type: 'loading',
  112. message: '正在加载',
  113. duration: '500'
  114. }
  115. this.$refs.uToast.show({
  116. ...params,
  117. complete() {
  118. console.log(event)
  119. _this.guestListDebug.forEach(guest => {
  120. console.log(guest.id)
  121. console.log(guest.id == event.name)
  122. if (guest.id == event.name) {
  123. guest.pic.push(event.file)
  124. uni.getFileSystemManager().readFile({
  125. filePath: guest.pic[0].url, //选择图片返回的相对路径
  126. encoding: 'base64', //编码格式
  127. success: res => {
  128. console.log(res);
  129. guest.picBase64 = res.data
  130. uni.$http.post('/faceVerification/checkPic', {
  131. hotelId: _this.reservation.hotelId,
  132. faceData: guest.picBase64
  133. }).then((res) => {
  134. if (res.data.code === 200 && res.data
  135. .success ===
  136. true) {
  137. uni.$showMsg('上传成功!')
  138. guest.picValid = true
  139. } else {
  140. uni.$showMsg('未检测到人脸,请重新上传!')
  141. }
  142. console.log(res)
  143. })
  144. },
  145. fail: (e) => {
  146. uni.$showMsg('图片转换失败,请重试!')
  147. console.log("图片转换失败!");
  148. console.log(e);
  149. }
  150. })
  151. }
  152. })
  153. }
  154. })
  155. },
  156. deleteGuest(id) {
  157. console.log(id)
  158. this.guestListDebug = this.guestListDebug.filter(guest => guest.id != id)
  159. },
  160. async checkin() {
  161. //检查姓名、证件号是否填入,上传图片是否通过检查
  162. if (this.guestListDebug.length < 1) {
  163. uni.$showMsg('请添加入住人!')
  164. return
  165. } else {
  166. let isEmpty = false;
  167. let allPicValid = true;
  168. this.guestListDebug.forEach((guest) =>
  169. Object.keys(guest).forEach(key => {
  170. console.log(key + ' + ' + guest[key])
  171. if (!guest.picValid) {
  172. allPicValid = false
  173. }
  174. if (guest[key] === null || guest[key] === undefined || guest[
  175. key] === '') {
  176. isEmpty = true;
  177. return
  178. }
  179. })
  180. )
  181. if (isEmpty) {
  182. uni.$showMsg('请正确填写信息!')
  183. return
  184. }
  185. if (!allPicValid) {
  186. uni.$showMsg('请检查图片!')
  187. return
  188. }
  189. }
  190. //办理入住
  191. this.debugCheckinButtonLoading = true
  192. try {
  193. let start = new Date(this.reservation.startTime)
  194. let checkinInfo = {
  195. hotelId: this.reservation.hotelId,
  196. building: this.reservation.building,
  197. floorId: this.reservation.floor,
  198. roomId: this.reservation.room,
  199. startTime: moment(this.reservation.startTime).format('YYMMDDHHmmss'),
  200. endTime: moment(this.reservation.endTime).format('YYMMDDHHmmss'),
  201. cardId: '0',
  202. userType: 1,
  203. isDebug: this.userInfo.isDebug
  204. }
  205. let checkinResult = new Array(this.guestListDebug.length).fill(false)
  206. console.log(checkinResult)
  207. for (let i = 0; i < this.guestListDebug.length; i++) {
  208. checkinInfo.userName = this.guestListDebug[i].name;
  209. checkinInfo.userId = this.guestListDebug[i].idNumber;
  210. checkinInfo.faceData = this.guestListDebug[i].picBase64;
  211. let res = await uni.$http.post('/checkin', checkinInfo)
  212. console.log(res)
  213. if (res.data.code == 200 && res.data.success === true) {
  214. checkinResult[i] = true
  215. console.log('checkinResult[' + i + '] = true')
  216. }
  217. }
  218. if (checkinResult.indexOf(false) < 0) {
  219. uni.$showMsg('办理成功!')
  220. setTimeout(() => {
  221. uni.switchTab({
  222. url: '/pages/home/home'
  223. })
  224. }, 1500)
  225. } else {
  226. let failMsg = '办理失败!'
  227. uni.$showMsg(failMsg)
  228. }
  229. } catch (e) {
  230. console.log(e)
  231. let failMsg = '办理失败!'
  232. uni.$showMsg(failMsg)
  233. } finally {
  234. this.debugCheckinButtonLoading = false
  235. }
  236. },
  237. async getReservationInfo() {
  238. let res = await uni.$http.post('/userPicRoomInfo/queryByCondition', {
  239. userId: this.userInfo.userId,
  240. // userId: 29,
  241. status: true,
  242. pageNo: 1,
  243. pageSize: 1
  244. })
  245. console.log(res)
  246. if (res.data.data.records?.length > 0) {
  247. this.reservation = res.data.data.records[0]
  248. this.reservation.startTime = moment(this.reservation.startTime).format('YYYY/MM/DD HH:mm:ss')
  249. this.reservation.endTime = moment(this.reservation.endTime).format('YYYY/MM/DD HH:mm:ss')
  250. } else {
  251. this.reservation = {}
  252. }
  253. console.log(this.reservation)
  254. }
  255. },
  256. onLoad() {
  257. this.getReservationInfo()
  258. this.guestListDebug[0].idNumber = this.userInfo.idNumber
  259. this.guestListDebug[0].name = this.userInfo.name
  260. }
  261. }
  262. </script>
  263. <style lang="scss">
  264. .is-debug {
  265. height: 900rpx;
  266. overflow: scroll;
  267. }
  268. .guest-list {
  269. border: 1rpx solid grey;
  270. margin: 20rpx;
  271. }
  272. .guest-form-item {
  273. display: flex;
  274. width: 80%;
  275. }
  276. .guest-form-item-tip {
  277. width: 160rpx;
  278. display: flex;
  279. margin-left: 20rpx;
  280. }
  281. .add-guest-btn,
  282. .checkin-btn {
  283. width: 80%;
  284. height: 72rpx;
  285. margin: 40rpx auto;
  286. }
  287. .u-input {
  288. width: 80%;
  289. }
  290. .guest-form-bottom {
  291. display: flex;
  292. }
  293. .delete-guest-btn {
  294. margin: 0 auto;
  295. position: relative;
  296. top: 30%;
  297. /*偏移*/
  298. transform: translateY(30%);
  299. text-align: center;
  300. }
  301. .bottom {
  302. z-index: 999;
  303. position: fixed;
  304. bottom: 0;
  305. background-color: white;
  306. width: 100%;
  307. height: 300rpx;
  308. }
  309. </style>