index.vue 10.0 KB

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