elevatorControl.vue 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331
  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. <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.userInfo.idNumber,
  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. // 获取入住记录
  199. let {data: infoRes} = await getCheckinInfo(this.currentHotel.hotelId)
  200. console.log("获取入住记录", infoRes);
  201. if (infoRes.code !== 200 || !infoRes.success) {
  202. console.log("获取入住记录失败", info.data.data);
  203. return
  204. }
  205. this.checkinInfo = infoRes.data;
  206. // console.log("入住记录", this.checkinInfo);
  207. // #ifdef MP-WEIXIN
  208. const wxSystemInfo = await wx.getSystemInfo()
  209. // console.log("systeminfo", systemInfo.screenWidth);
  210. this.diaplayWidth = (wxSystemInfo.screenWidth - 40).toFixed() + "px"
  211. this.qrCodeWidth = (wxSystemInfo.screenWidth * 3 / 5).toFixed() + "px"
  212. // #endif
  213. // #ifdef MP-ALIPAY
  214. let alipaySystemInfo = await uni.getSystemInfo()
  215. alipaySystemInfo = alipaySystemInfo[1].screen
  216. // console.log("alipaySystemInfo",alipaySystemInfo);
  217. this.diaplayWidth = (alipaySystemInfo.width - 40).toFixed() + "px"
  218. this.qrCodeWidth = (alipaySystemInfo.width * 3 / 5).toFixed() + "px"
  219. // #endif
  220. await this.renderQRCode()
  221. this.showPrompt = true
  222. },
  223. // #ifdef MP-WEIXIN
  224. onShareAppMessage(info) {
  225. return {
  226. title: '源享住',
  227. path: 'pages/login/login',
  228. imageUrl: "/static/logo.png"
  229. }
  230. }
  231. // #endif
  232. }
  233. </script>
  234. <style lang="scss">
  235. page {
  236. background-color: #FFFFFF;
  237. .have-reservation {
  238. .info {
  239. background: #F5F8FE;
  240. box-shadow: -6px 17px 21px 0px rgba(112, 152, 246, 0.14);
  241. margin-bottom: 80rpx;
  242. .title {
  243. display: flex;
  244. justify-content: space-between;
  245. padding: 0 40rpx;
  246. line-height: 80rpx;
  247. border-bottom: 2rpx solid #E0E8FB;
  248. }
  249. .checkin-info {
  250. margin: 20rpx auto;
  251. .checkin-info--item {
  252. display: flex;
  253. margin: 0 40rpx;
  254. .checkin-info--item--text {
  255. margin: 10rpx;
  256. margin-left: 0;
  257. }
  258. &:last-child {
  259. padding-bottom: 20rpx;
  260. }
  261. }
  262. }
  263. }
  264. .qrcode {
  265. display: flex;
  266. margin: 10rpx auto;
  267. padding: 10rpx 20rpx;
  268. background: #ffffff;
  269. border-radius: 10rpx;
  270. }
  271. .prompt {
  272. margin: 0 auto;
  273. display: flex;
  274. flex-direction: column;
  275. justify-content: center;
  276. align-items: center;
  277. .prompt--text {
  278. background-color: #fff;
  279. display: flex;
  280. flex-direction: column;
  281. justify-content: center;
  282. align-items: center;
  283. margin: 0 20rpx;
  284. padding: 10rpx 20rpx;
  285. border-radius: 10rpx;
  286. }
  287. .prompt--count-down__button {
  288. display: flex;
  289. align-items: center;
  290. justify-content: center;
  291. padding: 40rpx;
  292. }
  293. }
  294. }
  295. .not-reservation {
  296. display: flex;
  297. justify-content: center;
  298. height: 100%;
  299. text-align: center;
  300. vertical-align: 100rpx;
  301. .tip {
  302. padding-top: 40%;
  303. }
  304. }
  305. }
  306. </style>