index.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560
  1. <template>
  2. <view class="work-pages">
  3. <!-- 工作控制按钮及进度 -->
  4. <view class="work-cons flex-center">
  5. <!-- 操作按钮组件 -->
  6. <view class="work-button-wrap">
  7. <!-- 按钮 -->
  8. <view class="work-button flex-center">
  9. <!-- 扇形进度条 -->
  10. <view class="circle_process">
  11. <view class="wrapper right"><view class="circle rightcircle" :style="{ transform: `rotate(${rdeg}deg)` }"></view></view>
  12. <view class="wrapper left"><view class="circle leftcircle" :style="{ transform: `rotate(${ldeg}deg)` }"></view></view>
  13. </view>
  14. <view class="cirle-one"></view>
  15. <!-- 指针 -->
  16. <view class="cirle-two flex-center" v-for="item in 60" :key="item">
  17. <view class="sector" :style="{ transform: `rotate(${item * 6}deg)` }"></view>
  18. </view>
  19. <view class="cirle-three flex-center"></view>
  20. <view class="cirle-free" :class="status == 'working' ? 'w-stop' : 'w-start'"></view>
  21. <view class="cirle-free-1" :class="status == 'working' ? 'w-stop' : 'w-start'"></view>
  22. <view class="cirle-free-2" :class="status == 'working' ? 'w-stop' : 'w-start'"></view>
  23. <view class="cirle-sex flex-center" @tap="startWork">
  24. {{ status == 'working' ? '紧急停止' : '点击启动' }}
  25. </view>
  26. </view>
  27. <!-- 状态提示 -->
  28. <view class="work-button-tips">
  29. {{curWorkStutesText}}
  30. </view>
  31. </view>
  32. </view>
  33. <!-- 说明提示 -->
  34. <view class="work-tips">
  35. <view>
  36. <view class="work-dtime" v-if="status=='start'">
  37. 距离订单强制完成还剩
  38. <u-count-down
  39. v-if="timestamp>0"
  40. @end="endDtime"
  41. separator="zh"
  42. font-size="36"
  43. separator-size="28"
  44. color="#ff0000"
  45. :timestamp="timestamp"
  46. :show-days="false"
  47. :show-hours="false"
  48. ></u-count-down>
  49. </view>
  50. <view class="work-remarks">
  51. <view class="title">说明:</view>
  52. <view v-if="status=='start'">
  53. 支付完成后
  54. <text class="red">请尽快启动洗车服务</text>
  55. ,否则订单将在5分钟后自动完成。
  56. </view>
  57. <view v-else>
  58. <view>设备启动中请注意安全,如果设备工作中出现故障,请按紧急停止按钮或联系客服。</view>
  59. <view @click="callPhone">如有疑问,请联系客服:<text>400-xxx-xxx</text> </view>
  60. </view>
  61. </view>
  62. </view>
  63. </view>
  64. <!-- 正在启动,归位弹框提示 -->
  65. <u-popup v-model="showStart" :mask-close-able="false" border-radius="10" mode="center" width="500rpx" height="400rpx">
  66. <view style="padding: 30rpx;display: flex;justify-content: center;text-align: center;">
  67. <!-- 启动中 -->
  68. <view v-if="status == 'start'">
  69. <u-image width="216px" height="120px" src="/static/img/start.png"></u-image>
  70. <view style="padding: 15rpx;">洗车机正在启动...</view>
  71. </view>
  72. <!-- 停止中 -->
  73. <view v-if="status == 'stop'">
  74. <u-image width="216px" height="120px" src="/static/img/start.png"></u-image>
  75. <view style="padding: 15rpx;">洗车机正在停止中...</view>
  76. </view>
  77. <!-- 归位中 -->
  78. <view v-if="status == 'reseting'">
  79. <u-image width="216px" height="120px" src="/static/img/reset.png"></u-image>
  80. <view style="padding: 15rpx;">洗车机正在归位中...</view>
  81. </view>
  82. </view>
  83. </u-popup>
  84. <!-- 急停提示弹框 -->
  85. <u-popup v-model="showStop" :mask-close-able="false" border-radius="10" mode="center" width="80%">
  86. <view style="padding: 30rpx;text-align: center;">
  87. <view>
  88. <view style="font-weight: bold;">设备提示</view>
  89. <view style="display: flex;justify-content: center;padding: 10rpx 0;">
  90. <u-image width="165px" height="138px" src="/static/img/sbts.png"></u-image>
  91. </view>
  92. <u-divider>可能原因</u-divider>
  93. <view style="padding: 15rpx;text-align: left;">
  94. <view>1、洗车机紧急停止,本次服务结束</view>
  95. <view>2、因设备故障无法继续为您服务,所支付金额将退至您的支付账户</view>
  96. <view>3、如需再次服务,请退出车辆重新进入,再扫码支付洗车</view>
  97. <view>4、如需帮助请联系客服</view>
  98. </view>
  99. <view style="display: flex;padding: 20rpx 0;justify-content: center;">
  100. <u-button @click="callPhone" style="width: 45%;border-radius: 0;margin-right: 5%;">联系客服</u-button>
  101. <u-button @click="resetRabt" style="width: 45%;" type="error">洗车机归位</u-button>
  102. </view>
  103. </view>
  104. </view>
  105. </u-popup>
  106. </view>
  107. </template>
  108. <script>
  109. export default {
  110. data() {
  111. return {
  112. timestamp: 0, // 初始情况下5分钟后自动结束
  113. rdeg: -135, // 进度条初始角度
  114. ldeg: -135, /// 进度条初始角度
  115. step: 0, // 进度条增值,共60步
  116. interId: null, // 进度时间id
  117. status: 'start', // 状态,start 开始启动,working 正在工作,stop急停,reseting 归位中, success 洗车成功
  118. curWorkStutesText: '设备准备就绪', // 当前机器运行的进度提示
  119. showStart: false ,// 启动弹框提示
  120. showStop: false, // 急停提示
  121. washCarType: '', // 洗车服务类型,不同的类型对应的时间不一样
  122. washDuration: 0, // 机器运行时间
  123. orderNo: '',// 订单编号
  124. };
  125. },
  126. onShow() {
  127. console.log("onShow")
  128. // 计算当前倒计时
  129. let od = this.$store.state.orderDjs
  130. if(od!=0){
  131. let d = new Date().getTime() - od
  132. this.timestamp = 300 - d/1000
  133. }
  134. // 计算当前进度条步数
  135. let ld = this.$store.state.loadingDjs
  136. let serverTime = this.washDuration / 60 * 1000
  137. if(ld!=0){
  138. let lod = new Date().getTime() - ld
  139. this.step = this.step + Math.floor(lod/serverTime)
  140. }
  141. },
  142. onLoad(options) {
  143. console.log("onLoad")
  144. // 创建websocket
  145. this.$store.commit('$webSocket')
  146. uni.showLoading({
  147. title: '正在连接...',
  148. mask: true
  149. })
  150. // 获取用户及订单信息
  151. let orderInfo = this.$store.state.vuex_orderInfo
  152. this.washCarType = orderInfo.itemCode
  153. this.orderNo = orderInfo.orderNo
  154. this.washDuration = orderInfo.duration
  155. // 记录当前的时间
  156. this.$store.state.orderDjs = new Date().getTime()
  157. // 监听消息
  158. uni.$on('wsMessage',(e)=>{
  159. if(typeof e == 'string'){
  160. // 连接成功
  161. if(e=='connected'){
  162. console.log('connected')
  163. uni.hideLoading()
  164. }
  165. }
  166. console.log(typeof e)
  167. if(typeof e == 'object' && e.type == 'xcz'){
  168. console.log(e.data.level,e.data.msgCode,e.data.msgCodeInfo)
  169. console.log("--------------------------------------------")
  170. // 启动超时
  171. if(e.data.level == 'O'){
  172. if(e.data.msgCode == "PAUSE"){
  173. this.startWashCarFail()
  174. }
  175. }
  176. // 进度消息
  177. if(e.data.level == 'C'&&this.status!="reseting"){
  178. // 启动成功
  179. this.startWashCarSuccess()
  180. this.curWorkStutesText= e.data.msgCodeInfo
  181. // 洗车完成
  182. if(e.data.msgCode=="XCWC"){
  183. this.washCarSuccess()
  184. }
  185. }
  186. // 错误消息
  187. if(e.data.level == 'F'&&this.status!="reseting"){
  188. // 启动成功
  189. this.startWashCarSuccess()
  190. this.curWorkStutesText= e.data.msgCodeInfo
  191. // 显示复位提示弹框
  192. this.showStop = true;
  193. this.status = 'stop';
  194. this.stopWashCarSuccess();
  195. }
  196. // 急停
  197. if(e.data.level == 'A'){
  198. if(e.data.msgCode=="JJTZ"||e.data.msgCode=="XCX_JJTZ"){
  199. this.curWorkStutesText= e.data.msgCodeInfo
  200. // 显示复位提示弹框
  201. this.showStop = true;
  202. this.stopWashCarSuccess();
  203. }else{
  204. this.devError()
  205. }
  206. }
  207. // 复位状态
  208. if(e.data.level == 'D'){
  209. // 开始复位
  210. if(e.data.msgCode=="FW_START"){
  211. this.status = 'reseting';
  212. this.showStart = true;
  213. this.showStop = false;
  214. }
  215. // 复位成功
  216. if(e.data.msgCode=="FW_SUCC"){
  217. this.resetRabtSuccess()
  218. }
  219. // 设备离线,设备暂停营业或复位失败
  220. if(e.data.msgCode=="PAUSE" || e.data.msgCode == "FW_FAIL"){
  221. this.devError()
  222. }
  223. }
  224. }
  225. })
  226. },
  227. onUnload() {
  228. // 开始复位时关闭当前页面
  229. if(this.status = 'reseting'){
  230. // 关闭socket
  231. this.$store.commit("$closeWebsocket");
  232. }
  233. },
  234. methods: {
  235. // 电话客服
  236. callPhone () {
  237. uni.makePhoneCall({
  238. phoneNumber: '15202957025'
  239. })
  240. },
  241. // 倒计时结束时,自动完成洗车订单
  242. endDtime() {
  243. this.washCarSuccess()
  244. },
  245. // 操作按钮
  246. startWork() {
  247. let _this = this
  248. let cmd = {
  249. orderNo: this.orderNo, // 订单编号
  250. washType: this.washCarType,// 洗车模式
  251. }
  252. // 启动
  253. if (this.status == 'start') {
  254. cmd.operateType = 'start' //操作命令
  255. this.$store.commit("$sendWebsocket",JSON.stringify(cmd))
  256. this.showStart = true
  257. this.$store.state.vuex_workStatus = 'start'
  258. }
  259. // 急停
  260. if (this.status == 'working') {
  261. uni.showModal({
  262. title: '提示',
  263. content: '确定紧急停止洗车机?',
  264. success: function (res) {
  265. if (res.confirm) {
  266. cmd.operateType = 'stop' //操作命令
  267. _this.$store.commit("$sendWebsocket",JSON.stringify(cmd))
  268. _this.status = 'stop'
  269. }
  270. }
  271. });
  272. }
  273. },
  274. // 启动超时
  275. startWashCarFail(){
  276. this.showStart = false;
  277. uni.showModal({
  278. title: '提示',
  279. content: '设备启动超时,请重新点击启动',
  280. showCancel: false,
  281. });
  282. },
  283. // 启动成功
  284. startWashCarSuccess(){
  285. // 进度条,服务时间根据不同的服务类型而不同
  286. if(!this.interId){
  287. this.status = 'working';
  288. this.$store.state.vuex_workStatus = 'working'
  289. this.curWorkStutesText='设备已启动';
  290. this.showStart = false;
  291. this.step = 0;
  292. let serverTime = this.washDuration / 60; // 转换成分钟
  293. // 记录当前的开始时间
  294. this.$store.state.loadingDjs = new Date().getTime()
  295. this.interId = setInterval(()=>{
  296. // 小于60时说明洗车机正在工作中
  297. if(this.step<=60){
  298. this.loading(this.step++)
  299. }else{
  300. // 洗车机正常状态下工作结束
  301. // this.washCarSuccess()
  302. this.step = 0
  303. }
  304. },1000*serverTime)
  305. }
  306. },
  307. // 设备停止成功
  308. stopWashCarSuccess(){
  309. this.$store.state.vuex_workStatus = 'stop'
  310. this.curWorkStutesText='设备已停止';
  311. this.resetLoadingStatus();
  312. },
  313. // 设备异常
  314. devError(){
  315. this.stopWashCarSuccess();
  316. // 关闭socket
  317. this.$store.commit("$closeWebsocket");
  318. uni.showModal({
  319. title: '提示',
  320. content: '设备异常,请联系客服',
  321. showCancel: false,
  322. success: function (res) {
  323. if (res.confirm) {
  324. uni.navigateBack()
  325. }
  326. }
  327. });
  328. },
  329. // 洗车完成
  330. washCarSuccess(){
  331. this.status = "success";
  332. this.$store.state.vuex_workStatus = 'stop'
  333. this.curWorkStutesText='洗车已结束';
  334. this.resetLoadingStatus();
  335. uni.showModal({
  336. title: '提示',
  337. content: '洗车已结束',
  338. showCancel: false,
  339. success: function (res) {
  340. if (res.confirm) {
  341. uni.navigateBack()
  342. }
  343. }
  344. });
  345. console.log('washCarSuccess')
  346. // 关闭socket
  347. this.$store.commit("$closeWebsocket")
  348. },
  349. // 重置到进度条初始状态
  350. resetLoadingStatus(){
  351. // 停止进度
  352. this.rdeg= -135;
  353. this.ldeg= -135;
  354. clearInterval(this.interId);
  355. this.interId = null;
  356. },
  357. // 洗车机进度条动画
  358. loading(second) {
  359. if (second <= 30) {
  360. this.rdeg = -135 + 6 * second;
  361. this.ldeg = -135;
  362. } else {
  363. this.rdeg = 45;
  364. this.ldeg = -135 + 6 * (second - 30);
  365. }
  366. },
  367. // 归位机器
  368. resetRabt(){
  369. // 归位命令
  370. let cmd = {
  371. orderNo: this.orderNo, // 订单编号
  372. operateType: 'reset', //操作命令
  373. washType: this.washCarType,// 洗车模式
  374. }
  375. this.$store.commit("$sendWebsocket",JSON.stringify(cmd))
  376. },
  377. // 归位结束后
  378. resetRabtSuccess(){
  379. this.curWorkStutesText='设备已归位';
  380. this.status = 'reseting';
  381. this.$store.state.vuex_workStatus = 'stop';
  382. // 关闭socket
  383. this.$store.commit("$closeWebsocket");
  384. uni.redirectTo({
  385. url:"/pages/work/success/success"
  386. })
  387. }
  388. }
  389. };
  390. </script>
  391. <style lang="scss">
  392. // 扇形圆环
  393. .circle_process {
  394. position: absolute;
  395. width: 390rpx;
  396. height: 390rpx;
  397. }
  398. .circle_process .wrapper {
  399. width: 195rpx;
  400. height: 390rpx;
  401. position: absolute;
  402. top: 0;
  403. overflow: hidden;
  404. }
  405. .circle_process .right {
  406. right: 0;
  407. }
  408. .circle_process .left {
  409. left: 0;
  410. }
  411. .circle_process .circle {
  412. width: 390rpx;
  413. height: 390rpx;
  414. border: 20rpx solid transparent;
  415. border-radius: 50%;
  416. position: absolute;
  417. top: 0;
  418. transform: rotate(-135deg);
  419. }
  420. .circle_process .rightcircle {
  421. border-top: 20rpx solid #4CD964;
  422. border-right: 20rpx solid #4CD964;
  423. right: 1px;
  424. }
  425. .circle_process .leftcircle {
  426. border-bottom: 20rpx solid #4CD964;
  427. border-left: 20rpx solid #4CD964;
  428. left: 1px;
  429. }
  430. // 动画
  431. @keyframes mymove {
  432. 0% {
  433. transform: scale(1); /*开始为原始大小*/
  434. opacity: 1;
  435. }
  436. 50% {
  437. transform: scale(1.2); /*放大1.1倍*/
  438. opacity: 0;
  439. }
  440. }
  441. .work-pages {
  442. width: 100%;
  443. .flex-center {
  444. display: flex;
  445. align-items: center;
  446. justify-content: center;
  447. }
  448. .work-cons {
  449. height: 50vh;
  450. background-image: linear-gradient(0deg, #666, #333);
  451. border-bottom-left-radius: 500rpx 50rpx;
  452. border-bottom-right-radius: 500rpx 50rpx;
  453. position: relative;
  454. // 按钮
  455. .work-button-wrap {
  456. width: 400rpx;
  457. margin-top: -50rpx;
  458. .work-button {
  459. background: #666;
  460. border-radius: 100%;
  461. width: 390rpx;
  462. height: 390rpx;
  463. box-shadow:inset 0rpx 2rpx 10rpx #000;
  464. .cirle-one {
  465. background-image: linear-gradient(180deg, #666, #333 30%);
  466. width: 370rpx;
  467. height: 370rpx;
  468. border-radius: 100%;
  469. position: absolute;
  470. box-shadow: 0rpx 2rpx 10rpx #333;
  471. }
  472. .cirle-two {
  473. width: 370rpx;
  474. height: 370rpx;
  475. border-radius: 100%;
  476. position: absolute;
  477. .sector {
  478. transform-origin: center center;
  479. width: 350rpx;
  480. height: 5rpx;
  481. background: #777;
  482. }
  483. }
  484. .cirle-three {
  485. background: #444;
  486. width: 280rpx;
  487. height: 280rpx;
  488. border-radius: 100%;
  489. position: absolute;
  490. box-shadow: inset 0rpx 3rpx 10rpx #000;
  491. }
  492. .cirle-free, .cirle-free-1, .cirle-free-2 {
  493. width: 230rpx;
  494. height: 230rpx;
  495. border-radius: 100%;
  496. position: absolute;
  497. animation: mymove 5s infinite;
  498. }
  499. .cirle-free-1{
  500. width: 210rpx;
  501. height: 210rpx;
  502. animation: mymove 4.5s infinite;
  503. }
  504. .cirle-free-2{
  505. width: 190rpx;
  506. height: 190rpx;
  507. animation: mymove 4s infinite;
  508. }
  509. .cirle-sex {
  510. background-image: linear-gradient(180deg, #888, #333 50%);
  511. box-shadow: 0rpx 5rpx 10rpx #333;
  512. width: 210rpx;
  513. height: 210rpx;
  514. border-radius: 100%;
  515. position: absolute;
  516. color: #ffffff;
  517. font-size: 28rpx;
  518. color: #eee;
  519. &:active {
  520. background-image: linear-gradient(-180deg, #666, #333 80%);
  521. }
  522. }
  523. .w-start {
  524. background: #ffc800;
  525. }
  526. .w-stop {
  527. background: #ff0000;
  528. }
  529. }
  530. .work-button-tips {
  531. color: #eee;
  532. text-align: center;
  533. padding-top: 30rpx;
  534. }
  535. }
  536. }
  537. .work-tips {
  538. padding: 45rpx;
  539. .work-dtime {
  540. text-align: center;
  541. font-weight: bold;
  542. font-size: 34rpx;
  543. }
  544. .work-remarks {
  545. padding-top: 50rpx;
  546. .red {
  547. color: red;
  548. }
  549. .title {
  550. font-weight: bold;
  551. }
  552. }
  553. }
  554. }
  555. </style>