index.vue 11 KB

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