index.vue 18 KB

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