elevatorControl.vue 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336
  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="checkinInfo.hotelName" 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. <text class="tip">您还未入住!</text>
  75. </view>
  76. </view>
  77. </template>
  78. <script>
  79. import {
  80. mapState
  81. } from "vuex";
  82. import {
  83. getCheckinInfo,
  84. getElevatorQRCode,
  85. } from "../../utils/api";
  86. import moment from "moment";
  87. import {
  88. QRCodeSVG
  89. } from '../../utils/qrCode/qrcode/src/index';
  90. import svgToDataURL from "svg-to-dataurl";
  91. import {
  92. IMG_BASE_URL
  93. } from "../../config"
  94. import NavigateBar from "../../components/navigateBar/navigate-bar.vue";
  95. export default {
  96. components: {
  97. NavigateBar
  98. },
  99. data() {
  100. return {
  101. checkinInfo: {},
  102. qrCodeDate: "",
  103. qrCode: "",
  104. diaplayWidth: "",
  105. qrCodeWidth: "",
  106. showQRCode: false,
  107. loadedTime: null,
  108. waitTime: 10,
  109. showPrompt: false
  110. }
  111. },
  112. computed: {
  113. ...mapState("m_business", ["currentHotel"]),
  114. ...mapState("m_user", ["userInfo"])
  115. },
  116. methods: {
  117. getUrl() {
  118. return svgToDataURL(this.qrCode)
  119. },
  120. formatDateTime(dateTime) {
  121. return moment(dateTime).format("YYYY年MM月DD日HH时mm分");
  122. },
  123. timeCountDown() {
  124. const that = this
  125. let intervalId = setInterval(() => {
  126. that.waitTime--
  127. if (that.waitTime === 0) {
  128. that.showPrompt = false
  129. that.showQRCode = false
  130. clearInterval(intervalId)
  131. }
  132. }, 60000)
  133. },
  134. async renderQRCode() {
  135. const qrCodeMsg = await getElevatorQRCode({
  136. hotelId: this.currentHotel.hotelId,
  137. building: 1,
  138. floor: this.checkinInfo.floor,
  139. customerId: this.checkinInfo.customerUserId,
  140. customerType: 1,
  141. status: 1,
  142. activeTime: moment().add(10, "m")
  143. })
  144. // console.log("qrCodeMsg", qrCodeMsg);
  145. if (!qrCodeMsg.data.success || !qrCodeMsg.data.data.data) {
  146. console.log("获取梯控二维码data数据失败", qrCodeMsg.data);
  147. uni.showModal({
  148. title: "获取梯控二维码失败",
  149. content: "获取梯控二维码失败,请检查网络连接后重试。",
  150. });
  151. return
  152. }
  153. this.qrCodeDate = qrCodeMsg.data.data.data
  154. // console.log("获取qrCodeDate", this.qrCodeDate);
  155. this.$nextTick(async () => {
  156. let picBase64 = ""
  157. // #ifdef MP-WEIXIN
  158. let pic = await uni.request({
  159. url: `${IMG_BASE_URL}/yun_xiang_zhu_square.png`,
  160. responseType: 'arraybuffer',
  161. })
  162. // console.log("pic",pic);
  163. picBase64 = "data:image/png;base64," + Buffer.from(pic[1].data).toString('base64');
  164. // #endif
  165. // #ifdef MP-ALIPAY
  166. let picRes = await uni.request({
  167. url: `${IMG_BASE_URL}/yun_xiang_zhu_square.png`,
  168. dataType: "base64"
  169. })
  170. picBase64 = picRes[1].data
  171. // #endif
  172. const qrSvg = new QRCodeSVG(
  173. this.qrCodeDate, {
  174. padding: 0,
  175. image: {
  176. source: picBase64,
  177. width: '25%',
  178. height: '25%',
  179. x: 'center',
  180. y: 'center',
  181. border: 1
  182. },
  183. level: "M"
  184. }
  185. )
  186. this.qrCode = qrSvg.toString()
  187. this.showQRCode = true
  188. this.timeCountDown()
  189. })
  190. },
  191. async rerenderQrCode() {
  192. await this.renderQRCode()
  193. this.waitTime = 10
  194. this.showPrompt = true
  195. }
  196. },
  197. async onLoad() {
  198. const info = await getCheckinInfo({
  199. userIdNumber: this.userInfo.idNumber,
  200. hotelId: this.currentHotel.hotelId,
  201. status: 1,
  202. pageNo: 1,
  203. pageSize: 1,
  204. })
  205. // console.log("getCheckinInfo", info);
  206. if (!info.data.data.records.length) {
  207. console.log("未查询到入住记录");
  208. return
  209. }
  210. this.checkinInfo = info.data.data.records[0];
  211. // console.log("入住记录", this.checkinInfo);
  212. // #ifdef MP-WEIXIN
  213. const wxSystemInfo = await wx.getSystemInfo()
  214. // console.log("systeminfo", systemInfo.screenWidth);
  215. this.diaplayWidth = (wxSystemInfo.screenWidth - 40).toFixed() + "px"
  216. this.qrCodeWidth = (wxSystemInfo.screenWidth * 3 / 5).toFixed() + "px"
  217. // #endif
  218. // #ifdef MP-ALIPAY
  219. let alipaySystemInfo = await uni.getSystemInfo()
  220. alipaySystemInfo = alipaySystemInfo[1].screen
  221. // console.log("alipaySystemInfo",alipaySystemInfo);
  222. this.diaplayWidth = (alipaySystemInfo.width - 40).toFixed() + "px"
  223. this.qrCodeWidth = (alipaySystemInfo.width * 3 / 5).toFixed() + "px"
  224. // #endif
  225. await this.renderQRCode()
  226. this.showPrompt = true
  227. },
  228. // #ifdef MP-WEIXIN
  229. onShareAppMessage(info) {
  230. return {
  231. title: '源享住',
  232. path: 'pages/login/login',
  233. imageUrl: "/static/logo.png"
  234. }
  235. }
  236. // #endif
  237. }
  238. </script>
  239. <style lang="scss">
  240. page {
  241. background-color: #FFFFFF;
  242. .have-reservation {
  243. .info {
  244. background: #F5F8FE;
  245. box-shadow: -6px 17px 21px 0px rgba(112, 152, 246, 0.14);
  246. margin-bottom: 80rpx;
  247. .title {
  248. display: flex;
  249. justify-content: space-between;
  250. padding: 0 40rpx;
  251. line-height: 80rpx;
  252. border-bottom: 2rpx solid #E0E8FB;
  253. }
  254. .checkin-info {
  255. margin: 20rpx auto;
  256. .checkin-info--item {
  257. display: flex;
  258. margin: 0 40rpx;
  259. .checkin-info--item--text {
  260. margin: 10rpx;
  261. margin-left: 0;
  262. }
  263. &:last-child {
  264. padding-bottom: 20rpx;
  265. }
  266. }
  267. }
  268. }
  269. .qrcode {
  270. display: flex;
  271. margin: 10rpx auto;
  272. padding: 10rpx 20rpx;
  273. background: #ffffff;
  274. border-radius: 10rpx;
  275. }
  276. .prompt {
  277. margin: 0 auto;
  278. display: flex;
  279. flex-direction: column;
  280. justify-content: center;
  281. align-items: center;
  282. .prompt--text {
  283. background-color: #fff;
  284. display: flex;
  285. flex-direction: column;
  286. justify-content: center;
  287. align-items: center;
  288. margin: 0 20rpx;
  289. padding: 10rpx 20rpx;
  290. border-radius: 10rpx;
  291. }
  292. .prompt--count-down__button {
  293. display: flex;
  294. align-items: center;
  295. justify-content: center;
  296. padding: 40rpx;
  297. }
  298. }
  299. }
  300. .not-reservation {
  301. display: flex;
  302. justify-content: center;
  303. height: 100%;
  304. text-align: center;
  305. vertical-align: 100rpx;
  306. .tip {
  307. padding-top: 40%;
  308. }
  309. }
  310. }
  311. </style>