index.vue 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368
  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.drawLine();
  98. this.InitWs()
  99. },
  100. methods: {
  101. //判断websocket是否链接上
  102. InitWs() {
  103. if (this.$storage.get("exchangeNo")) {
  104. let msg = {
  105. type: "subscribeExchange",
  106. payLoad: {
  107. exchangeNo: this.$storage.get("exchangeNo")
  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. }else{
  117. this.getWsData()
  118. this.$ws.sendmessage(msg)
  119. }
  120. }else {
  121. this.$utils.msg('未获取到换电编号')
  122. }
  123. },
  124. // //获取websocket数据
  125. getWsData() {
  126. this.$ws.onSocketMsg = (res) => {
  127. let data = JSON.parse(res.data)
  128. console.log(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. this.swapInfoDTO=data.swapInfoDTO
  134. this.process_txt=data.swapConfirmDTO.vehSoc
  135. } else {
  136. this.$utils.msg('订阅失败')
  137. }
  138. }
  139. },
  140. goto(url) {
  141. if (uni.getStorageSync("token")) {
  142. if (this.$storage.get("exchangeNo")) {
  143. let msg = {
  144. type: "startExchange",
  145. payLoad: {
  146. exchangeNo: this.$storage.get("exchangeNo")
  147. }
  148. }
  149. this.$ws.sendmessage(msg)
  150. this.$ws.onSocketMsg = (res) =>{
  151. let data=JSON.parse(res.data)
  152. console.log(res.data)
  153. if (data.type === 'start' && data.state ===0) {
  154. uni.navigateTo({
  155. url: url
  156. })
  157. }else {
  158. this.$utils.msg('下发换电指令失败')
  159. }
  160. }
  161. }
  162. } else {
  163. uni.reLaunch({
  164. url: '/pages/public/login?item=scan'
  165. })
  166. }
  167. },
  168. drawProgressbg() {
  169. // 自定义组件实例 this ,表示在这个自定义组件下查找拥有 canvas-id 的 <canvas/>
  170. var ctx = uni.createCanvasContext('cpbg', this);
  171. ctx.setLineWidth(14); // 设置圆环的宽度
  172. ctx.setStrokeStyle('#dadada'); // 设置圆环的颜色
  173. ctx.setLineCap('round'); // 设置圆环端点的形状
  174. ctx.setLineCap('square'); // 设置圆环端点的形状
  175. ctx.beginPath(); //开始一个新的路径
  176. ctx.arc(110, 110, 70, 0 * Math.PI, 2 * Math.PI, false);
  177. //设置一个原点(110,110),半径为100的圆的路径到当前路径
  178. ctx.stroke(); //对当前路径进行描边
  179. ctx.draw();
  180. },
  181. drawCircle(step) {
  182. var ctx = uni.createCanvasContext('cpbar', this);
  183. // 进度条的渐变(中心x坐标-半径-边宽,中心Y坐标,中心x坐标+半径+边宽,中心Y坐标)
  184. var gradient = ctx.createLinearGradient(0, 0, 130, 0);
  185. let increase = 0.05;
  186. let end = (step / 100) * 2 * Math.PI - Math.PI / 2; // 最后的角度
  187. let current = -Math.PI / 2; // 起始角度
  188. let timer = setInterval(() => {
  189. gradient.addColorStop('0', '#58be6b');
  190. gradient.addColorStop('1.0', '#58be6b');
  191. ctx.setLineWidth(12);
  192. ctx.setStrokeStyle(gradient);
  193. ctx.setLineCap('square');
  194. ctx.beginPath();
  195. // 参数step 为绘制的百分比
  196. if (current < end) {
  197. current = current + increase;
  198. }
  199. if (current >= end) {
  200. current = end;
  201. clearInterval(timer);
  202. }
  203. ctx.arc(110, 110, 70, -Math.PI / 2, current, false);
  204. ctx.stroke();
  205. ctx.draw();
  206. }, 20);
  207. },
  208. drawLine() {
  209. var context = uni.createCanvasContext("cpline", this);
  210. var r = 70;
  211. var x0 = 110;
  212. var y0 = 110;
  213. var x;
  214. var y;
  215. var lineWidth = 12;
  216. for (let i = 0; i < 60; i++) {
  217. context.beginPath();
  218. context.setLineWidth(lineWidth);
  219. context.setStrokeStyle("#FFFFFF");
  220. x = x0 - r * Math.sin(((6 * (i + 1) - 3) * Math.PI) / 180);
  221. y = y0 - r * Math.cos(((6 * (i + 1) - 3) * Math.PI) / 180);
  222. // console.log('x0:' + x0 + ' y0:' + y0 + ' x:' + x + ' y:' + y);
  223. context.moveTo(x, y);
  224. context.arc(
  225. x0,
  226. y0,
  227. r,
  228. ((270 - 6 * (i + 1) + 3) * Math.PI) / 180,
  229. ((270 - 6 * i) * Math.PI) / 180,
  230. false
  231. );
  232. context.stroke();
  233. context.closePath();
  234. }
  235. context.stroke();
  236. context.draw();
  237. }
  238. }
  239. }
  240. </script>
  241. <style lang="scss" scoped>
  242. .progress_box {
  243. position: relative;
  244. width: 400rpx;
  245. height: 400rpx;
  246. display: flex;
  247. margin: 0 auto;
  248. align-items: center;
  249. justify-content: center;
  250. text-align: center;
  251. }
  252. .progress_bg {
  253. position: absolute;
  254. width: 220px;
  255. height: 220px;
  256. }
  257. .progress_bar {
  258. position: absolute;
  259. width: 220px;
  260. height: 220px;
  261. }
  262. .progress_line {
  263. position: absolute;
  264. width: 220px;
  265. height: 220px;
  266. }
  267. .progress_txt {
  268. position: absolute;
  269. font-size: 28upx;
  270. color: #999999;
  271. }
  272. .progress_info {
  273. font-size: 36upx;
  274. padding-left: 16upx;
  275. letter-spacing: 2upx;
  276. font-size: 52upx;
  277. color: #333333;
  278. }
  279. .progress_dot {
  280. width: 16upx;
  281. height: 16upx;
  282. border-radius: 50%;
  283. background-color: #fb9126;
  284. }
  285. .battery-info {
  286. display: flex;
  287. justify-content: space-between;
  288. padding: 0 80rpx;
  289. text-align: center;
  290. line-height: 36rpx;
  291. view>view:first-child {
  292. font-weight: bold;
  293. }
  294. view>view:last-child {
  295. color: #939da7;
  296. font-size: 26rpx;
  297. }
  298. }
  299. .carinfo {
  300. padding-left: 45rpx;
  301. width: 100%;
  302. box-sizing: border-box;
  303. margin-top: 90rpx;
  304. .battery-list {
  305. display: flex;
  306. width: 100%;
  307. margin-top: 36rpx;
  308. .icon {
  309. width: 55rpx;
  310. padding-top: 5rpx;
  311. image {
  312. width: 32rpx;
  313. height: 32rpx;
  314. }
  315. }
  316. .info {
  317. display: flex;
  318. flex: 1;
  319. border-bottom: #e5e5e5 solid 1px;
  320. justify-content: space-between;
  321. font-size: 28rpx;
  322. padding-bottom: 36rpx;
  323. padding-right: 40rpx;
  324. box-sizing: border-box;
  325. .word {
  326. color: #86909c;
  327. }
  328. .number {
  329. color: #333333;
  330. font-weight: bold;
  331. }
  332. }
  333. }
  334. }
  335. .submit {
  336. width: 600rpx;
  337. height: 88rpx;
  338. margin: 35rpx auto;
  339. font-size: 36rpx;
  340. background-color: #58be6b;
  341. color: #fff;
  342. border-radius: 44rpx;
  343. }
  344. </style>