index.vue 8.9 KB

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