UMessage.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510
  1. <template>
  2. <view>
  3. <u-popup v-model="showUMessage" mode="bottom" border-radius="14" :closeable="true">
  4. <view>
  5. <view class="UMessage">
  6. <view class="q1">系统通知</view>
  7. <view class="q2 margin">尊敬的优电用户,当前站点采用动态调能技术检测到区域用电负荷较高(实时负载率{{loadRate}}%)<br /> 系统已为您智能匹配以下选项:
  8. </view>
  9. <view class="q3card q3card0 margin" @click="payValue=0" :class="{
  10. cardselect:payValue==0,
  11. cardno:payValue!=0
  12. }">
  13. <view class="cardgo">
  14. <view class="cardinfo">
  15. <img src="@/assets/img/riFill-check-fill.svg" alt="">
  16. </view>
  17. </view>
  18. <view class="title"> 前往附近站点 享受即时充电</view>
  19. <view class="q4" v-show="payValue==0" v-if="searchNearStationData.station">
  20. <view class="q41">最近<span class="q4span">{{searchNearStationData.station.name}}</span>
  21. </view>
  22. <view class="q41">距离 <span class="q4span" style="margin-right: 32rpx;">1.2km</span> 空闲桩
  23. <span class="q4span">{{searchNearStationData.availableDeviceNum}}个</span>
  24. </view>
  25. </view>
  26. </view>
  27. <view class="q3card q3card1 margin" @click="payValue=1,loadPredictionCurve()" :class="{
  28. cardselect:payValue==1,
  29. cardno:payValue!=1
  30. }">
  31. <view class="cardgo">
  32. <view class="cardinfo">
  33. <img src="@/assets/img/riFill-check-fill.svg" alt="">
  34. </view>
  35. </view>
  36. <view class="title">预约<span v-show="payValue==1&&payTime"
  37. style="color:#00B962;margin: 0 12rpx;">{{payTime}}</span>充电</view>
  38. <view class="q4" style="margin: 12rpx 0;" v-if="payValue==1&&payTime">
  39. 享 <span style="color: rgba(51, 51, 51, 1);font-weight: bold;margin: 0 8rpx;">{{price}}元/度</span> 充电优惠
  40. </view>
  41. <view class="q4">
  42. 点击查看[负荷预测曲线],了解最佳充电时段。
  43. </view>
  44. <view class="q4" v-show="payValue==1">
  45. <view id="UMessage_pieEcharts">
  46. </view>
  47. </view>
  48. </view>
  49. <view class="q5">再次感谢您对我们的信任,期待您的下次光临!</view>
  50. </view>
  51. <view class="q6">
  52. <view class="q6n1 q6n" @click="bHide">取消充电</view>
  53. <view class=" q6n q6n2" v-if="payValue==0" @click="toSearchPile">查找附近站点 </view>
  54. <view class=" q6n q6n3" v-if="payValue==1&&personInfo.userType==1" @click="toLogin">登录后可预约充电</view>
  55. <view class=" q6n q6n3" v-else-if="payValue==1&&!payValue1bl">{{payTime?'当前时间不可预约':'点击曲线预约充电'}}
  56. </view>
  57. <view class=" q6n q6n2" v-else-if="payValue==1&&payValue1bl" @click="confirmBtn">立即预约</view>
  58. </view>
  59. </view>
  60. </u-popup>
  61. </view>
  62. </template>
  63. <script>
  64. import * as API from '@/apis/umessage.js'
  65. import * as echarts from "echarts";
  66. export default {
  67. name: "UMessage",
  68. props: {
  69. stationId: "",
  70. deviceNo: "",
  71. channelNo: ""
  72. },
  73. data() {
  74. return {
  75. groupId: "8bc25585-4e5b-4895-a94e-431a23a095df",
  76. showUMessage: false,
  77. payValue: 0,
  78. payValue1bl: false, //预约的时间是否合格
  79. payTime: "",
  80. loadRate: 0,
  81. ampereList: [],
  82. myChart: null,
  83. maxAmpere: 0,
  84. personInfo: {},
  85. price:"",
  86. searchNearStationData: {},
  87. cache: null,
  88. };
  89. },
  90. methods: {
  91. bShow() {
  92. this.payValue = 0
  93. this.payTime = ""
  94. this.myChart = null
  95. this.price='';
  96. this.payValue1bl = false;
  97. this.showUMessage = true;
  98. this.findChargingGroup()
  99. },
  100. toHTML(data,params){
  101. this.price=data.data.price;
  102. var result = params[0].name + '<br>';
  103. result += `${params[0].marker} ${params[0].seriesName}: ${params[0].value} A<br>`;
  104. result += `${params[0].marker} 电价: ${data.data.price} 元/度<br>`;
  105. return result
  106. },
  107. bHide() {
  108. this.showUMessage = false;
  109. },
  110. toLogin() {
  111. uni.navigateTo({
  112. url: '/pages/login/login'
  113. })
  114. },
  115. toSearchPile() {
  116. uni.navigateTo({
  117. url: '/pages/searchPile/searchPile'
  118. })
  119. },
  120. initLine() {
  121. if (!this.myChart) {
  122. this.myChart = echarts.init(document.getElementById('UMessage_pieEcharts'), null, {
  123. height: uni.upx2px(300)
  124. });
  125. }
  126. //this.myChart.clear()
  127. var _this = this
  128. var data1 = []
  129. var data2 = []
  130. var pieces=[]
  131. var gt=0
  132. var keyswitch=0//
  133. for (var i in this.ampereList) {
  134. var item = this.ampereList[i]
  135. var key = item.createTime.split(' ')[1]
  136. key = key.substring(0, 5)
  137. data1.push(key)
  138. data2.push(item.ampere)
  139. if(i==0){
  140. if(item.ampere>this.maxAmpere){
  141. keyswitch=1;
  142. }
  143. }
  144. // console.log(keyswitch==0&&item.ampere>this.maxAmpere)
  145. // console.log(item.ampere,this.maxAmpere)
  146. if(keyswitch==0&&item.ampere>this.maxAmpere){
  147. pieces.push({
  148. gt: parseInt(gt),
  149. lte:parseInt(i-1),
  150. color: 'green'
  151. })
  152. gt=i-1
  153. keyswitch=1
  154. }else if(keyswitch==1&&item.ampere<this.maxAmpere){
  155. pieces.push({
  156. gt: parseInt(gt),
  157. lte:parseInt(i-1),
  158. color: 'red'
  159. })
  160. gt=i-1
  161. keyswitch=0
  162. }
  163. }
  164. pieces.push({
  165. gt: parseInt(gt),
  166. lte:parseInt(this.ampereList.length),
  167. color: keyswitch?'red':'green'
  168. })
  169. var option = {
  170. xAxis: {
  171. type: 'category',
  172. data: data1
  173. },
  174. yAxis: {
  175. type: 'value'
  176. },
  177. grid: {
  178. top: '25px',
  179. left: '30px',
  180. right: '20px',
  181. bottom: '25px',
  182. // containLabel: true
  183. },
  184. tooltip: {
  185. trigger: 'axis',
  186. formatter: function(params, ticket, callback) {
  187. _this.payTime=params[0].name ;
  188. if( params[0].data>_this.maxAmpere){
  189. _this.payValue1bl=false;
  190. }else{
  191. _this.payValue1bl=true;
  192. }
  193. API.timePointPrice({
  194. deviceNo: _this.deviceNo,
  195. timePoint: params[0].name
  196. }).then((res) => {
  197. callback(ticket, _this.toHTML(res,params));
  198. }).catch(error => {
  199. })
  200. return '加载中...';
  201. }
  202. },
  203. visualMap: {
  204. show: false,
  205. dimension: 0,
  206. pieces: pieces
  207. },
  208. series: [{
  209. data: data2,
  210. type: 'line',
  211. name: '电流',
  212. markLine: {
  213. data: [{
  214. name: '参考线',
  215. yAxis: this.maxAmpere, // 参考线的值
  216. lineStyle: {
  217. color: 'red',
  218. type: 'dashed'
  219. }
  220. }]
  221. }
  222. }],
  223. };
  224. console.log(option)
  225. this.myChart.setOption(option);
  226. },
  227. readyToTimingCharging() {
  228. uni.showLoading({
  229. title: "加载中",
  230. mask: true,
  231. })
  232. var submitForm = {
  233. deviceNo: this.deviceNo,
  234. channelNo: this.channelNo,
  235. startTime: this.payTime
  236. }
  237. API.readyToTimingCharging(submitForm).then((res) => {
  238. uni.hideLoading();
  239. this.showUMessage = false
  240. uni.showModal({
  241. title: '预约成功',
  242. showCancel: false,
  243. content: "预约成功,拔枪将会自动取消预约"
  244. })
  245. }).catch(error => {
  246. uni.showToast({
  247. title: error,
  248. icon: "none"
  249. })
  250. })
  251. },
  252. loadPredictionCurve() {
  253. if (this.myChart) {
  254. return
  255. }
  256. uni.showLoading({
  257. title: "加载中",
  258. mask: true,
  259. })
  260. API.loadPredictionCurve({
  261. deviceNo: this.deviceNo
  262. }).then((res) => {
  263. uni.hideLoading();
  264. console.log(res)
  265. this.ampereList = res.data.ampereList
  266. this.maxAmpere = res.data.maxAmpere
  267. this.initLine()
  268. }).catch(error => {
  269. uni.showToast({
  270. title: error,
  271. icon: "none"
  272. })
  273. })
  274. },
  275. confirmBtn() {
  276. this.readyToTimingCharging()
  277. },
  278. fetchAdditionalValue() {
  279. },
  280. searchNearStation() {
  281. uni.showLoading({
  282. title: "加载中",
  283. mask: true,
  284. })
  285. API.searchNearStation({
  286. stationId: this.stationId
  287. }).then((res) => {
  288. uni.hideLoading();
  289. console.log(res)
  290. this.searchNearStationData = res.data;
  291. }).catch(error => {
  292. uni.showToast({
  293. title: error,
  294. icon: "none"
  295. })
  296. })
  297. },
  298. findChargingGroup() {
  299. uni.showLoading({
  300. title: "加载中",
  301. mask: true,
  302. })
  303. API.findChargingGroup({
  304. deviceNo: this.deviceNo
  305. }).then((res) => {
  306. uni.hideLoading();
  307. console.log(res)
  308. this.loadRate = res.data.loadRate
  309. this.searchNearStation()
  310. }).catch(error => {
  311. uni.showToast({
  312. title: error,
  313. icon: "none"
  314. })
  315. })
  316. },
  317. },
  318. mounted() {
  319. this.personInfo = this.carhelp.getPersonInfo()
  320. this.cache = new Map()
  321. //this.searchNearStation()
  322. //this.loadPredictionCurve()
  323. }
  324. }
  325. </script>
  326. <style scoped lang="scss">
  327. .q6 {
  328. border: 1px solid rgba(242, 242, 242, 1);
  329. padding: 24rpx;
  330. display: flex;
  331. justify-content: space-around;
  332. .q6n {
  333. padding: 20rpx 0;
  334. border-radius: 50px;
  335. font-size: 34rpx;
  336. text-align: center;
  337. }
  338. .q6n1 {
  339. width: 30%;
  340. background-color: rgba(187, 187, 187, 1);
  341. color: rgba(255, 255, 255, 1);
  342. }
  343. .q6n2 {
  344. background-color: rgba(0, 185, 98, 1);
  345. color: rgba(255, 255, 255, 1);
  346. width: 60%;
  347. }
  348. .q6n3 {
  349. width: 60%;
  350. background-color: rgba(187, 187, 187, 1);
  351. color: rgba(255, 255, 255, 1);
  352. }
  353. }
  354. .UMessage {
  355. padding: 30rpx 40rpx;
  356. .q1 {
  357. color: rgba(16, 16, 16, 1);
  358. font-size: 40rpx;
  359. font-weight: bold;
  360. }
  361. .margin {
  362. margin: 20rpx 0;
  363. }
  364. .q2 {
  365. color: rgba(51, 51, 51, 1);
  366. font-size: 32rpx;
  367. }
  368. .q5 {
  369. color: rgba(119, 119, 119, 1);
  370. font-size: 28rpx;
  371. //margin-bottom: 40rpx;
  372. }
  373. .q4 {
  374. color: rgba(119, 119, 119, 1);
  375. font-size: 28rpx;
  376. .q4span {
  377. color: rgba(51, 51, 51, 1);
  378. margin: 0 8rpx;
  379. font-weight: bold;
  380. }
  381. .q41 {
  382. margin: 8rpx;
  383. }
  384. }
  385. .q3card {
  386. overflow: hidden;
  387. padding: 30rpx 40rpx;
  388. margin-top: 10px;
  389. .title {
  390. font-size: 40rpx;
  391. font-weight: bold;
  392. }
  393. }
  394. .cardselect {
  395. border-radius: 8px;
  396. border: 2px solid rgba(0, 185, 98, 1);
  397. .cardgo {
  398. position: relative;
  399. .cardinfo {
  400. background-color: #00b962;
  401. width: 64rpx;
  402. height: 64rpx;
  403. position: absolute;
  404. top: -44rpx;
  405. right: -44rpx;
  406. border-radius: 0 0 0 8px;
  407. img {
  408. width: 64rpx;
  409. }
  410. }
  411. }
  412. }
  413. .cardno {
  414. border: 2px solid rgba(204, 204, 204, 1);
  415. border-radius: 8px;
  416. .cardgo {
  417. position: relative;
  418. .cardinfo {
  419. background-color: rgba(204, 204, 204, 1);
  420. width: 64rpx;
  421. height: 64rpx;
  422. position: absolute;
  423. top: -44rpx;
  424. right: -44rpx;
  425. border-radius: 0 0 0 8px;
  426. img {
  427. width: 64rpx;
  428. }
  429. }
  430. }
  431. }
  432. }
  433. </style>