scan-info.vue 8.7 KB

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