UMessage.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520
  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:this.maxAmpere==0?{}: {
  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. var gunNo=res.data.gunNo
  241. uni.showModal({
  242. title: '预约成功',
  243. showCancel: false,
  244. content: "预约成功,拔枪将会自动取消预约",
  245. success: res1 => {
  246. if (res1.confirm) {
  247. uni.navigateTo({
  248. url:"/pages/searchPile/stationAndPile/chargingPileDetails?isback=1&id="+gunNo
  249. })
  250. } else if (res1.cancel) {
  251. //('用户点击取消');
  252. }
  253. }
  254. })
  255. }).catch(error => {
  256. uni.showToast({
  257. title: error,
  258. icon: "none"
  259. })
  260. })
  261. },
  262. loadPredictionCurve() {
  263. if (this.myChart) {
  264. return
  265. }
  266. uni.showLoading({
  267. title: "加载中",
  268. mask: true,
  269. })
  270. API.loadPredictionCurve({
  271. deviceNo: this.deviceNo
  272. }).then((res) => {
  273. uni.hideLoading();
  274. console.log(res)
  275. this.ampereList = res.data.ampereList
  276. this.maxAmpere = res.data.maxAmpere
  277. this.initLine()
  278. }).catch(error => {
  279. uni.showToast({
  280. title: error,
  281. icon: "none"
  282. })
  283. })
  284. },
  285. confirmBtn() {
  286. this.readyToTimingCharging()
  287. },
  288. fetchAdditionalValue() {
  289. },
  290. searchNearStation() {
  291. uni.showLoading({
  292. title: "加载中",
  293. mask: true,
  294. })
  295. API.searchNearStation({
  296. stationId: this.stationId
  297. }).then((res) => {
  298. uni.hideLoading();
  299. console.log(res)
  300. this.searchNearStationData = res.data;
  301. }).catch(error => {
  302. uni.showToast({
  303. title: error,
  304. icon: "none"
  305. })
  306. })
  307. },
  308. findChargingGroup() {
  309. uni.showLoading({
  310. title: "加载中",
  311. mask: true,
  312. })
  313. API.findChargingGroup({
  314. deviceNo: this.deviceNo
  315. }).then((res) => {
  316. uni.hideLoading();
  317. console.log(res)
  318. this.loadRate = res.data.loadRate
  319. this.searchNearStation()
  320. }).catch(error => {
  321. uni.showToast({
  322. title: error,
  323. icon: "none"
  324. })
  325. })
  326. },
  327. },
  328. mounted() {
  329. this.personInfo = this.carhelp.getPersonInfo()
  330. this.cache = new Map()
  331. //this.searchNearStation()
  332. //this.loadPredictionCurve()
  333. }
  334. }
  335. </script>
  336. <style scoped lang="scss">
  337. .q6 {
  338. border: 1px solid rgba(242, 242, 242, 1);
  339. padding: 24rpx;
  340. display: flex;
  341. justify-content: space-around;
  342. .q6n {
  343. padding: 20rpx 0;
  344. border-radius: 50px;
  345. font-size: 34rpx;
  346. text-align: center;
  347. }
  348. .q6n1 {
  349. width: 30%;
  350. background-color: rgba(187, 187, 187, 1);
  351. color: rgba(255, 255, 255, 1);
  352. }
  353. .q6n2 {
  354. background-color: rgba(0, 185, 98, 1);
  355. color: rgba(255, 255, 255, 1);
  356. width: 60%;
  357. }
  358. .q6n3 {
  359. width: 60%;
  360. background-color: rgba(187, 187, 187, 1);
  361. color: rgba(255, 255, 255, 1);
  362. }
  363. }
  364. .UMessage {
  365. padding: 30rpx 40rpx;
  366. .q1 {
  367. color: rgba(16, 16, 16, 1);
  368. font-size: 40rpx;
  369. font-weight: bold;
  370. }
  371. .margin {
  372. margin: 20rpx 0;
  373. }
  374. .q2 {
  375. color: rgba(51, 51, 51, 1);
  376. font-size: 32rpx;
  377. }
  378. .q5 {
  379. color: rgba(119, 119, 119, 1);
  380. font-size: 28rpx;
  381. //margin-bottom: 40rpx;
  382. }
  383. .q4 {
  384. color: rgba(119, 119, 119, 1);
  385. font-size: 28rpx;
  386. .q4span {
  387. color: rgba(51, 51, 51, 1);
  388. margin: 0 8rpx;
  389. font-weight: bold;
  390. }
  391. .q41 {
  392. margin: 8rpx;
  393. }
  394. }
  395. .q3card {
  396. overflow: hidden;
  397. padding: 30rpx 40rpx;
  398. margin-top: 10px;
  399. .title {
  400. font-size: 40rpx;
  401. font-weight: bold;
  402. }
  403. }
  404. .cardselect {
  405. border-radius: 8px;
  406. border: 2px solid rgba(0, 185, 98, 1);
  407. .cardgo {
  408. position: relative;
  409. .cardinfo {
  410. background-color: #00b962;
  411. width: 64rpx;
  412. height: 64rpx;
  413. position: absolute;
  414. top: -44rpx;
  415. right: -44rpx;
  416. border-radius: 0 0 0 8px;
  417. img {
  418. width: 64rpx;
  419. }
  420. }
  421. }
  422. }
  423. .cardno {
  424. border: 2px solid rgba(204, 204, 204, 1);
  425. border-radius: 8px;
  426. .cardgo {
  427. position: relative;
  428. .cardinfo {
  429. background-color: rgba(204, 204, 204, 1);
  430. width: 64rpx;
  431. height: 64rpx;
  432. position: absolute;
  433. top: -44rpx;
  434. right: -44rpx;
  435. border-radius: 0 0 0 8px;
  436. img {
  437. width: 64rpx;
  438. }
  439. }
  440. }
  441. }
  442. }
  443. </style>