index.vue 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342
  1. <template>
  2. <view>
  3. <view class="progress_box">
  4. <canvas class="progress_bg" canvas-id="cpbg"></canvas>
  5. <canvas class="progress_bar" canvas-id="cpbar"></canvas>
  6. <canvas class="progress_line" canvas-id="cpline"></canvas>
  7. <view class="progress_txt">
  8. <view class="progress_info">{{ $scan.swapConfirmDTO.vehSoc || '-' }}%</view>
  9. <view>当前电池SOC</view>
  10. </view>
  11. </view>
  12. <view class="battery-info">
  13. <view>
  14. <view>{{swapInfoDTO.mileage || '-'}}km</view>
  15. <view>累计里程</view>
  16. </view>
  17. <view>
  18. <view>{{ $scan.swapConfirmDTO.vehVol || '-' }}V</view>
  19. <view>电压</view>
  20. </view>
  21. <view>
  22. <view>{{ swapConfirmDTO.vehCur || '-' }}A</view>
  23. <view>电流</view>
  24. </view>
  25. </view>
  26. <view class="carinfo">
  27. <view class="battery-list">
  28. <view class="icon"><image src="../../static/p1.png"></image></view>
  29. <view class="info">
  30. <view class="word">车牌号</view>
  31. <view class="number">{{ swapConfirmDTO.plate || '-' }}</view>
  32. </view>
  33. </view>
  34. <view class="battery-list">
  35. <view class="icon"><image src="../../static/p2.png"></image></view>
  36. <view class="info">
  37. <view class="word">当前车辆电池SOC</view>
  38. <view class="number">{{ swapConfirmDTO.vehSoc || '-' }}%</view>
  39. </view>
  40. </view>
  41. <view class="battery-list">
  42. <view class="icon"><image src="../../static/p3.png"></image></view>
  43. <view class="info">
  44. <view class="word">换电电池SOC</view>
  45. <view class="number">{{ swapConfirmDTO.swapSoc || '-' }}%</view>
  46. </view>
  47. </view>
  48. <view class="battery-list">
  49. <view class="icon"><image src="../../static/p4.png"></image></view>
  50. <view class="info">
  51. <view class="word">预估换电费用</view>
  52. <view class="number">{{ swapConfirmDTO.expense || '-' }}元</view>
  53. </view>
  54. </view>
  55. <view class="battery-list">
  56. <view class="icon"><image src="../../static/p5.png"></image></view>
  57. <view class="info">
  58. <view class="word">服务费</view>
  59. <view class="number">{{ swapConfirmDTO.serviceCharge || '-' }}元</view>
  60. </view>
  61. </view>
  62. </view>
  63. <button type="primary" @click="goto('/pages/monitoring/index')" class="submit" :disabled="swapConfirmDTO.swapState">确认换电</button>
  64. </view>
  65. </template>
  66. <script>
  67. export default {
  68. data() {
  69. return {
  70. qrcode:null,
  71. // swapConfirmDTO:this.$scan.swapConfirmDTO,
  72. // swapInfoDTO:this.$scan.SwapInfoDTO,
  73. process_txt:0,
  74. }
  75. },
  76. beforeCreate() {
  77. if(!uni.getStorageSync("token")){
  78. uni.reLaunch({
  79. url:'/pages/public/login?item=scan'
  80. })
  81. }
  82. },
  83. mounted() {
  84. this.drawProgressbg();
  85. this.drawCircle(this.process_txt); //参数为1-100
  86. this.drawLine();
  87. this.$scan.InitWs()
  88. },
  89. methods: {
  90. // InitWs(){
  91. // console.log(this.$scan)
  92. // this.$scan.InitWs()
  93. // setTimeout(()=>{
  94. // this.swapConfirmDTO=this.$scan.swapConfirmDTO
  95. // this.swapInfoDTO=this.$scan.swapInfoDTO
  96. // this.process_txt=Math.ceil(this.swapConfirmDTO.vehSoc)
  97. // },1000)
  98. // },
  99. //判断websocket是否链接上
  100. // InitWs(){
  101. // if(this.$storage.get("stationCode")){
  102. // this.$http.getStationExchange({stationCode:this.$storage.get("stationCode")}).then(res=>{
  103. // if(res.code === 0 && res.data){
  104. // let msg = {
  105. // type: "subscribeExchange",
  106. // payLoad: {
  107. // exchangeNo: res.data
  108. // }
  109. // }
  110. // if(this.$ws.socketTask ==null){
  111. // this.$ws.connect()
  112. // this.$ws.onSocketOpen=()=>{
  113. // this.getWsData()
  114. // this.$ws.sendmessage(msg)
  115. // }
  116. // }
  117. // }else{
  118. // this.$utils.msg(res.msg)
  119. // }
  120. // })
  121. // }else{
  122. // this.$utils.msg('未获取到换电站编号')
  123. // }
  124. // },
  125. // // //获取websocket数据
  126. // getWsData(){
  127. // this.$ws.onSocketMsg=(res)=>{
  128. // let data=JSON.parse(res.data)
  129. // if(data.type === 'subscribe'){
  130. // console.log(data.state)
  131. // }else if(data.type === 'swapInfo' && data.state === 0){
  132. // this.swapConfirmDTO=data.swapConfirmDTO
  133. // }
  134. // else{
  135. // this.$utils.msg('订阅失败')
  136. // }
  137. // }
  138. // },
  139. goto(url){
  140. if(uni.getStorageSync("token")){
  141. if(this.$storage.get("exchangeNo")){
  142. let msg = {
  143. type: "startExchange",
  144. payLoad: {
  145. exchangeNo: this.$storage.get("exchangeNo")
  146. }
  147. }
  148. this.$ws.sendmessage(msg)
  149. }
  150. uni.navigateTo({
  151. url:url
  152. })
  153. }else{
  154. uni.reLaunch({
  155. url:'/pages/public/login?item=scan'
  156. })
  157. }
  158. },
  159. drawProgressbg(){
  160. // 自定义组件实例 this ,表示在这个自定义组件下查找拥有 canvas-id 的 <canvas/>
  161. var ctx = uni.createCanvasContext('cpbg', this);
  162. ctx.setLineWidth(14); // 设置圆环的宽度
  163. ctx.setStrokeStyle('#dadada'); // 设置圆环的颜色
  164. ctx.setLineCap('round'); // 设置圆环端点的形状
  165. ctx.setLineCap('square'); // 设置圆环端点的形状
  166. ctx.beginPath(); //开始一个新的路径
  167. ctx.arc(110, 110, 70, 0 * Math.PI, 2 * Math.PI, false);
  168. //设置一个原点(110,110),半径为100的圆的路径到当前路径
  169. ctx.stroke(); //对当前路径进行描边
  170. ctx.draw();
  171. },
  172. drawCircle(step){
  173. var ctx = uni.createCanvasContext('cpbar', this);
  174. // 进度条的渐变(中心x坐标-半径-边宽,中心Y坐标,中心x坐标+半径+边宽,中心Y坐标)
  175. var gradient = ctx.createLinearGradient(0, 0, 130, 0);
  176. let increase = 0.05;
  177. let end = (step / 100) * 2 * Math.PI - Math.PI / 2; // 最后的角度
  178. let current = -Math.PI / 2; // 起始角度
  179. let timer = setInterval(() => {
  180. gradient.addColorStop('0', '#58be6b');
  181. gradient.addColorStop('1.0', '#58be6b');
  182. ctx.setLineWidth(12);
  183. ctx.setStrokeStyle(gradient);
  184. ctx.setLineCap('square');
  185. ctx.beginPath();
  186. // 参数step 为绘制的百分比
  187. if (current < end) {
  188. current = current + increase;
  189. }
  190. if (current >= end) {
  191. current = end;
  192. clearInterval(timer);
  193. }
  194. ctx.arc(110, 110, 70, -Math.PI / 2, current, false);
  195. ctx.stroke();
  196. ctx.draw();
  197. }, 20);
  198. },
  199. drawLine(){
  200. var context = uni.createCanvasContext("cpline",this);
  201. var r = 70;
  202. var x0 = 110;
  203. var y0 = 110;
  204. var x;
  205. var y;
  206. var lineWidth = 12;
  207. for (let i = 0; i < 60; i++) {
  208. context.beginPath();
  209. context.setLineWidth(lineWidth);
  210. context.setStrokeStyle("#FFFFFF");
  211. x = x0 - r * Math.sin(((6 * (i + 1) - 3) * Math.PI) / 180);
  212. y = y0 - r * Math.cos(((6 * (i + 1) - 3) * Math.PI) / 180);
  213. // console.log('x0:' + x0 + ' y0:' + y0 + ' x:' + x + ' y:' + y);
  214. context.moveTo(x, y);
  215. context.arc(
  216. x0,
  217. y0,
  218. r,
  219. ((270 - 6 * (i + 1) + 3) * Math.PI) / 180,
  220. ((270 - 6 * i) * Math.PI) / 180,
  221. false
  222. );
  223. context.stroke();
  224. context.closePath();
  225. }
  226. context.stroke();
  227. context.draw();
  228. }
  229. }
  230. }
  231. </script>
  232. <style lang="scss" scoped>
  233. .progress_box {
  234. position: relative;
  235. width: 400rpx;
  236. height: 400rpx;
  237. display: flex;
  238. margin: 0 auto;
  239. align-items: center;
  240. justify-content: center;
  241. text-align: center;
  242. }
  243. .progress_bg {
  244. position: absolute;
  245. width: 220px;
  246. height: 220px;
  247. }
  248. .progress_bar {
  249. position: absolute;
  250. width: 220px;
  251. height: 220px;
  252. }
  253. .progress_line {
  254. position: absolute;
  255. width: 220px;
  256. height: 220px;
  257. }
  258. .progress_txt {
  259. position: absolute;
  260. font-size: 28upx;
  261. color: #999999;
  262. }
  263. .progress_info {
  264. font-size: 36upx;
  265. padding-left: 16upx;
  266. letter-spacing: 2upx;
  267. font-size: 52upx;
  268. color: #333333;
  269. }
  270. .progress_dot {
  271. width: 16upx;
  272. height: 16upx;
  273. border-radius: 50%;
  274. background-color: #fb9126;
  275. }
  276. .battery-info{
  277. display: flex;
  278. justify-content: space-between;
  279. padding: 0 80rpx;
  280. text-align: center;
  281. line-height: 36rpx;
  282. view > view:first-child{
  283. font-weight: bold;
  284. }
  285. view > view:last-child{
  286. color: #939da7;
  287. font-size: 26rpx;
  288. }
  289. }
  290. .carinfo{
  291. padding-left: 45rpx;
  292. width: 100%;
  293. box-sizing: border-box;
  294. margin-top: 90rpx;
  295. .battery-list{
  296. display: flex;
  297. width: 100%;
  298. margin-top: 36rpx;
  299. .icon{
  300. width: 55rpx;
  301. padding-top: 5rpx;
  302. image{
  303. width: 32rpx;
  304. height: 32rpx;
  305. }
  306. }
  307. .info{
  308. display: flex;
  309. flex: 1;
  310. border-bottom:#e5e5e5 solid 1px;
  311. justify-content: space-between;
  312. font-size: 28rpx;
  313. padding-bottom: 36rpx;
  314. padding-right: 40rpx;
  315. box-sizing: border-box;
  316. .word{
  317. color: #86909c;
  318. }
  319. .number{
  320. color: #333333;
  321. font-weight: bold;
  322. }
  323. }
  324. }
  325. }
  326. .submit{
  327. width: 600rpx;
  328. height: 88rpx;
  329. margin:35rpx auto;
  330. font-size: 36rpx;
  331. background-color: #58be6b;
  332. color: #fff;
  333. border-radius: 44rpx;
  334. }
  335. </style>