scan-info.vue 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321
  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 || 0 }}%</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="swapSubmit" class="submit" :disabled="swapConfirmDTO.swapState==2" :loading="swapConfirmDTO.swapState==2">
  74. {{swapConfirmDTO.swapState==1?'确认换电':'换电进行中'}}</button>
  75. </view>
  76. </template>
  77. <script>
  78. export default {
  79. name: "scan-info",
  80. props: ['swapConfirmDTO', 'swapInfoDTO', 'exchangeNo'],
  81. data() {
  82. return {
  83. percent: 0,
  84. currentAngle: null,
  85. angleTimer: null
  86. }
  87. },
  88. beforeCreate() {
  89. if (!uni.getStorageSync("token")) {
  90. uni.reLaunch({
  91. url: '/pages/public/login?item=scan'
  92. })
  93. }
  94. },
  95. mounted() {
  96. this.drawProgressbg();
  97. this.$bus.$on('OndrawCircle', this.drawCircle) //参数为1-100
  98. this.drawLine();
  99. },
  100. methods: {
  101. swapSubmit() {
  102. let that = this
  103. if (uni.getStorageSync("token")) {
  104. if (this.exchangeNo) {
  105. let msg = {
  106. type: "startExchange",
  107. payLoad: {
  108. exchangeNo: this.exchangeNo
  109. }
  110. }
  111. this.$bus.$emit('sendMsg2', {
  112. data: JSON.stringify(msg)
  113. })
  114. }
  115. } else {
  116. uni.reLaunch({
  117. url: '/pages/public/login?item=scan'
  118. })
  119. }
  120. },
  121. drawProgressbg() {
  122. // 自定义组件实例 this ,表示在这个自定义组件下查找拥有 canvas-id 的 <canvas/>
  123. var ctx = uni.createCanvasContext('cpbg', this);
  124. ctx.setLineWidth(14); // 设置圆环的宽度
  125. ctx.setStrokeStyle('#dadada'); // 设置圆环的颜色
  126. ctx.setLineCap('round'); // 设置圆环端点的形状
  127. ctx.setLineCap('square'); // 设置圆环端点的形状
  128. ctx.beginPath(); //开始一个新的路径
  129. ctx.arc(110, 110, 70, 0 * Math.PI, 2 * Math.PI, false);
  130. //设置一个原点(110,110),半径为100的圆的路径到当前路径
  131. ctx.stroke(); //对当前路径进行描边
  132. ctx.draw();
  133. },
  134. drawCircle(step) {
  135. var ctx = uni.createCanvasContext('cpbar', this);
  136. // 进度条的渐变(中心x坐标-半径-边宽,中心Y坐标,中心x坐标+半径+边宽,中心Y坐标)
  137. var gradient = ctx.createLinearGradient(0, 0, 130, 0);
  138. let increase = 0.05;
  139. let end = (step / 100) * 2 * Math.PI - Math.PI / 2; // 最后的角度
  140. let current = -Math.PI / 2; // 起始角度
  141. let timer = setInterval(() => {
  142. gradient.addColorStop('0', '#58be6b');
  143. gradient.addColorStop('1.0', '#58be6b');
  144. ctx.setLineWidth(12);
  145. ctx.setStrokeStyle(gradient);
  146. ctx.setLineCap('square');
  147. ctx.beginPath();
  148. // 参数step 为绘制的百分比
  149. if (current < end) {
  150. current = current + increase;
  151. }
  152. if (current >= end) {
  153. current = end;
  154. clearInterval(timer);
  155. }
  156. ctx.arc(110, 110, 70, -Math.PI / 2, current, false);
  157. ctx.stroke();
  158. ctx.draw();
  159. }, 20);
  160. },
  161. drawLine() {
  162. var context = uni.createCanvasContext("cpline", this);
  163. var r = 70;
  164. var x0 = 110;
  165. var y0 = 110;
  166. var x;
  167. var y;
  168. var lineWidth = 12;
  169. for (let i = 0; i < 60; i++) {
  170. context.beginPath();
  171. context.setLineWidth(lineWidth);
  172. context.setStrokeStyle("#FFFFFF");
  173. x = x0 - r * Math.sin(((6 * (i + 1) - 3) * Math.PI) / 180);
  174. y = y0 - r * Math.cos(((6 * (i + 1) - 3) * Math.PI) / 180);
  175. // console.log('x0:' + x0 + ' y0:' + y0 + ' x:' + x + ' y:' + y);
  176. context.moveTo(x, y);
  177. context.arc(
  178. x0,
  179. y0,
  180. r,
  181. ((270 - 6 * (i + 1) + 3) * Math.PI) / 180,
  182. ((270 - 6 * i) * Math.PI) / 180,
  183. false
  184. );
  185. context.stroke();
  186. context.closePath();
  187. }
  188. context.stroke();
  189. context.draw();
  190. }
  191. }
  192. }
  193. </script>
  194. <style lang="scss" scoped>
  195. .progress_box {
  196. position: relative;
  197. width: 400rpx;
  198. height: 400rpx;
  199. display: flex;
  200. margin: 0 auto;
  201. align-items: center;
  202. justify-content: center;
  203. text-align: center;
  204. }
  205. .progress_bg {
  206. position: absolute;
  207. width: 220px;
  208. height: 220px;
  209. }
  210. .progress_bar {
  211. position: absolute;
  212. width: 220px;
  213. height: 220px;
  214. }
  215. .progress_line {
  216. position: absolute;
  217. width: 220px;
  218. height: 220px;
  219. }
  220. .progress_txt {
  221. position: absolute;
  222. font-size: 28upx;
  223. color: #999999;
  224. }
  225. .progress_info {
  226. font-size: 36upx;
  227. padding-left: 16upx;
  228. letter-spacing: 2upx;
  229. font-size: 52upx;
  230. color: #333333;
  231. }
  232. .progress_dot {
  233. width: 16upx;
  234. height: 16upx;
  235. border-radius: 50%;
  236. background-color: #fb9126;
  237. }
  238. .battery-info {
  239. display: flex;
  240. justify-content: space-between;
  241. padding: 0 80rpx;
  242. text-align: center;
  243. line-height: 36rpx;
  244. view>view:first-child {
  245. font-weight: bold;
  246. }
  247. view>view:last-child {
  248. color: #939da7;
  249. font-size: 26rpx;
  250. }
  251. }
  252. .carinfo {
  253. padding-left: 45rpx;
  254. width: 100%;
  255. box-sizing: border-box;
  256. margin-top: 90rpx;
  257. .battery-list {
  258. display: flex;
  259. width: 100%;
  260. margin-top: 36rpx;
  261. .icon {
  262. width: 55rpx;
  263. padding-top: 5rpx;
  264. image {
  265. width: 32rpx;
  266. height: 32rpx;
  267. }
  268. }
  269. .info {
  270. display: flex;
  271. flex: 1;
  272. border-bottom: #e5e5e5 solid 1px;
  273. justify-content: space-between;
  274. font-size: 28rpx;
  275. padding-bottom: 36rpx;
  276. padding-right: 40rpx;
  277. box-sizing: border-box;
  278. .word {
  279. color: #86909c;
  280. }
  281. .number {
  282. color: #333333;
  283. font-weight: bold;
  284. }
  285. }
  286. }
  287. }
  288. .submit {
  289. width: 600rpx;
  290. height: 88rpx;
  291. margin: 35rpx auto;
  292. font-size: 36rpx;
  293. background-color: #58be6b;
  294. color: #fff;
  295. border-radius: 44rpx;
  296. }
  297. </style>