index.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506
  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. }else{
  194. uni.showToast({
  195. title:'链接超时,请重新扫码'
  196. })
  197. return
  198. }
  199. API.chargingData(data).then((res) => {
  200. this.detail = res.data.chargingDevice;
  201. if(!this.detail .online){
  202. uni.showToast({
  203. title:'设备不在线,请扫描其他二维码'
  204. })
  205. return
  206. }
  207. this.carhelp.set("qr-default-id",this.id);
  208. this.user = res.data.userAccount;
  209. this.list=this.detail.chargeStatusArray
  210. this.isReady=true;
  211. uni.hideLoading()
  212. }).catch(error => {
  213. this.isReady=true;
  214. uni.showToast({
  215. title: error
  216. })
  217. })
  218. },
  219. selectItem(row){
  220. if(row.status==0){
  221. this.submitForm.channelNo=row.channelNo
  222. }else{
  223. uni.showToast({
  224. title:'当前设备不可选'
  225. })
  226. }
  227. },
  228. confirm(){
  229. uni.showLoading({
  230. title: "加载中",
  231. mask: true,
  232. })
  233. this.submitForm.deviceNo=this.detail.deviceNo;
  234. API.startCharging(this.submitForm).then((res) => {
  235. this.gotoUrl("pages/index/index");
  236. // uni.showModal({
  237. // title: '提示',
  238. // showCancel:false,
  239. // content: '启动成功',
  240. // success: res=> {
  241. // if (res.confirm) {
  242. // //付钱 改为组件
  243. // this.gotoUrl("pages/index/index");
  244. // } else if (res.cancel) {
  245. // console.log('用户点击取消');
  246. // }
  247. // }
  248. // });
  249. // uni.showToast({
  250. // title: '启动中..'
  251. // })
  252. // setTimeout(()=>{
  253. // },3000)
  254. // uni.hideLoading()
  255. }).catch(error => {
  256. if(error=='用户账户余额不足!'){
  257. uni.showModal({
  258. title: '支付',
  259. content: '用户账户余额不足,是否充值?',
  260. success: res=> {
  261. if (res.confirm) {
  262. //付钱 改为组件
  263. this.gotoUrl("pages/user/recharge");
  264. } else if (res.cancel) {
  265. console.log('用户点击取消');
  266. }
  267. }
  268. });
  269. }else{
  270. uni.showToast({
  271. title: error
  272. })
  273. }
  274. })
  275. },
  276. submit(){
  277. if(!this.submitForm.channelNo){
  278. uni.showToast({
  279. title:'请先选择充电通道'
  280. })
  281. return
  282. }
  283. var obj=this.list.find(item=>{
  284. return item.channelNo==this.submitForm.channelNo
  285. })
  286. if(!obj||obj.status!=0){
  287. uni.showToast({
  288. title:'当前设备不可选'
  289. })
  290. return
  291. }
  292. if(this.submitForm.hour==0&&this.user.accountBalance<5){
  293. uni.showModal({
  294. title: '支付',
  295. content: '余额不足5元无法开启充满自停,是否充值?',
  296. success: res=> {
  297. if (res.confirm) {
  298. //付钱 改为组件
  299. this.gotoUrl("pages/user/recharge");
  300. } else if (res.cancel) {
  301. console.log('用户点击取消');
  302. }
  303. }
  304. });
  305. }else{
  306. this.showmodel=true;
  307. }
  308. },
  309. showTips(){
  310. this.showPriceList=true
  311. }
  312. },onShow() {
  313. if(this.isReady){
  314. if (this.id) {
  315. this.carhelp.set("qr-default-id",this.id);
  316. }else{
  317. //用于支付后返回系统 -- 点金计划
  318. this.id =this.carhelp.get("qr-default-id");
  319. }
  320. this.init()
  321. }
  322. }
  323. }
  324. </script>
  325. <style>
  326. page{
  327. background-color: #f7f7f7;
  328. }
  329. </style>
  330. <style lang="scss" scoped>
  331. .showmodel{
  332. margin-left: 20px;
  333. margin-right: 20px;
  334. p{
  335. display: inline-block;
  336. width: 100px;
  337. }
  338. }
  339. .showPriceList{
  340. margin-left: 20px;
  341. margin-right: 20px;
  342. span{
  343. float: right;
  344. }
  345. }
  346. .slot-wrap {
  347. display: flex;
  348. align-items: center;
  349. justify-content: space-between;
  350. flex: 1;
  351. }
  352. .navbar-right {
  353. display: flex;
  354. margin-right: 20rpx;
  355. align-items: center;
  356. }
  357. .charge{
  358. padding: 15px;
  359. background-color: #fff;
  360. margin-bottom: 10px;
  361. }
  362. .chargeRadio{
  363. display: flex;
  364. justify-content: space-between;
  365. align-items: center;
  366. width: 100%;
  367. .chargeRadio-text{
  368. margin-left: 5px;
  369. }
  370. }
  371. .chargeTime{
  372. display: flex;
  373. overflow: scroll;
  374. padding-bottom: 15px;
  375. .chargeTime-item{
  376. border: 1px solid #1677ff;
  377. border-radius: 50%;
  378. min-width: 56px;
  379. height: 56px;
  380. text-align: center;
  381. line-height: 56px;
  382. margin-right: 20px;
  383. }
  384. .chargeTime-first{
  385. line-height: 20px !important;
  386. padding-top: 6px;
  387. margin-right: 20px;
  388. }
  389. .chargeTime-active{
  390. color:#fff;
  391. background-color: #1677ff;
  392. }
  393. }
  394. .chargeTime-text{
  395. border-top: 1px solid #f7f7f7;
  396. padding-top: 15px;
  397. display: flex;
  398. align-items: center;
  399. span{
  400. margin-left: 20px;
  401. color:#1677ff;
  402. }
  403. }
  404. .chargeInfo{
  405. .chargeInfo-row{
  406. display: flex;
  407. align-items: center;
  408. justify-content: space-between;
  409. margin-bottom: 10px;
  410. p{
  411. color:#999;
  412. }
  413. h4{
  414. font-weight: normal;
  415. }
  416. span{
  417. color:#1677ff;
  418. margin-right: 5px;
  419. }
  420. }
  421. }
  422. .chargeMain{
  423. display: flex;
  424. flex-wrap: wrap;
  425. justify-content: space-between;
  426. margin-top: 20px;
  427. .chargeMain-item{
  428. width: 18%;
  429. text-align: center;
  430. padding: 10px;
  431. border: 1px solid #1677ff;
  432. margin-bottom: 10px;
  433. border-radius: 10px;
  434. color:#1677ff;
  435. }
  436. .active{
  437. background-color:#1677ff;
  438. color:#fff;
  439. }
  440. .fault{
  441. background-color:#e1e1e1;
  442. color:#666;
  443. border: 1px solid #ccc;
  444. }
  445. .occupy{
  446. color:#FF4F3F;
  447. border: 1px solid #FF4F3F;
  448. }
  449. }
  450. .foot-btn{
  451. padding: 10px;
  452. position: fixed;
  453. left: 0;
  454. right: 0;
  455. bottom: 0;
  456. background-color: #fff;
  457. }
  458. </style>