elevatorControl.vue 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324
  1. <template>
  2. <view>
  3. <view class="top">
  4. <!-- #ifdef MP-WEIXIN -->
  5. <NavigateBar title="梯控二维码" control="back" bgcolor="#a09cc4"></NavigateBar>
  6. <!-- #endif -->
  7. <!-- #ifdef MP-ALIPAY -->
  8. <NavigateBar title="梯控二维码" bgcolor="#a09cc4"></NavigateBar>
  9. <!-- #endif -->
  10. </view>
  11. <view class="have-reservation" v-if="Object.keys(checkinInfo).length > 0">
  12. <view class="info">
  13. <view class="title">
  14. <view class="hotel-name">
  15. <u-text :text="currentHotel.name" bold color="#333333" size="30rpx"></u-text>
  16. </view>
  17. <view class="tips">
  18. <u-text text="入住信息" color="#666666" size="24rpx"></u-text>
  19. </view>
  20. </view>
  21. <view class="checkin-info">
  22. <view class="checkin-info--item">
  23. <view class="checkin-info--item--text">
  24. <u-text text="所在楼层 : " color="#999999" size="26rpx"></u-text>
  25. </view>
  26. <view class="checkin-info--item--text">
  27. <u-text :text="checkinInfo.floor+'楼'" color="#999999" size="26rpx"></u-text>
  28. </view>
  29. </view>
  30. <view class="checkin-info--item">
  31. <view class="checkin-info--item--text">
  32. <u-text text="房间信息 : " color="#999999" size="26rpx"></u-text>
  33. </view>
  34. <view class="checkin-info--item--text">
  35. <u-text :text="checkinInfo.room" color="#999999" size="26rpx"></u-text>
  36. </view>
  37. </view>
  38. <view class="checkin-info--item">
  39. <view class="checkin-info--item--text">
  40. <u-text text="起始时间 : " color="#999999" size="26rpx"></u-text>
  41. </view>
  42. <view class="checkin-info--item--text">
  43. <u-text :text="formatDateTime(checkinInfo.startTime)" color="#999999" size="26rpx"></u-text>
  44. </view>
  45. </view>
  46. <view class="checkin-info--item">
  47. <view class="checkin-info--item--text">
  48. <u-text text="结束时间 : " color="#999999" size="26rpx"></u-text>
  49. </view>
  50. <view class="checkin-info--item--text">
  51. <u-text :text="formatDateTime(checkinInfo.endTime)" color="#999999" size="26rpx"></u-text>
  52. </view>
  53. </view>
  54. </view>
  55. </view>
  56. <view class="qrcode" :style="{width: qrCodeWidth, height: qrCodeWidth, display: showQRCode ? '' : 'none'}">
  57. <img style="width: 100%; height: 100%;" :src="getUrl()" />
  58. </view>
  59. <view class="prompt" :style="{width: diaplayWidth}">
  60. <view class="prompt--text" v-if="showPrompt">
  61. <text>
  62. 请将梯控二维码正对扫描框进行梯控识别
  63. </text>
  64. <text style="margin-top: 10rpx;">
  65. {{ `该二维码将在${waitTime}分钟后失效` }}
  66. </text>
  67. </view>
  68. <view v-if="!showPrompt">
  69. <button class="prompt--count-down__button" @click="rerenderQrCode">二维码失效,点击重新生成二维码</button>
  70. </view>
  71. </view>
  72. </view>
  73. <view v-else class="not-reservation">
  74. <u-text class="tip" text="您还未入住!" align="center"></u-text>
  75. <u-text class="tip" text="若已退房或房间到期,请至前台办理" align="center"></u-text>
  76. </view>
  77. </view>
  78. </template>
  79. <script>
  80. import {
  81. mapState
  82. } from "vuex";
  83. import {
  84. getCheckinInfo,
  85. getElevatorQRCode,
  86. } from "../../utils/api";
  87. import moment from "moment";
  88. import {
  89. QRCodeSVG
  90. } from '../../utils/qrCode/qrcode/src/index';
  91. import svgToDataURL from "svg-to-dataurl";
  92. import {
  93. IMG_BASE_URL
  94. } from "../../config"
  95. import NavigateBar from "../../components/navigateBar/navigate-bar.vue";
  96. export default {
  97. components: {
  98. NavigateBar
  99. },
  100. data() {
  101. return {
  102. checkinInfo: {},
  103. qrCodeDate: "",
  104. qrCode: "",
  105. diaplayWidth: "",
  106. qrCodeWidth: "",
  107. showQRCode: false,
  108. loadedTime: null,
  109. waitTime: 10,
  110. showPrompt: false
  111. }
  112. },
  113. computed: {
  114. ...mapState("m_business", ["currentHotel"]),
  115. ...mapState("m_user", ["userInfo"])
  116. },
  117. methods: {
  118. getUrl() {
  119. return svgToDataURL(this.qrCode)
  120. },
  121. formatDateTime(dateTime) {
  122. return moment(dateTime).format("YYYY年MM月DD日HH时mm分");
  123. },
  124. timeCountDown() {
  125. const that = this
  126. let intervalId = setInterval(() => {
  127. that.waitTime--
  128. if (that.waitTime === 0) {
  129. that.showPrompt = false
  130. that.showQRCode = false
  131. clearInterval(intervalId)
  132. }
  133. }, 60000)
  134. },
  135. async renderQRCode() {
  136. const qrCodeMsg = await getElevatorQRCode({
  137. hotelId: this.currentHotel.hotelId,
  138. building: 1,
  139. floor: this.checkinInfo.floor,
  140. customerId: this.userInfo.idNumber,
  141. customerType: 1,
  142. status: 1,
  143. activeTime: moment().add(10, "m")
  144. })
  145. // console.log("qrCodeMsg", qrCodeMsg);
  146. if (!qrCodeMsg.data.success || !qrCodeMsg.data.data.data) {
  147. console.log("获取梯控二维码data数据失败", qrCodeMsg.data);
  148. uni.showModal({
  149. title: "获取梯控二维码失败",
  150. content: "获取梯控二维码失败,请检查网络连接后重试。",
  151. });
  152. return
  153. }
  154. this.qrCodeDate = qrCodeMsg.data.data.data
  155. // console.log("获取qrCodeDate", this.qrCodeDate);
  156. this.$nextTick(async () => {
  157. let picBase64 = ""
  158. // #ifdef MP-WEIXIN
  159. let pic = await uni.request({
  160. url: `${IMG_BASE_URL}/yun_xiang_zhu_square.png`,
  161. responseType: 'arraybuffer',
  162. })
  163. // console.log("pic",pic);
  164. picBase64 = "data:image/png;base64," + Buffer.from(pic[1].data).toString('base64');
  165. // #endif
  166. // #ifdef MP-ALIPAY
  167. let picRes = await uni.request({
  168. url: `${IMG_BASE_URL}/yun_xiang_zhu_square.png`,
  169. dataType: "base64"
  170. })
  171. picBase64 = picRes[1].data
  172. // #endif
  173. const qrSvg = new QRCodeSVG(
  174. this.qrCodeDate, {
  175. padding: 0,
  176. image: {
  177. source: picBase64,
  178. width: '25%',
  179. height: '25%',
  180. x: 'center',
  181. y: 'center',
  182. border: 1
  183. },
  184. level: "M"
  185. }
  186. )
  187. this.qrCode = qrSvg.toString()
  188. this.showQRCode = true
  189. this.timeCountDown()
  190. })
  191. },
  192. async rerenderQrCode() {
  193. await this.renderQRCode()
  194. this.waitTime = 10
  195. this.showPrompt = true
  196. }
  197. },
  198. async onLoad() {
  199. // 获取入住记录
  200. let {data: infoRes} = await getCheckinInfo(this.currentHotel.hotelId)
  201. console.log("获取入住记录", infoRes);
  202. if (infoRes.code !== 200 || !infoRes.success || !infoRes.data) {
  203. console.log("获取入住记录失败", infoRes);
  204. return
  205. }
  206. this.checkinInfo = infoRes.data;
  207. // console.log("入住记录", this.checkinInfo);
  208. // #ifdef MP-WEIXIN
  209. const wxSystemInfo = await wx.getSystemInfo()
  210. // console.log("systeminfo", systemInfo.screenWidth);
  211. this.diaplayWidth = (wxSystemInfo.screenWidth - 40).toFixed() + "px"
  212. this.qrCodeWidth = (wxSystemInfo.screenWidth * 3 / 5).toFixed() + "px"
  213. // #endif
  214. // #ifdef MP-ALIPAY
  215. let alipaySystemInfo = await uni.getSystemInfo()
  216. alipaySystemInfo = alipaySystemInfo[1].screen
  217. // console.log("alipaySystemInfo",alipaySystemInfo);
  218. this.diaplayWidth = (alipaySystemInfo.width - 40).toFixed() + "px"
  219. this.qrCodeWidth = (alipaySystemInfo.width * 3 / 5).toFixed() + "px"
  220. // #endif
  221. await this.renderQRCode()
  222. this.showPrompt = true
  223. },
  224. // #ifdef MP-WEIXIN
  225. onShareAppMessage(info) {
  226. return {
  227. title: '源享住',
  228. path: 'pages/login/login',
  229. imageUrl: "/static/logo.png"
  230. }
  231. }
  232. // #endif
  233. }
  234. </script>
  235. <style lang="scss">
  236. page {
  237. background-color: #FFFFFF;
  238. .have-reservation {
  239. .info {
  240. background: #F5F8FE;
  241. box-shadow: -6px 17px 21px 0px rgba(112, 152, 246, 0.14);
  242. margin-bottom: 80rpx;
  243. .title {
  244. display: flex;
  245. justify-content: space-between;
  246. padding: 0 40rpx;
  247. line-height: 80rpx;
  248. border-bottom: 2rpx solid #E0E8FB;
  249. }
  250. .checkin-info {
  251. margin: 20rpx auto;
  252. .checkin-info--item {
  253. display: flex;
  254. margin: 0 40rpx;
  255. .checkin-info--item--text {
  256. margin: 10rpx;
  257. margin-left: 0;
  258. }
  259. &:last-child {
  260. padding-bottom: 20rpx;
  261. }
  262. }
  263. }
  264. }
  265. .qrcode {
  266. display: flex;
  267. margin: 10rpx auto;
  268. padding: 10rpx 20rpx;
  269. background: #ffffff;
  270. border-radius: 10rpx;
  271. }
  272. .prompt {
  273. margin: 0 auto;
  274. display: flex;
  275. flex-direction: column;
  276. justify-content: center;
  277. align-items: center;
  278. .prompt--text {
  279. background-color: #fff;
  280. display: flex;
  281. flex-direction: column;
  282. justify-content: center;
  283. align-items: center;
  284. margin: 0 20rpx;
  285. padding: 10rpx 20rpx;
  286. border-radius: 10rpx;
  287. }
  288. .prompt--count-down__button {
  289. display: flex;
  290. align-items: center;
  291. justify-content: center;
  292. padding: 40rpx;
  293. }
  294. }
  295. }
  296. }
  297. .not-reservation {
  298. margin-top: 40%;
  299. }
  300. </style>