index.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409
  1. <template>
  2. <view>
  3. <scan-info
  4. :swapInfoDTO="swapInfoDTO"
  5. :swapConfirmDTO="swapConfirmDTO"
  6. @sendExchangeMsg="sendExchangeMsg"
  7. :exchangeNo="exchangeNo"
  8. v-show="pageState===1">
  9. </scan-info>
  10. <view class="swapinfo" v-show="pageState===2">
  11. <view class="header">
  12. <view @click="getTab(1)" :class="{'active':currentTab===1}">换电流程</view>
  13. <view @click="getTab(2)" :class="{'active':currentTab===2}">车辆信息</view>
  14. <view @click="getTab(3)" :class="{'active':currentTab===3}">电池信息</view>
  15. </view>
  16. <view class="changeProcess" v-show="currentTab===1">
  17. <view class="changeCurrent">
  18. <view class="info">
  19. <view>
  20. <image src="../../static/icon7.png"></image>
  21. </view>
  22. <view>{{currentDescript || '-'}}</view>
  23. </view>
  24. <view class="times">
  25. {{currentTime || '-'}} | {{plate || '-'}}
  26. </view>
  27. </view>
  28. <view class="timeline">
  29. <view class="timeinfo">
  30. <view class="list" v-for="(item,index) in swapStepList" :key="index">
  31. <view>{{$moment(item.seqTime).format("YYYY-MM-DD")}}</view>
  32. <view>{{$moment(item.seqTime).format("HH:mm:ss")}}</view>
  33. </view>
  34. </view>
  35. <view class="line">
  36. <uni-steps :options="swapStepList" :active="step" direction="column"></uni-steps>
  37. </view>
  38. </view>
  39. </view>
  40. <view class="changeCar" v-show="currentTab===2">
  41. <view class="ban">
  42. <image src="../../static/car-info.png"></image>
  43. </view>
  44. <view class="info-box">
  45. <sub-title descript="车牌" :values="swapInfoDTO.plate"></sub-title>
  46. <sub-title descript="VIN码" :values="swapInfoDTO.vin"></sub-title>
  47. <sub-title descript="累计里程" :values="swapInfoDTO.mileage" unit="km"></sub-title>
  48. <sub-title descript="累计换电" :values="times" unit="次"></sub-title>
  49. <sub-title descript="解锁状态" :values="swapInfoDTO.lockState===1?'已解锁':'已上锁'"></sub-title>
  50. <sub-title descript="上电状态" :values="swapInfoDTO.powerOnState===0?'已下电':'未下电'"></sub-title>
  51. </view>
  52. </view>
  53. <view class="changeBattery" v-show="currentTab===3">
  54. <view class="ban">
  55. <image src="../../static/battery-info.png"></image>
  56. </view>
  57. <view class="info-box">
  58. <sub-title descript="车辆电池编号" :values="swapInfoDTO.vehSn"></sub-title>
  59. <sub-title descript="车辆电池SOC" :values="swapInfoDTO.vehSoc" unit="%"></sub-title>
  60. <view class="list">
  61. <view>换电电池编号:</view>
  62. <zb-tooltip :content="swapInfoDTO.swapSn" placement="top" ref="tooltip13" color="#58be6b">
  63. <view v-if="swapInfoDTO" @click="showBattery">{{swapInfoDTO.swapSn | fiterBattery}}</view>
  64. </zb-tooltip>
  65. </view>
  66. <sub-title descript="换电电池SOC" :values="swapInfoDTO.swapSoc" unit="%"></sub-title>
  67. <sub-title descript="换电量" :values="swapInfoDTO.swapCapacity" unit="(kW/h)"></sub-title>
  68. <sub-title descript="累计里程" :values="swapInfoDTO.mileage" unit="km"></sub-title>
  69. </view>
  70. </view>
  71. </view>
  72. </view>
  73. </template>
  74. <script>
  75. export default {
  76. data() {
  77. return {
  78. swapStepList: [],
  79. step: 0,
  80. currentDescript: '',
  81. currentTime: '',
  82. plate: '',
  83. swapInfoDTO: null,
  84. swapConfirmDTO: null,
  85. currentTab: 1, //当前tab
  86. swapState: -1,
  87. ws: null,
  88. timer: null,
  89. exchangeNo: null,
  90. times: 0, //累计换电次数,
  91. getStationCode:null,
  92. }
  93. },
  94. mounted() {
  95. this.$bus.$on('sendMsg2', this.sendExchangeMsg)
  96. if(this.getStationCode && this.exchangeNo){
  97. this.InitWs(this.exchangeNo, this.getStationCode)
  98. }
  99. },
  100. onLoad(options) {
  101. if (options.exchangeNo && options.stationCode) {
  102. this.getStationCode=options.stationCode
  103. this.exchangeNo = options.exchangeNo
  104. } else {
  105. this.$utils.msg('参数丢失!')
  106. }
  107. },
  108. filters:{
  109. fiterBattery:function(val){
  110. if(!val){
  111. return '-'
  112. }else{
  113. return val.substring(0,4)+'****'+val.substring(val.length-4)
  114. }
  115. },
  116. },
  117. onUnload() {
  118. console.log('onUnload')
  119. clearInterval(this.timer)
  120. this.timer = null
  121. this.ws.close()
  122. uni.redirectTo({
  123. url: '/pages/index/index'
  124. })
  125. },
  126. computed: {
  127. pageState() {
  128. if (this.swapState === -1) {
  129. return 0
  130. } else if (this.swapState === 1) {
  131. return 1
  132. } else {
  133. return 2
  134. }
  135. }
  136. },
  137. watch: {
  138. pageState(val) {
  139. if (val === 0) {
  140. uni.showLoading({
  141. title: ''
  142. });
  143. } else {
  144. uni.hideLoading();
  145. }
  146. }
  147. },
  148. methods: {
  149. //显示电池编号
  150. showBattery(){
  151. },
  152. //切换tab
  153. getTab(num) {
  154. if (num === 2) {
  155. this.currentTab = 2
  156. this.$http.getExchangeTimes(this.swapInfoDTO.vin).then(res => {
  157. this.times = res.data
  158. })
  159. } else if (num === 3) {
  160. this.currentTab = 3
  161. } else {
  162. this.currentTab = 1
  163. }
  164. },
  165. //判断websocket是否链接上
  166. InitWs(exchangeNo, stationCode) {
  167. if (exchangeNo && stationCode) {
  168. if (this.ws != null) {
  169. this.ws.close()
  170. this.ws = null
  171. }
  172. if (this.timer != null) {
  173. clearInterval(this.timer)
  174. this.timer = null
  175. }
  176. let users = this.$storage.getJson("users");
  177. let token = this.$storage.getJson("token");
  178. if (users == null || token == null) {
  179. navigateTo("public/login");
  180. return false;
  181. }
  182. this.ws = uni.connectSocket({
  183. url: this.$config.web_socket_url + stationCode + '/' + token,
  184. header: {
  185. 'content-type': 'application/json'
  186. },
  187. complete: () => {}
  188. })
  189. this.ws.onOpen(() => {
  190. let msg = {
  191. type: "subscribeExchange",
  192. payLoad: {
  193. exchangeNo: exchangeNo
  194. }
  195. }
  196. this.ws.send({
  197. data: JSON.stringify(msg)
  198. })
  199. })
  200. this.ws.onMessage((res) => {
  201. let data = JSON.parse(res.data)
  202. console.log(data)
  203. if (data.type === 'subscribe') {
  204. if (data.state === 0) {
  205. console.log('订阅成功')
  206. } else {
  207. this.$utils.msg('订阅失败')
  208. }
  209. } else if (data.type === 'swapInfo') {
  210. this.swapConfirmDTO = data.swapConfirmDTO
  211. this.swapInfoDTO = data.swapInfoDTO
  212. this.swapState = data.swapConfirmDTO.swapState
  213. data.swapStepList.reverse()
  214. this.currentDescript = data.swapStepList[0].description,
  215. this.currentTime = data.swapStepList[0].seqTime,
  216. this.plate = data.swapConfirmDTO.plate
  217. this.swapStepList.unshift(...data.swapStepList)
  218. this.step = 0
  219. this.$bus.$emit('OndrawCircle', Math.ceil((data.swapConfirmDTO.vehSoc) * 1))
  220. } else if (data.type === 'startReply') {
  221. if (data.state === 0) {
  222. this.swapState = 2
  223. console.log('站控已启动')
  224. } else {
  225. this.$utils.msg('站控启动失败')
  226. }
  227. }
  228. })
  229. // 监听WebSocket关闭事件
  230. this.ws.onClose(() => {
  231. console.log('WebSocket连接已关闭!');
  232. })
  233. this.ws.onError(() => {
  234. console.log("WebSocket连接错误")
  235. })
  236. if (this.timer == null) {
  237. this.timer = setInterval(() => {
  238. if (this.ws.readyState != 1) {
  239. clearInterval(this.timer)
  240. this.timer = null
  241. this.ws.close()
  242. this.InitWs(exchangeNo, stationCode)
  243. }
  244. }, 2000)
  245. }
  246. } else {
  247. uni.switchTab({
  248. url: '/pages/index/index'
  249. })
  250. }
  251. },
  252. sendExchangeMsg(msg) {
  253. this.ws.send(msg)
  254. }
  255. }
  256. }
  257. </script>
  258. <style lang="scss" scoped>
  259. .swapinfo {
  260. //顶部
  261. .header {
  262. display: flex;
  263. padding: 30rpx;
  264. width: 690rpx;
  265. color: #86909c;
  266. font-size: 32rpx;
  267. justify-content: space-around;
  268. .active {
  269. color: #1d2129;
  270. font-weight: bold;
  271. position: relative;
  272. }
  273. .active::after {
  274. content: '';
  275. background-image: url('@/static/line.png');
  276. background-size: 100% 100%;
  277. width: 52rpx;
  278. height: 9rpx;
  279. position: absolute;
  280. bottom: -25rpx;
  281. left: 32%;
  282. }
  283. }
  284. //换电流程
  285. .changeProcess {
  286. padding-bottom: 20rpx;
  287. .timeline {
  288. display: flex;
  289. box-shadow: 0rpx 0rpx 10rpx 0rpx rgba(226, 226, 226, 0.25);
  290. border-radius: 24rpx;
  291. background-color: #fff;
  292. margin: 30rpx;
  293. padding: 29rpx;
  294. opacity: 1;
  295. .timeinfo {
  296. display: flex;
  297. flex-direction: column;
  298. text-align: right;
  299. .list {
  300. display: flex;
  301. flex-direction: column;
  302. width: 100%;
  303. height: 102rpx;
  304. color: #c9cdd4;
  305. font-size: 28rpx;
  306. view:first-child {
  307. color: #86909c;
  308. }
  309. }
  310. }
  311. .line {
  312. flex: 1;
  313. }
  314. }
  315. .changeCurrent {
  316. width: 690rpx;
  317. margin: 30rpx auto;
  318. height: 180rpx;
  319. background-image: url('@/static/change-bg.png');
  320. background-size: 100% 100%;
  321. padding: 25rpx;
  322. box-sizing: border-box;
  323. display: flex;
  324. flex-direction: column;
  325. justify-content: space-around;
  326. .info {
  327. display: flex;
  328. color: #fff;
  329. font-size: 30rpx;
  330. font-weight: bold;
  331. line-height: 36rpx;
  332. image {
  333. width: 60rpx;
  334. height: 60rpx;
  335. padding-right: 25rpx;
  336. }
  337. view:last-child {
  338. padding-top: 12rpx;
  339. }
  340. }
  341. .times {
  342. color: #ededed;
  343. text-indent: 10rpx;
  344. }
  345. }
  346. }
  347. //换电流程车和电池信息
  348. .changeCar,
  349. .changeBattery {
  350. width: 690rpx;
  351. margin: 30rpx 30rpx;
  352. padding: 15rpx 0rpx;
  353. box-shadow: 0rpx 0rpx 10rpx 0rpx rgba(226, 226, 226, 0.25);
  354. border-radius: 24rpx;
  355. opacity: 1;
  356. background-color: #fff;
  357. .ban {
  358. width: 547rpx;
  359. height: 298rpx;
  360. margin: 70rpx auto;
  361. image {
  362. width: 100%;
  363. height: 100%;
  364. }
  365. }
  366. .info-box {
  367. width: 587rpx;
  368. margin: 0 auto;
  369. display: flex;
  370. flex-direction: column;
  371. .list {
  372. width: 100%;
  373. display: flex;
  374. height: 100rpx;
  375. justify-content: space-between;
  376. font-size: 30rpx;
  377. view:first-child {
  378. color: #86909c;
  379. }
  380. view:last-child {
  381. color: #1d2129;
  382. }
  383. }
  384. }
  385. }
  386. }
  387. </style>