index.vue 8.7 KB

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