index.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665
  1. <template>
  2. <view class="page-container">
  3. <scroll-view class="content-scroll" scroll-y="true">
  4. <!-- 设备信息卡片 -->
  5. <view class="device-info-card">
  6. <view class="device-number">
  7. <uv-icon name="car" size="24" color="#C6171E"></uv-icon>
  8. <text class="number-text">洗车机 No.{{ state.device?.shortId }}</text>
  9. </view>
  10. <view class="device-status" :class="'status-' + (state.device?.state || 'idle')">
  11. <view class="status-dot"></view>
  12. <text>{{ fmtDictName('WashDevice.state',state.device?.state) }}</text>
  13. </view>
  14. <view class="device-functions">
  15. <view
  16. class="function-item"
  17. v-for="f in state.device?.functionList"
  18. :key="f"
  19. >
  20. <uv-icon name="checkbox-mark" size="14" color="#C6171E"></uv-icon>
  21. <text>{{ f }}</text>
  22. </view>
  23. </view>
  24. </view>
  25. <!-- 操作按钮卡片 -->
  26. <view class="control-card">
  27. <view class="control-wrapper">
  28. <view
  29. class="control-button"
  30. :class="{ 'control-button--active': state.device?.state !== 'idle' }"
  31. @click="debounceStartStopDevice"
  32. >
  33. <view class="button-icon">
  34. <!-- 空闲状态显示播放图标 -->
  35. <view v-if="state.device?.state==='idle'" class="icon-play">
  36. <uv-icon name="play-circle-fill" size="48" color="#fff"></uv-icon>
  37. </view>
  38. <!-- 忙碌状态显示停止图标 -->
  39. <view v-else class="icon-stop">
  40. <uv-icon name="pause-circle-fill" size="48" color="#fff"></uv-icon>
  41. </view>
  42. </view>
  43. <text class="button-text" v-if="state.device?.state==='idle'">启动设备</text>
  44. <text class="button-text" v-else>停止设备</text>
  45. <text class="button-tip">{{ state.device?.state==='idle' ? '点击开始洗车' : '点击结束洗车' }}</text>
  46. </view>
  47. </view>
  48. </view>
  49. <!-- 操作指南卡片 -->
  50. <view class="guide-card">
  51. <view class="card-header">
  52. <view class="header-line"></view>
  53. <text class="header-title">操作指南</text>
  54. <uv-icon name="question-circle" size="18" color="#909399"></uv-icon>
  55. </view>
  56. <view class="guide-list">
  57. <view class="guide-step" v-for="(step, index) in guideSteps" :key="index">
  58. <view class="step-number">{{ index + 1 }}</view>
  59. <text class="step-text">{{ step }}</text>
  60. </view>
  61. </view>
  62. </view>
  63. <!-- 余额充值卡片 -->
  64. <view class="balance-card" v-if="state.isLogin" @click="handleGotoRechage">
  65. <view class="balance-left">
  66. <view class="balance-icon">
  67. <uv-icon name="bag" size="22" color="#C6171E"></uv-icon>
  68. </view>
  69. <view class="balance-info">
  70. <text class="balance-label">账户余额</text>
  71. <view class="balance-amount">
  72. <text class="amount-symbol">¥</text>
  73. <text class="amount-number">{{ fmtMoney(state.balance) }}</text>
  74. </view>
  75. </view>
  76. </view>
  77. <view class="balance-right">
  78. <text class="recharge-text">去充值</text>
  79. <uv-icon name="arrow-right" size="16" color="#C6171E"></uv-icon>
  80. </view>
  81. </view>
  82. <!-- 底部占位 -->
  83. <view style="height: 40rpx;"></view>
  84. </scroll-view>
  85. <!-- 登录条 -->
  86. <login-bar class="w100 text-center"></login-bar>
  87. </view>
  88. </template>
  89. <script setup lang="ts">
  90. import {onHide, onLoad, onShow} from "@dcloudio/uni-app";
  91. import {reactive, ref} from "vue";
  92. import {debounce, fmtDictName} from "@/utils/common";
  93. import {get, post} from "@/utils/https";
  94. import {checkLogin, fetchToken, tryLogin} from "@/utils/auth";
  95. import {fmtMoney} from "@/utils/common";
  96. import LoginBar from "@/components/login-bar/index.vue";
  97. const guideSteps = [
  98. '点击上方【启动设备】按钮启动设备',
  99. '设备启动后,在设备功能面板按下功能按键选择服务项目',
  100. '洗车过程中可按功能按键暂停,暂停期间停止计费',
  101. '洗车结束后,按结算按键或【停止设备】按钮结束计费',
  102. '请及时将车辆驶离工位,方便后续用户使用'
  103. ]
  104. const initState = () => ({
  105. isLogin:false,
  106. balance:0,
  107. device: {
  108. functions: [],
  109. deviceName: '',
  110. state: '',
  111. stationId: ''
  112. },
  113. time: "00:00:00",
  114. start: new Date(),
  115. deviceId: null,
  116. stationId: null
  117. })
  118. const state = reactive(initState())
  119. onHide(() => {
  120. Object.assign(state, initState());
  121. })
  122. onLoad((options: any) => {
  123. // uni.showModal({
  124. // title:'onLoad,'+options?.shortId
  125. // })
  126. // onLoad
  127. let id = options?.shortId;
  128. state.stationId = options?.stationId;
  129. if (!id) {
  130. let query = decodeURIComponent(options.q);
  131. let scanTime = options.scancode_time;
  132. if (query) {
  133. id = query.split("#")[1].split("?")[0]
  134. state.deviceId = id;
  135. } else {
  136. return;
  137. }
  138. }
  139. getApp<any>().globalData.deviceId = id;
  140. state.deviceId = id;
  141. state.device = getApp<any>().globalData.last.device;
  142. checkLogin().then((token) => {
  143. state.isLogin =true;
  144. setTimeout(() => {
  145. loadDeviceDetail(id);
  146. state.balance = getApp<any>().globalData.user.balance
  147. }, 200)
  148. }).catch(e => {
  149. console.error("onLoad 校验登录失败,自动跳转登录页")
  150. // uni.navigateTo({
  151. // url: `/pages-user/login/index?shortId=${state.deviceId}&redirectUrl=/pages-wash/device/index`
  152. // })
  153. })
  154. });
  155. onShow((options:any) => {
  156. addListener();
  157. // uni.showToast({
  158. // title:'onShow,'
  159. // })
  160. checkLogin().then(() => {
  161. // uni.showToast({
  162. // title:'onShow,loaded'
  163. // })
  164. if (!state.deviceId) {
  165. let deviceId = getApp<any>().globalData.deviceId;
  166. if (deviceId) {
  167. loadDeviceDetail(deviceId);
  168. }
  169. } else {
  170. loadDeviceDetail(state.deviceId);
  171. }
  172. state.isLogin =true;
  173. state.balance = getApp<any>().globalData.user.balance
  174. }).catch(e => {
  175. console.error("校验登录失败,自动跳转登录页")
  176. setTimeout(()=>{
  177. uni.navigateTo({
  178. url: `/pages-user/login/index?shortId=${!!state.deviceId?state.deviceId:''}&stationId=${!!state.stationId?state.stationId:''}&redirectUrl=/pages-wash/device/index`
  179. })
  180. },1000)
  181. })
  182. })
  183. const addListener = () => {
  184. uni.$on('login', function (data) {
  185. state.isLogin =true;
  186. if (state.deviceId && data.isLogin) {
  187. loadDeviceDetail(state.deviceId);
  188. state.balance = getApp<any>().globalData.user.balance
  189. }
  190. })
  191. uni.$on('logout', function (data) {
  192. })
  193. }
  194. const removeListener = () => {
  195. uni.$off('logout');
  196. uni.$off('login');
  197. }
  198. const loadDeviceDetail = (id: any) => {
  199. state.deviceId = id;
  200. let ft = fetchToken();
  201. get(`/wash-device/queryDevice/${id}`).then((res: any) => {
  202. if (res.currentUserId && res.currentUserId != getApp<any>().globalData.user.id) {
  203. uni.showToast({
  204. title: '设备已被占用',
  205. icon: 'error'
  206. })
  207. setTimeout(() => {
  208. uni.switchTab({
  209. url: '/pages/index/index'
  210. })
  211. }, 2000)
  212. }
  213. res.functionList = res.functions?.split("|") || []
  214. state.device = res;
  215. getApp<any>().globalData.deviceId = id;
  216. }).catch(e => {
  217. console.error(e)
  218. })
  219. // countTime();
  220. }
  221. const handleNavigateBack = () => {
  222. uni.navigateBack();
  223. }
  224. const debounceStartStopDevice = debounce(() => {
  225. handleClickDevice();
  226. }, 600)
  227. const handleClickDevice = () => {
  228. if(!state.isLogin){
  229. return;
  230. }
  231. uni.showModal({
  232. title: '提示',
  233. content: state.device?.state === 'idle' ? '确定启动设备开始洗车吗?' : '确定停止设备终止本次服务吗?',
  234. success: (res) => {
  235. if (res.confirm) {
  236. getApp<any>().globalData.refresh =true;
  237. if (state.device?.state === 'idle') {
  238. uni.showLoading({
  239. title: "启动中",
  240. mask: true,
  241. });
  242. post(`/wash-device/startDevice/${state.device?.shortId}`).then((res: any) => {
  243. uni.hideLoading();
  244. uni.showToast({
  245. title: '设备启动成功'
  246. })
  247. state.device.state = 'busy'
  248. })
  249. } else {
  250. uni.showLoading({
  251. title: "停止中",
  252. mask: true,
  253. });
  254. post(`/wash-device/stopDevice/${state.device?.shortId}`).then((res: any) => {
  255. uni.hideLoading();
  256. uni.showToast({
  257. title: '设备停机成功'
  258. })
  259. state.device.state = 'idle'
  260. })
  261. }
  262. }
  263. }
  264. });
  265. }
  266. const countTime = () => {
  267. setInterval(() => {
  268. let delta = new Date().getTime() - state.start.getTime();
  269. delta = delta / 1000;
  270. let hour = (delta / 3600).toFixed(0);
  271. let min = ((delta % 3600) / 60).toFixed(0);
  272. let second = ((delta % 3600) % 60).toFixed(0);
  273. state.time = [
  274. Number(hour) > 9 ? hour : `0${hour}`,
  275. Number(min) > 9 ? min : `0${min}`,
  276. Number(second) > 9 ? second : `0${second}`
  277. ].join(":")
  278. }, 1000)
  279. }
  280. const handleGotoRechage = () => {
  281. uni.navigateTo({
  282. url: `/pages-user/wallet/recharge?stationId=${state.device.stationId}`
  283. })
  284. }
  285. </script>
  286. <style lang="scss" scoped>
  287. .page-container {
  288. width: 100vw;
  289. height: 100vh;
  290. background: linear-gradient(180deg, #FFE8E8 0%, #FFF5F5 15%, $uni-bg-color-page 30%);
  291. display: flex;
  292. flex-direction: column;
  293. }
  294. .content-scroll {
  295. flex: 1;
  296. height: 100%;
  297. width: 100%;
  298. }
  299. // 设备信息卡片
  300. .device-info-card {
  301. margin: 24rpx 30rpx;
  302. background: white;
  303. border-radius: 24rpx;
  304. padding: 32rpx;
  305. box-shadow: 0 4rpx 20rpx rgba(0, 0, 0, 0.06);
  306. text-align: center;
  307. .device-number {
  308. display: flex;
  309. align-items: center;
  310. justify-content: center;
  311. gap: 8rpx;
  312. margin-bottom: 20rpx;
  313. .number-text {
  314. font-size: 32rpx;
  315. font-weight: 600;
  316. color: #303133;
  317. }
  318. }
  319. .device-status {
  320. display: inline-flex;
  321. align-items: center;
  322. gap: 8rpx;
  323. padding: 8rpx 20rpx;
  324. border-radius: 20rpx;
  325. font-size: 24rpx;
  326. font-weight: 500;
  327. margin-bottom: 24rpx;
  328. .status-dot {
  329. width: 12rpx;
  330. height: 12rpx;
  331. border-radius: 50%;
  332. animation: pulse 2s infinite;
  333. }
  334. &.status-idle {
  335. background: #E8F8F0;
  336. color: #07C160;
  337. .status-dot {
  338. background: #07C160;
  339. }
  340. }
  341. &.status-busy {
  342. background: #FFF7E6;
  343. color: #FAAD14;
  344. .status-dot {
  345. background: #FAAD14;
  346. }
  347. }
  348. &.status-fault {
  349. background: #FEF0F0;
  350. color: #F56C6C;
  351. .status-dot {
  352. background: #F56C6C;
  353. }
  354. }
  355. }
  356. .device-functions {
  357. display: flex;
  358. flex-wrap: wrap;
  359. justify-content: center;
  360. gap: 12rpx;
  361. .function-item {
  362. display: flex;
  363. align-items: center;
  364. gap: 6rpx;
  365. padding: 6rpx 16rpx;
  366. background: linear-gradient(135deg, rgba(198, 23, 30, 0.08), rgba(232, 69, 69, 0.05));
  367. color: #C6171E;
  368. border-radius: 16rpx;
  369. font-size: 22rpx;
  370. font-weight: 500;
  371. }
  372. }
  373. }
  374. @keyframes pulse {
  375. 0%, 100% {
  376. opacity: 1;
  377. }
  378. 50% {
  379. opacity: 0.5;
  380. }
  381. }
  382. // 控制按钮卡片
  383. .control-card {
  384. margin: 0 30rpx 24rpx;
  385. background: white;
  386. border-radius: 24rpx;
  387. padding: 60rpx 32rpx;
  388. box-shadow: 0 4rpx 20rpx rgba(0, 0, 0, 0.06);
  389. .control-wrapper {
  390. display: flex;
  391. justify-content: center;
  392. align-items: center;
  393. .control-button {
  394. width: 240rpx;
  395. height: 240rpx;
  396. border-radius: 50%;
  397. background: linear-gradient(135deg, #C6171E 0%, #E84545 100%);
  398. display: flex;
  399. flex-direction: column;
  400. justify-content: center;
  401. align-items: center;
  402. gap: 8rpx;
  403. box-shadow: 0 12rpx 32rpx rgba(198, 23, 30, 0.3);
  404. transition: all 0.15s ease;
  405. position: relative;
  406. overflow: hidden;
  407. &::before {
  408. content: '';
  409. position: absolute;
  410. top: 0;
  411. left: 0;
  412. right: 0;
  413. bottom: 0;
  414. background: rgba(255, 255, 255, 0.1);
  415. border-radius: 50%;
  416. transform: scale(0);
  417. transition: transform 0.3s ease;
  418. }
  419. &:active {
  420. transform: scale(0.95);
  421. box-shadow: 0 6rpx 20rpx rgba(198, 23, 30, 0.3);
  422. &::before {
  423. transform: scale(1);
  424. }
  425. }
  426. .button-icon {
  427. margin-bottom: 4rpx;
  428. display: flex;
  429. align-items: center;
  430. justify-content: center;
  431. .icon-play,
  432. .icon-stop {
  433. display: flex;
  434. align-items: center;
  435. justify-content: center;
  436. line-height: 1;
  437. }
  438. }
  439. .button-text {
  440. font-size: 32rpx;
  441. font-weight: 600;
  442. color: white;
  443. }
  444. .button-tip {
  445. font-size: 20rpx;
  446. color: rgba(255, 255, 255, 0.85);
  447. }
  448. &.control-button--active {
  449. background: linear-gradient(135deg, #E84545 0%, #FF6B6B 100%);
  450. box-shadow: 0 12rpx 32rpx rgba(232, 69, 69, 0.3);
  451. &:active {
  452. box-shadow: 0 6rpx 20rpx rgba(232, 69, 69, 0.3);
  453. }
  454. }
  455. }
  456. }
  457. }
  458. // 操作指南卡片
  459. .guide-card {
  460. margin: 0 30rpx 24rpx;
  461. background: white;
  462. border-radius: 24rpx;
  463. box-shadow: 0 4rpx 20rpx rgba(0, 0, 0, 0.06);
  464. overflow: hidden;
  465. .card-header {
  466. display: flex;
  467. align-items: center;
  468. gap: 12rpx;
  469. padding: 28rpx;
  470. border-bottom: 1rpx solid $uni-border-color-light;
  471. .header-line {
  472. width: 10rpx;
  473. height: 10rpx;
  474. background: $uni-color-primary;
  475. border-radius: 50%;
  476. }
  477. .header-title {
  478. font-size: 30rpx;
  479. font-weight: 600;
  480. color: #303133;
  481. flex: 1;
  482. }
  483. }
  484. .guide-list {
  485. padding: 24rpx 28rpx;
  486. .guide-step {
  487. display: flex;
  488. align-items: flex-start;
  489. gap: 16rpx;
  490. margin-bottom: 20rpx;
  491. &:last-child {
  492. margin-bottom: 0;
  493. }
  494. .step-number {
  495. width: 40rpx;
  496. height: 40rpx;
  497. border-radius: 50%;
  498. background: linear-gradient(135deg, #C6171E, #E84545);
  499. color: white;
  500. font-size: 22rpx;
  501. font-weight: 600;
  502. display: flex;
  503. align-items: center;
  504. justify-content: center;
  505. flex-shrink: 0;
  506. margin-top: 4rpx;
  507. }
  508. .step-text {
  509. flex: 1;
  510. font-size: 26rpx;
  511. color: #606266;
  512. line-height: 1.6;
  513. padding-top: 8rpx;
  514. }
  515. }
  516. }
  517. }
  518. // 余额充值卡片
  519. .balance-card {
  520. margin: 0 30rpx 24rpx;
  521. background: white;
  522. border-radius: 24rpx;
  523. padding: 28rpx 32rpx;
  524. box-shadow: 0 4rpx 20rpx rgba(0, 0, 0, 0.06);
  525. display: flex;
  526. justify-content: space-between;
  527. align-items: center;
  528. transition: all 0.15s ease;
  529. &:active {
  530. transform: scale(0.98);
  531. box-shadow: 0 2rpx 12rpx rgba(0, 0, 0, 0.08);
  532. }
  533. .balance-left {
  534. display: flex;
  535. align-items: center;
  536. gap: 16rpx;
  537. flex: 1;
  538. .balance-icon {
  539. width: 56rpx;
  540. height: 56rpx;
  541. border-radius: 50%;
  542. background: linear-gradient(135deg, rgba(198, 23, 30, 0.1), rgba(232, 69, 69, 0.05));
  543. display: flex;
  544. align-items: center;
  545. justify-content: center;
  546. }
  547. .balance-info {
  548. display: flex;
  549. flex-direction: column;
  550. gap: 6rpx;
  551. .balance-label {
  552. font-size: 24rpx;
  553. color: #909399;
  554. }
  555. .balance-amount {
  556. display: flex;
  557. align-items: baseline;
  558. gap: 4rpx;
  559. .amount-symbol {
  560. font-size: 24rpx;
  561. color: #C6171E;
  562. font-weight: 500;
  563. }
  564. .amount-number {
  565. font-size: 32rpx;
  566. color: #C6171E;
  567. font-weight: 600;
  568. }
  569. }
  570. }
  571. }
  572. .balance-right {
  573. display: flex;
  574. align-items: center;
  575. gap: 8rpx;
  576. .recharge-text {
  577. font-size: 26rpx;
  578. color: #C6171E;
  579. font-weight: 500;
  580. }
  581. }
  582. }
  583. </style>