index.vue 17 KB

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