index.vue 10 KB

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