index.vue 8.3 KB

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