index.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517
  1. <template>
  2. <view>
  3. <u-navbar title="充电">
  4. <view class="slot-wrap">
  5. <view class="navbar-left"></view>
  6. <!-- <view class="navbar-right"><u-icon name="iconfontscan" custom-prefix="custom-icon" color="#1677ff" size="40"></u-icon></view>
  7. --> </view>
  8. </u-navbar>
  9. <view class="charge">
  10. <view class="chargeInfo">
  11. <view class="chargeInfo-row">
  12. <view class="u-flex"><p>站点:</p><h4>{{detail.stationName}}</h4></view>
  13. </view>
  14. <view class="chargeInfo-row">
  15. <view class="u-flex"><p>桩号:</p><h4>{{detail.deviceNo}}</h4></view>
  16. <view class="u-flex" @click="switchCharge">
  17. <span>切换充电桩</span>
  18. <u-icon name="arrow-right" color="#999" size="24"></u-icon>
  19. </view>
  20. </view>
  21. <view class="chargeInfo-row">
  22. <view class="u-flex"><p>桩名:</p><h4>{{detail.name}}</h4></view>
  23. <view class="u-flex" @click="showTips()">
  24. <span>费用说明</span>
  25. <u-icon name="error-circle" color="#1677ff" size="32" ></u-icon>
  26. </view>
  27. </view>
  28. </view>
  29. <view class="chargeMain">
  30. <template v-for="(item,i) in list">
  31. <view :key="i" class="chargeMain-item "
  32. @click="selectItem(item)"
  33. :class="{
  34. 'active':item.channelNo==submitForm.channelNo,
  35. 'occupy':item.status==1,
  36. 'fault':item.status==2,
  37. }"
  38. ><p>{{i+1}}</p>
  39. <p >{{item.statusStr}}</p>
  40. </view>
  41. </template>
  42. <h2 v-if="isReady&&list.length==0">无可用通道<br/>请联系客服人员</h2>
  43. </view>
  44. </view>
  45. <view class="charge">
  46. <view class="chargeTime">
  47. <view v-for="(item,i) in timelist"
  48. class="chargeTime-item " :key="i"
  49. @click="submitForm.hour=item.id"
  50. :class="{
  51. 'chargeTime-active':submitForm.hour==item.id,
  52. 'chargeTime-first':i==0
  53. }"
  54. >
  55. <template v-if="i==0">
  56. <p>充满</p><p>自停</p>
  57. </template>
  58. <template v-else>
  59. {{item.name}}
  60. </template>
  61. </view>
  62. </view>
  63. <view class="chargeTime-text">
  64. <p>充电时长</p>
  65. <span>{{timelist[submitForm.hour].name}}</span>
  66. </view>
  67. </view>
  68. <view style="padding-bottom: 100px;">
  69. <view class="charge">
  70. <view class="chargeRadio">
  71. <view class="u-flex">
  72. <u-icon name="rmb-circle-fill" color="#ff9502" size="90"></u-icon>
  73. <view class="chargeRadio-text">
  74. <p>余额支付</p>
  75. <p>现有余额¥{{user.availableBalance}} </p>
  76. </view>
  77. </view>
  78. <u-button type="warning" style=" height: 34px;"
  79. @click='gotoUrl("pages/user/recharge")'
  80. >我要充值</u-button>
  81. </view>
  82. </view>
  83. </view>
  84. <view class="foot-btn">
  85. <u-button type="primary" :custom-style="customStyle"
  86. @click="submit"
  87. shape="square">开始充电</u-button>
  88. </view>
  89. <u-modal v-model="showPriceList" title="费用说明" >
  90. <p v-for="(item,i) in detail.priceList" class="showPriceList" :key="i">{{item.minPower}}W-{{item.maxPower}}W <span>{{item.price}}元每小时</span></p>
  91. <p style=" padding: 15px;" v-if="detail.roundingMinute!=null&&detail.roundingMinute!=-1">超过{{detail.roundingMinute}}分钟,按1小时记,不足{{detail.roundingMinute}}分钟,不计费</p>
  92. <p style=" padding: 15px;" v-if="detail.priceList.length==0">无费用说明或为免费充电模式</p>
  93. </u-modal>
  94. <u-modal v-model="showmodel" @confirm="confirm" :showCancelButton="true" title="订单信息" >
  95. <div class="showmodel" ><p >桩号</p>{{detail.deviceNo}}</div>
  96. <div class="showmodel" ><p >充电通道</p>{{submitForm.channelNo}}</div>
  97. <div class="showmodel" ><p >支付方式</p>余额支付</div>
  98. <div class="showmodel" ><p >充电时间</p>{{timelist[submitForm.hour].name}}</div>
  99. <p class="showmodel" style="color: red;" v-if="submitForm.hour==0" >充满自停模式,设备充满后会自动停止计费,剩余费用会原路返还</p>
  100. </u-modal>
  101. </view>
  102. </template>
  103. <script>
  104. import * as API from '@/apis/index.js'
  105. export default {
  106. data() {
  107. return {
  108. id:"",
  109. showPriceList:false,
  110. showmodel:false,
  111. //充电桩信息
  112. detail:{
  113. roundingMinute:-1,
  114. priceList:[],
  115. },
  116. user:{},
  117. //充电位子list
  118. list:[
  119. ],
  120. timelist:[
  121. {
  122. id:'0',
  123. name:'充满自停'
  124. },
  125. {
  126. id:'1',
  127. name:'1小时'
  128. },
  129. {
  130. id:'2',
  131. name:'2小时'
  132. },
  133. {
  134. id:'3',
  135. name:'3小时'
  136. },
  137. {
  138. id:'4',
  139. name:'4小时'
  140. },
  141. {
  142. id:'5',
  143. name:'5小时'
  144. },
  145. {
  146. id:'6',
  147. name:'6小时'
  148. },
  149. {
  150. id:'7',
  151. name:'7小时'
  152. },
  153. {
  154. id:'8',
  155. name:'8小时'
  156. },
  157. ],
  158. //提交信息
  159. submitForm:{
  160. deviceNo:'',
  161. channelNo:'',
  162. hour:'0',
  163. //paytype:'YE',
  164. },
  165. isReady:false,
  166. customStyle: {
  167. background: '#1677ff'
  168. }
  169. }
  170. },
  171. onLoad(op) {
  172. if (op.id) {
  173. this.id = op.id;
  174. this.carhelp.set("qr-default-id",op.id);
  175. }else{
  176. //用于支付后返回系统 -- 点金计划
  177. var id=this.carhelp.get("qr-default-id")
  178. if(id){
  179. this.id =this.carhelp.get("qr-default-id");
  180. }
  181. }
  182. this.init()
  183. },
  184. methods: {
  185. switchCharge(){
  186. var stationId=this.detail.stationId;
  187. console.log("switchCharge")
  188. uni.redirectTo({
  189. url:'/pages/charge/switchCharge?id='+this.id+'&stationId='+stationId
  190. })
  191. },
  192. init(){
  193. if(!this.id){
  194. this.switchCharge()
  195. }else{
  196. uni.showLoading({
  197. title: "加载中",
  198. mask: true,
  199. })
  200. var data = {
  201. };
  202. if(this.id){
  203. data.deviceId=this.id
  204. }
  205. API.chargingData(data).then((res) => {
  206. this.detail = res.data.chargingDevice;
  207. if(!this.detail .online){
  208. uni.showToast({
  209. title:'设备不在线,请扫描其他二维码'
  210. })
  211. return
  212. }
  213. this.carhelp.set("qr-default-id",this.id);
  214. this.user = res.data.userAccount;
  215. this.list=this.detail.chargeStatusArray
  216. this.isReady=true;
  217. uni.hideLoading()
  218. }).catch(error => {
  219. this.isReady=true;
  220. uni.showToast({
  221. title: error
  222. })
  223. })
  224. }
  225. },
  226. selectItem(row){
  227. if(row.status==0){
  228. this.submitForm.channelNo=row.channelNo
  229. }else{
  230. uni.showToast({
  231. title:'当前设备不可选'
  232. })
  233. }
  234. },
  235. confirm(){
  236. uni.showLoading({
  237. title: "加载中",
  238. mask: true,
  239. })
  240. this.submitForm.deviceNo=this.detail.deviceNo;
  241. API.startCharging(this.submitForm).then((res) => {
  242. this.gotoUrl("pages/index/index");
  243. // uni.showModal({
  244. // title: '提示',
  245. // showCancel:false,
  246. // content: '启动成功',
  247. // success: res=> {
  248. // if (res.confirm) {
  249. // //付钱 改为组件
  250. // this.gotoUrl("pages/index/index");
  251. // } else if (res.cancel) {
  252. // console.log('用户点击取消');
  253. // }
  254. // }
  255. // });
  256. // uni.showToast({
  257. // title: '启动中..'
  258. // })
  259. // setTimeout(()=>{
  260. // },3000)
  261. // uni.hideLoading()
  262. }).catch(error => {
  263. if(error=='用户账户余额不足!'){
  264. uni.showModal({
  265. title: '支付',
  266. content: '用户账户余额不足,是否充值?',
  267. success: res=> {
  268. if (res.confirm) {
  269. //付钱 改为组件
  270. this.gotoUrl("pages/user/recharge");
  271. } else if (res.cancel) {
  272. console.log('用户点击取消');
  273. }
  274. }
  275. });
  276. }else{
  277. uni.showToast({
  278. title: error
  279. })
  280. }
  281. })
  282. },
  283. submit(){
  284. if(!this.submitForm.channelNo){
  285. uni.showToast({
  286. title:'请先选择充电通道'
  287. })
  288. return
  289. }
  290. var obj=this.list.find(item=>{
  291. return item.channelNo==this.submitForm.channelNo
  292. })
  293. if(!obj||obj.status!=0){
  294. uni.showToast({
  295. title:'当前设备不可选'
  296. })
  297. return
  298. }
  299. if(this.submitForm.hour==0&&this.user.availableBalance<5){
  300. uni.showModal({
  301. title: '支付',
  302. content: '余额不足5元无法开启充满自停,是否充值?',
  303. success: res=> {
  304. if (res.confirm) {
  305. //付钱 改为组件
  306. this.gotoUrl("pages/user/recharge");
  307. } else if (res.cancel) {
  308. console.log('用户点击取消');
  309. }
  310. }
  311. });
  312. }else{
  313. this.showmodel=true;
  314. }
  315. },
  316. showTips(){
  317. this.showPriceList=true
  318. }
  319. },onShow() {
  320. if(this.isReady){
  321. if (this.id) {
  322. this.carhelp.set("qr-default-id",this.id);
  323. }else{
  324. //用于支付后返回系统 -- 点金计划
  325. this.id =this.carhelp.get("qr-default-id");
  326. }
  327. this.init()
  328. }
  329. }
  330. }
  331. </script>
  332. <style>
  333. page{
  334. background-color: #f7f7f7;
  335. }
  336. </style>
  337. <style lang="scss" scoped>
  338. .showmodel{
  339. margin-left: 20px;
  340. margin-right: 20px;
  341. p{
  342. display: inline-block;
  343. width: 100px;
  344. }
  345. }
  346. .showPriceList{
  347. margin-left: 20px;
  348. margin-right: 20px;
  349. span{
  350. float: right;
  351. }
  352. }
  353. .slot-wrap {
  354. display: flex;
  355. align-items: center;
  356. justify-content: space-between;
  357. flex: 1;
  358. }
  359. .navbar-right {
  360. display: flex;
  361. margin-right: 20rpx;
  362. align-items: center;
  363. }
  364. .charge{
  365. padding: 15px;
  366. background-color: #fff;
  367. margin-bottom: 10px;
  368. }
  369. .chargeRadio{
  370. display: flex;
  371. justify-content: space-between;
  372. align-items: center;
  373. width: 100%;
  374. .chargeRadio-text{
  375. margin-left: 5px;
  376. }
  377. }
  378. .chargeTime{
  379. display: flex;
  380. overflow: scroll;
  381. padding-bottom: 15px;
  382. .chargeTime-item{
  383. border: 1px solid #1677ff;
  384. border-radius: 50%;
  385. min-width: 56px;
  386. height: 56px;
  387. text-align: center;
  388. line-height: 56px;
  389. margin-right: 20px;
  390. }
  391. .chargeTime-first{
  392. line-height: 20px !important;
  393. padding-top: 6px;
  394. margin-right: 20px;
  395. }
  396. .chargeTime-active{
  397. color:#fff;
  398. background-color: #1677ff;
  399. }
  400. }
  401. .chargeTime-text{
  402. border-top: 1px solid #f7f7f7;
  403. padding-top: 15px;
  404. display: flex;
  405. align-items: center;
  406. span{
  407. margin-left: 20px;
  408. color:#1677ff;
  409. }
  410. }
  411. .chargeInfo{
  412. .chargeInfo-row{
  413. display: flex;
  414. align-items: center;
  415. justify-content: space-between;
  416. margin-bottom: 10px;
  417. p{
  418. color:#999;
  419. }
  420. h4{
  421. font-weight: normal;
  422. }
  423. span{
  424. color:#1677ff;
  425. margin-right: 5px;
  426. }
  427. }
  428. }
  429. .chargeMain{
  430. display: flex;
  431. flex-wrap: wrap;
  432. justify-content: space-between;
  433. margin-top: 20px;
  434. .chargeMain-item{
  435. width: 18%;
  436. text-align: center;
  437. padding: 10px;
  438. border: 1px solid #1677ff;
  439. margin-bottom: 10px;
  440. border-radius: 10px;
  441. color:#1677ff;
  442. }
  443. .active{
  444. background-color:#1677ff;
  445. color:#fff;
  446. }
  447. .fault{
  448. background-color:#e1e1e1;
  449. color:#666;
  450. border: 1px solid #ccc;
  451. }
  452. .occupy{
  453. color:#FF4F3F;
  454. border: 1px solid #FF4F3F;
  455. }
  456. }
  457. .foot-btn{
  458. padding: 10px;
  459. position: fixed;
  460. left: 0;
  461. right: 0;
  462. bottom: 0;
  463. background-color: #fff;
  464. }
  465. </style>