index.vue 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. <template>
  2. <view :class="['page']">
  3. <view class="device-header">
  4. <view class="device-header_name">
  5. <text>洗车机编号:{{ state.device.shortId }}</text>
  6. </view>
  7. <view class="device-header_fun">
  8. <view class="device-header_func-tag" v-for="f in state.device.functionList" :key="f" style="margin-right: 10px;">
  9. <uv-tags :text="f" size="mini" plain plainFill bgColor="#19A497" color="white"> </uv-tags>
  10. </view>
  11. </view>
  12. <view class="device-header_fun">
  13. <uv-tags plain size="mini" type="primary" :text="fmtDictName('WashDevice.status',state.device.state)"></uv-tags>
  14. </view>
  15. </view>
  16. <view class="device-body">
  17. <view class="device-body_ops" @click="debounceStartStopDevice">
  18. <text v-if="state.device.state==='idle'">启动设备</text>
  19. <text v-else>停止设备</text>
  20. </view>
  21. <view class=device-body_guide>
  22. <view>●点击上方【启动】按钮启动设备;
  23. </view>
  24. <view>●设备启动后,请在设备功能面板按下功能按键以选择服务项目;
  25. </view>
  26. <view>●洗车过程中再次按下功能按键可以暂停次功能,暂停过程中将停止计费,如需恢复请再次按下功能按键;
  27. </view>
  28. <view>●洗车结束后,请按下结算按键或小程序【结束】按钮,设备停止运行之后将结束计费;
  29. </view>
  30. <view>●请在洗车完成后尽快将车辆驶离工位以方便后续用户,谢谢配合。
  31. </view>
  32. </view>
  33. <!-- <view class="device-body_ops-time">{{ state.time }}</view>-->
  34. </view>
  35. </view>
  36. </template>
  37. <script setup lang="ts">
  38. import {onHide, onLoad, onShow} from "@dcloudio/uni-app";
  39. import {reactive, ref} from "vue";
  40. import {debounce, fmtDictName} from "@/utils/common";
  41. import {get, post} from "@/utils/https";
  42. const initState = () => ({
  43. device: {
  44. functions:[],
  45. deviceName:'',
  46. state:''
  47. },
  48. time: "00:00:00",
  49. start: new Date()
  50. })
  51. const state = reactive(initState())
  52. onHide(() => {
  53. Object.assign(state, initState());
  54. })
  55. onLoad((options:any) => {
  56. console.log("device onLoad>>>>", options)
  57. let id = options?.shortId;
  58. if (!id) {
  59. let query = decodeURIComponent(options.q);
  60. let scanTime = options.scancode_time;
  61. console.log(query,scanTime)
  62. if(query){
  63. id = query.split("#")[1]
  64. }else{
  65. return;
  66. }
  67. }
  68. state.device = getApp<any>().globalData.last.device;
  69. loadDeviceDetail(id);
  70. });
  71. const loadDeviceDetail = (id: number) => {
  72. get(`/wash-device/queryDevice/${id}`).then((res: any) => {
  73. res.functionList = res.funcs.split("|")||[]
  74. state.device = res;
  75. }).catch(e => {
  76. console.error(e)
  77. })
  78. // countTime();
  79. }
  80. const handleNavigateBack = () => {
  81. uni.navigateBack();
  82. }
  83. const debounceStartStopDevice = debounce(()=>{
  84. handleClickDevice();
  85. },600)
  86. const handleClickDevice = () => {
  87. if(state.device?.state==='idle'){
  88. uni.showLoading({
  89. title: "启动中",
  90. mask: true,
  91. });
  92. post(`/wash-device/startDevice/${state.device.shortId}`).then((res:any)=>{
  93. uni.hideLoading();
  94. uni.showToast({
  95. title:'设备启动成功'
  96. })
  97. })
  98. }else{
  99. uni.showLoading({
  100. title: "停止中",
  101. mask: true,
  102. });
  103. post(`/wash-device/stopDevice/${state.device.shortId}`).then((res:any)=>{
  104. uni.hideLoading()
  105. })
  106. }
  107. }
  108. const countTime = () => {
  109. setInterval(() => {
  110. let delta = new Date().getTime() - state.start.getTime();
  111. delta = delta / 1000;
  112. let hour = (delta / 3600).toFixed(0);
  113. let min = ((delta % 3600) / 60).toFixed(0);
  114. let second = ((delta % 3600) % 60).toFixed(0);
  115. state.time = [
  116. Number(hour) > 9 ? hour : `0${hour}`,
  117. Number(min) > 9 ? min : `0${min}`,
  118. Number(second) > 9 ? second : `0${second}`
  119. ].join(":")
  120. }, 1000)
  121. }
  122. </script>
  123. <style lang="scss" scoped>
  124. .page {
  125. height: 100vh;
  126. width: 100%;
  127. background-color: #f6f7fa;
  128. }
  129. .device-header {
  130. padding: 20rpx;
  131. display: flex;
  132. flex-direction: column;
  133. justify-content: center;
  134. align-items: center;
  135. &_name {
  136. font-weight: 500;
  137. margin: 15rpx 0;
  138. }
  139. &_fun {
  140. font-size: 13px;
  141. color: #7a7a7a;
  142. margin: 10rpx 0;
  143. display: inline-flex;
  144. &-tag{
  145. margin-right: 10px;
  146. }
  147. }
  148. }
  149. .device-body {
  150. flex-grow: 1;
  151. margin-top: 60rpx;
  152. display: flex;
  153. flex-direction: column;
  154. justify-content: center;
  155. align-items: center;
  156. align-content: center;
  157. &_ops {
  158. display: flex;
  159. justify-content: center;
  160. align-items: center;
  161. align-content: center;
  162. width: 300rpx;
  163. height: 300rpx;
  164. border-radius: 50%;
  165. background-color: $uni-color-primary;
  166. color: white;
  167. font-size: 28px;
  168. font-weight: 500;
  169. }
  170. &_guide{
  171. width: 80%;
  172. margin-top: 40px;
  173. font-size: 14px;
  174. }
  175. }
  176. </style>