index.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577
  1. <template>
  2. <view class="work-pages">
  3. <!-- 工作控制按钮及进度 -->
  4. <view class="work-cons flex-center" style="flex-direction: column;">
  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. </view>
  28. <!-- 状态提示 -->
  29. <view class="work-button-tips">
  30. <u-notice-bar type="error" border-radius="50" color="#fff" bg-color="#666" mode="vertical" :list="[curWorkStutesText,curWorkStutesText]"></u-notice-bar>
  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 == 'starting'">
  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 == 'stoping'">
  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="sendCmdRabt('reset')" 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: 'linking', // 状态,linking 连接中,start 开始启动, starting 启动中,working 正在工作,stoping 停止中, reset 归位,reseting 归位中, end 洗车完成
  118. curWorkStutesText: '设备准备就绪', // 当前机器运行的进度提示
  119. showStart: false ,// 启动弹框提示
  120. showStop: false, // 急停提示
  121. washCarType: '', // 洗车服务类型,不同的类型对应的时间不一样
  122. washDuration: 7.5, // 机器运行步骤,共8步,等分60
  123. orderNo: '',// 订单编号
  124. };
  125. },
  126. onShow() {
  127. console.log("onShow")
  128. // 计算当前倒计时
  129. let od = this.$store.state.vuex_orderDjs
  130. if(od!=0){
  131. let d = new Date().getTime() - od
  132. this.timestamp = 300 - d/1000
  133. }
  134. // 更新进度条
  135. if(this.$store.state.vuex_workStatus == 'working'){
  136. this.step = this.$store.state.vuex_workStep
  137. this.loading()
  138. }
  139. },
  140. onLoad(options) {
  141. console.log("onLoad")
  142. // 创建websocket
  143. this.$store.commit('$webSocket')
  144. uni.showLoading({
  145. title: '正在连接...',
  146. mask: true
  147. })
  148. // 第一次进入洗车页面
  149. if(this.$store.state.vuex_workStatus == 'linking'){
  150. // 记录当前的时间
  151. this.$store.state.vuex_orderDjs = new Date().getTime()
  152. }
  153. // 获取用户及订单信息
  154. let orderInfo = this.$store.state.vuex_orderInfo
  155. this.washCarType = orderInfo.itemCode
  156. this.orderNo = orderInfo.orderNo
  157. // 监听消息
  158. uni.$on('wsMessage', this.watchMessage)
  159. },
  160. onUnload() {
  161. // 关闭socket
  162. this.$store.commit("$closeWebsocket")
  163. },
  164. onUnload() {
  165. uni.$off('wsMessage', this.watchMessage)
  166. },
  167. methods: {
  168. // 电话客服
  169. callPhone () {
  170. uni.makePhoneCall({
  171. phoneNumber: '15202957025'
  172. })
  173. },
  174. // 倒计时结束时,自动完成洗车订单
  175. endDtime() {
  176. if(this.status == 'start'){
  177. this.washCarSuccess()
  178. }
  179. },
  180. // 监听socket消息
  181. watchMessage(e){
  182. if(typeof e == 'string'){
  183. // 连接成功
  184. if(e=='connected'){
  185. console.log('connected')
  186. uni.hideLoading()
  187. this.status = 'start'
  188. this.$store.state.vuex_workStatus = 'start'
  189. }
  190. }
  191. if(typeof e == 'object' && e.type == 'xcz'){
  192. console.log(e.data.level,e.data.msgCodeInfo,e.data.msgCodeSrc)
  193. // 启动超时
  194. if(e.data.level == 'O'){
  195. if(e.data.msgCode == "PAUSE"){
  196. this.startWashCarFail()
  197. }
  198. }
  199. // 进度消息
  200. if(e.data.level == 'C'&&this.status!="reseting"&&e.data.msgCodeSrc){
  201. this.curWorkStutesText= e.data.msgCodeInfo
  202. // 启动成功
  203. this.startWashCarSuccess()
  204. // 更新进度条
  205. this.step = e.data.msgCodeSrc?Number(e.data.msgCodeSrc.split('-')[1]):0
  206. this.$store.state.vuex_workStep = this.step
  207. this.loading()
  208. // 洗车完成
  209. if(e.data.msgCode=="XCWC"){
  210. this.washCarSuccess()
  211. }
  212. }
  213. // 错误消息
  214. if(e.data.level == 'F'&&this.status!="reseting"){
  215. this.curWorkStutesText= e.data.msgCodeInfo
  216. // 启动成功
  217. this.startWashCarSuccess()
  218. // 显示复位提示弹框
  219. this.showReset()
  220. }
  221. // 急停
  222. if(e.data.level == 'A'){
  223. if(e.data.msgCode=="JJTZ"||e.data.msgCode=="XCX_JJTZ"){
  224. this.curWorkStutesText= e.data.msgCodeInfo
  225. // 显示复位提示弹框
  226. this.showReset()
  227. }else{
  228. this.devError()
  229. }
  230. }
  231. // 复位状态
  232. if(e.data.level == 'D'){
  233. // 开始复位中
  234. if(e.data.msgCode=="FW_START"){
  235. this.reseting()
  236. }
  237. // 复位成功
  238. if(e.data.msgCode=="FW_SUCC"){
  239. this.resetRabtSuccess()
  240. }
  241. // 设备离线,设备暂停营业或复位失败
  242. if(e.data.msgCode=="PAUSE" || e.data.msgCode == "FW_FAIL"){
  243. this.devError()
  244. }
  245. }
  246. }
  247. },
  248. // 重置到进度条初始状态
  249. resetLoadingStatus(){
  250. this.rdeg= -135;
  251. this.ldeg= -135;
  252. },
  253. // 洗车机进度条动画
  254. loading() {
  255. if(this.step==16){this.step = 8}
  256. let second = this.step*this.washDuration
  257. if (second <= 30) {
  258. this.rdeg = -135 + 6 * second;
  259. this.ldeg = -135;
  260. } else {
  261. this.rdeg = 45;
  262. this.ldeg = -135 + 6 * (second - 30);
  263. }
  264. },
  265. // 操作按钮
  266. startWork() {
  267. let _this = this
  268. // 启动
  269. if (this.status == 'start') {
  270. this.sendCmdRabt("start")
  271. this.starting()
  272. }
  273. // 急停
  274. if (this.status == 'working') {
  275. uni.showModal({
  276. title: '提示',
  277. content: '确定紧急停止洗车机?',
  278. success: function (res) {
  279. if (res.confirm) {
  280. _this.sendCmdRabt("stop")
  281. _this.stoping()
  282. }
  283. }
  284. });
  285. }
  286. },
  287. // 启动中
  288. starting(){
  289. this.showStart = true;
  290. this.status = 'starting';
  291. this.$store.state.vuex_workStatus = 'starting';
  292. this.curWorkStutesText='设备启动中';
  293. },
  294. // 启动成功
  295. startWashCarSuccess(){
  296. // 进度条,服务时间根据不同的服务类型而不同
  297. if(this.step==0){
  298. this.showStart = false;
  299. this.status = 'working';
  300. this.$store.state.vuex_workStatus = 'working';
  301. }
  302. },
  303. // 启动超时
  304. startWashCarFail(){
  305. this.showStart = false;
  306. this.status = 'start';
  307. this.$store.state.vuex_workStatus = 'start';
  308. this.curWorkStutesText='设备启动超时,请重新点击启动'
  309. uni.showToast({
  310. title: "设备启动超时",
  311. duration: 3000
  312. })
  313. },
  314. // 发送命令,start 启动,stop 急停,reset 归位
  315. sendCmdRabt(cmdCode){
  316. // 归位命令
  317. let cmd = {
  318. orderNo: this.orderNo, // 订单编号
  319. operateType: cmdCode, //操作命令
  320. washType: this.washCarType,// 洗车模式
  321. }
  322. this.$store.commit("$sendWebsocket",JSON.stringify(cmd))
  323. },
  324. // 停止中
  325. stoping(){
  326. this.showStart = true;
  327. this.status = 'stoping';
  328. this.$store.state.vuex_workStatus = 'stoping';
  329. this.curWorkStutesText='设备停止中';
  330. },
  331. // 停止成功后或有F类错误时,显示复位弹框
  332. showReset(){
  333. this.showStart = false;
  334. this.showStop = true;
  335. this.status = 'reset';
  336. this.$store.state.vuex_workStatus = 'reset'
  337. this.resetLoadingStatus();
  338. },
  339. // 归位中
  340. reseting(){
  341. this.status = 'reseting';
  342. this.$store.state.vuex_workStatus = 'reseting';
  343. this.showStart = true;
  344. this.showStop = false;
  345. },
  346. // 归位结束后
  347. resetRabtSuccess(){
  348. this.curWorkStutesText='设备已归位';
  349. this.status = 'end';
  350. this.$store.state.vuex_workStatus = 'end';
  351. // 关闭socket
  352. this.$store.commit("$closeWebsocket");
  353. // 跳转到复位成功页面
  354. uni.redirectTo({
  355. url:"/pages/work/success/success?type=1"
  356. })
  357. },
  358. // 洗车完成
  359. washCarSuccess(){
  360. this.status = "end";
  361. this.$store.state.vuex_workStatus = 'end'
  362. this.curWorkStutesText='洗车已结束';
  363. this.resetLoadingStatus();
  364. uni.showModal({
  365. title: '提示',
  366. content: '洗车已结束',
  367. showCancel: false,
  368. success: function (res) {
  369. if (res.confirm) {
  370. // 跳转到成功页面
  371. uni.redirectTo({
  372. url:"/pages/work/success/success?type=0"
  373. })
  374. }
  375. }
  376. });
  377. // 关闭socket
  378. this.$store.commit("$closeWebsocket")
  379. },
  380. // 设备异常
  381. devError(){
  382. this.status = "end";
  383. this.$store.state.vuex_workStatus = 'end'
  384. this.resetLoadingStatus();
  385. uni.showModal({
  386. title: '提示',
  387. content: '设备异常,请联系客服',
  388. showCancel: false,
  389. success: function (res) {
  390. if (res.confirm) {
  391. uni.navigateBack()
  392. }
  393. }
  394. });
  395. // 关闭socket
  396. this.$store.commit("$closeWebsocket");
  397. },
  398. }
  399. };
  400. </script>
  401. <style lang="scss">
  402. // 扇形圆环
  403. .circle_process {
  404. position: absolute;
  405. width: 390rpx;
  406. height: 390rpx;
  407. }
  408. .circle_process .wrapper {
  409. width: 195rpx;
  410. height: 390rpx;
  411. position: absolute;
  412. top: 0;
  413. overflow: hidden;
  414. }
  415. .circle_process .right {
  416. right: 0;
  417. }
  418. .circle_process .left {
  419. left: 0;
  420. }
  421. .circle_process .circle {
  422. width: 390rpx;
  423. height: 390rpx;
  424. border: 20rpx solid transparent;
  425. border-radius: 50%;
  426. position: absolute;
  427. top: 0;
  428. transform: rotate(-135deg);
  429. }
  430. .circle_process .rightcircle {
  431. border-top: 20rpx solid #4CD964;
  432. border-right: 20rpx solid #4CD964;
  433. right: 1px;
  434. }
  435. .circle_process .leftcircle {
  436. border-bottom: 20rpx solid #4CD964;
  437. border-left: 20rpx solid #4CD964;
  438. left: 1px;
  439. }
  440. // 动画
  441. @keyframes mymove {
  442. 0% {
  443. transform: scale(1); /*开始为原始大小*/
  444. opacity: 1;
  445. }
  446. 50% {
  447. transform: scale(1.2); /*放大1.1倍*/
  448. opacity: 0;
  449. }
  450. }
  451. .work-pages {
  452. width: 100%;
  453. .flex-center {
  454. display: flex;
  455. align-items: center;
  456. justify-content: center;
  457. }
  458. .work-cons {
  459. height: 50vh;
  460. background-image: linear-gradient(0deg, #666, #333);
  461. border-bottom-left-radius: 500rpx 50rpx;
  462. border-bottom-right-radius: 500rpx 50rpx;
  463. position: relative;
  464. // 按钮
  465. .work-button-wrap {
  466. width: 400rpx;
  467. margin-top: -50rpx;
  468. .work-button {
  469. background: #666;
  470. border-radius: 100%;
  471. width: 390rpx;
  472. height: 390rpx;
  473. box-shadow:inset 0rpx 2rpx 10rpx #000;
  474. .cirle-one {
  475. background-image: linear-gradient(180deg, #666, #333 30%);
  476. width: 370rpx;
  477. height: 370rpx;
  478. border-radius: 100%;
  479. position: absolute;
  480. box-shadow: 0rpx 2rpx 10rpx #333;
  481. }
  482. .cirle-two {
  483. width: 370rpx;
  484. height: 370rpx;
  485. border-radius: 100%;
  486. position: absolute;
  487. .sector {
  488. transform-origin: center center;
  489. width: 350rpx;
  490. height: 5rpx;
  491. background: #777;
  492. }
  493. }
  494. .cirle-three {
  495. background: #444;
  496. width: 280rpx;
  497. height: 280rpx;
  498. border-radius: 100%;
  499. position: absolute;
  500. box-shadow: inset 0rpx 3rpx 10rpx #000;
  501. }
  502. .cirle-free, .cirle-free-1, .cirle-free-2 {
  503. width: 230rpx;
  504. height: 230rpx;
  505. border-radius: 100%;
  506. position: absolute;
  507. animation: mymove 5s infinite;
  508. }
  509. .cirle-free-1{
  510. width: 210rpx;
  511. height: 210rpx;
  512. animation: mymove 4.5s infinite;
  513. }
  514. .cirle-free-2{
  515. width: 190rpx;
  516. height: 190rpx;
  517. animation: mymove 4s infinite;
  518. }
  519. .cirle-sex {
  520. background-image: linear-gradient(180deg, #888, #333 50%);
  521. box-shadow: 0rpx 5rpx 10rpx #333;
  522. width: 210rpx;
  523. height: 210rpx;
  524. border-radius: 100%;
  525. position: absolute;
  526. color: #ffffff;
  527. font-size: 28rpx;
  528. color: #eee;
  529. &:active {
  530. background-image: linear-gradient(-180deg, #666, #333 80%);
  531. }
  532. }
  533. .w-start {
  534. background: #ffc800;
  535. }
  536. .w-stop {
  537. background: #ff0000;
  538. }
  539. }
  540. }
  541. .work-button-tips {
  542. width: 80%;
  543. color: #eee;
  544. text-align: center;
  545. padding-top: 30rpx;
  546. .u-swiper-item{
  547. justify-content: center;
  548. }
  549. }
  550. }
  551. .work-tips {
  552. padding: 45rpx;
  553. .work-dtime {
  554. text-align: center;
  555. font-weight: bold;
  556. font-size: 34rpx;
  557. }
  558. .work-remarks {
  559. padding-top: 50rpx;
  560. .red {
  561. color: red;
  562. }
  563. .title {
  564. font-weight: bold;
  565. }
  566. }
  567. }
  568. }
  569. </style>