charge.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821
  1. <template>
  2. <view>
  3. <ujp-navbar title="充电" :is-back="isback" ></ujp-navbar>
  4. <view class="recharge" >
  5. <view class="title">请选择充电金额
  6. <view class="to-recharge" @click="gotoUrl('pages/user/finance/recharge')">
  7. 去充值
  8. </view>
  9. </view>
  10. <p>当前余额{{user.balance>0?user.balance.toFixed(2):'0.00'}}元</p>
  11. <view class="rechargeMain">
  12. <view class="recharge-item" @click="moneyClick(item.id)"
  13. :class="!otherNum&&moneyActiveClass == item.id ? 'active' : ''" v-for="(item,index) in moneyList"
  14. :key="item.id">
  15. {{item.name}}元
  16. </view>
  17. <view class="recharge-item" :class="otherNum ? 'active' : ''" style="
  18. padding: 8px 0px;">
  19. <u-input v-model="otherNum" @input="ckInput" type="digit" placeholder="其他充值金额" />
  20. </view>
  21. <view style="color: rgba(153, 153, 153, 100);
  22. font-size: 14px;
  23. text-align: left;
  24. font-family: AlibabaPuHui-regular;"><span style="color:red">*</span>充电金额输入范围为1元-500元的整数。实际充电金额与所选金额会略有出入(一般误差约几分钱),最终结算金额将以实际充入电量为准。</view>
  25. </view>
  26. <view class="title">其他充电模式</view>
  27. <view @click="moneyClick(-1)" :class="!otherNum&&moneyActiveClass == -1? 'active' : ''" class="self-stop ">
  28. 充满自停
  29. </view>
  30. <view v-if="false" style="color: rgba(153, 153, 153, 100);
  31. font-size: 14px;
  32. text-align: left;
  33. font-family: AlibabaPuHui-regular;">充满自停将<span style="color:#53b56b">预扣费10元</span>,充电结束后按实际金额结算,多退少补<br/>
  34. </view>
  35. <!-- 优惠券 -->
  36. <view class="discounts" v-if="false" >
  37. <view class="title">
  38. <span class="title-1">
  39. 优惠券
  40. </span>
  41. <span class="title-2">
  42. 每次只能使用1张
  43. </span>
  44. <span class="title-3">
  45. -6.00
  46. </span>
  47. </view>
  48. <view class="select">
  49. <u-radio-group v-model="value" :wrap="true">
  50. <template v-for="(item, index) in list" >
  51. <u-radio @change="radioChange" :key="index" :name="item.id"
  52. :style="item.chooseStatus==0?' background-color: #e3e3e3 !important;':''"
  53. :disabled="item.chooseStatus==0">
  54. 满{{item.threshold.toFixed(2)}}元减{{item.value.toFixed(2)}}元
  55. <view class="explain" @click="gotoUrl('pages/user/coupon/couponDetails?id='+item.id)" :key="index" >使用说明</view>
  56. </u-radio>
  57. </template>
  58. </u-radio-group>
  59. </view>
  60. </view>
  61. <!-- 优惠券2 -->
  62. <view class="discounts2">
  63. <view class="left">
  64. 优惠券
  65. </view>
  66. <view class="right" @click="chooseCoupons" v-if="selectObj.id">
  67. {{selectObj.threshold == 0 ? '无门槛' : '满'+selectObj.threshold.toFixed(2)+'元可用'}},
  68. <span class="price" v-if="selectObj.classify == '1'||selectObj.classify == '3'">抵扣{{selectObj.value.toFixed(2)}}元</span>
  69. <span class="price" v-if="selectObj.classify == '2'">服务费{{selectObj.value}}折</span>
  70. <view class="iconfont">&#xe600;</view>
  71. </view>
  72. <view class="right" @click="chooseCoupons" v-else-if="listlength">
  73. 未选择,剩余{{listlength}}张优惠券
  74. <view class="iconfont">&#xe600;</view>
  75. </view>
  76. <view class="right" @click="chooseCoupons" v-else>
  77. 无优惠券
  78. <view class="iconfont">&#xe600;</view>
  79. </view>
  80. </view>
  81. <view class="couponsuse" ><span style="color:red">*</span>{{couponsuse}}</view>
  82. <!-- 会员活动 -->
  83. <view class="member" v-if="userCardBool" >
  84. <view class="actively">
  85. 会员活动
  86. </view>
  87. <view class="type" v-if="!vin" style="color: red;" >
  88. vin码不一致
  89. </view>
  90. <view class="type" v-else-if="canUse">
  91. 充电服务费包月卡
  92. </view>
  93. <view class="type" style="color: red;" v-else>
  94. 此充电站不支持月卡服务
  95. </view>
  96. </view>
  97. </view>
  98. <view class="bottom">
  99. <view class="botton"
  100. @click="submit"
  101. >开始充电</view>
  102. </view>
  103. <!-- <view class="but-box" style="margin-bottom: 20px;">
  104. <u-button
  105. style=" background-color: rgba(0, 185, 98, 100);
  106. color: rgba(255, 255, 255, 100);
  107. font-size: 16px;
  108. text-align: center;"
  109. @click="submit" shape="circle">开始充电</u-button>
  110. </view> -->
  111. </view>
  112. </template>
  113. <script>
  114. import * as API from '@/apis/chargeProcess.js'
  115. import * as userApi from '@/apis/user.js'
  116. export default {
  117. data() {
  118. return {
  119. stationId:"",
  120. elderMode:false,
  121. isback:true,
  122. moneyActiveClass: "-1",
  123. detail: {},
  124. couponsuse:'',
  125. //提交信息
  126. submitForm: {
  127. deviceNo: '',
  128. channelNo: '',
  129. carNumber: '',
  130. chargeStrategy: 2,
  131. amount: 0
  132. //paytype:'YE',
  133. },
  134. uuid:0,
  135. user: {},
  136. otherNum: '',
  137. moneyList: [
  138. {
  139. id: '5',
  140. name: '5'
  141. },
  142. {
  143. id: '10',
  144. name: '10'
  145. },
  146. {
  147. id: '20',
  148. name: '20'
  149. },
  150. {
  151. id: '50',
  152. name: '50'
  153. },
  154. {
  155. id: '100',
  156. name: '100'
  157. },
  158. ],
  159. userCard:null,
  160. canUse:false,
  161. selectObj:{},
  162. value:"",
  163. // 优惠券
  164. listlength:0,
  165. vin:true,
  166. }
  167. },
  168. computed:{
  169. userCardBool(){
  170. if(this.userCard){
  171. var date=new Date().getTime()
  172. var reg=new RegExp('-','gi')
  173. var str=this.userCard.endTime;
  174. //console.log(str.replace(reg,'/'))
  175. var date2=new Date(str.replace(reg,'/')).getTime();
  176. if(date<date2){
  177. return true;
  178. }
  179. }
  180. return false
  181. }
  182. },
  183. onLoad(op) {
  184. // var plus=this.carhelp.getPersonInfoPlus()
  185. // if(plus){
  186. // this.userCard=plus.userCard;
  187. // }
  188. this.uuid=new Date().getTime();
  189. this.stationId= op.stationId;
  190. if (op.deviceNo) {
  191. this.submitForm.deviceNo = op.deviceNo;
  192. this.submitForm.channelNo = op.gun;
  193. this.submitForm.carNumber = op.carNumber;
  194. this.carhelp.setGunIdCharge(this.submitForm);
  195. }
  196. if(op.vin=='no'){
  197. this.vin=false;
  198. }
  199. if(op.isback){
  200. this.isback=false;
  201. }
  202. this.useCoupon()
  203. var couponsuse=this.carhelp.getConfig().couponsuse
  204. // img="https://yktwechat.xiaoxinda.com/config/xxd2021.jpg"
  205. if(couponsuse){
  206. this.couponsuse=couponsuse
  207. }
  208. },
  209. onReady(){
  210. this.elderMode = this.carhelp.get('getElderModeClass') == '长辈模式';
  211. if(this.elderMode)
  212. this.theme('elder')
  213. else
  214. this.theme('standard')
  215. },
  216. onShow() {
  217. var obj=this.carhelp.get("chooseCoupons");
  218. if(obj){
  219. if(obj.uuid==this.uuid){
  220. this.selectObj=obj.selectObj;
  221. }
  222. }
  223. this.getHomePage()
  224. },
  225. methods: {
  226. getPile(){
  227. },
  228. theme(type) {
  229. if(type == 'elder')
  230. {
  231. document.getElementsByTagName('body')[0].setAttribute('data-theme',type);
  232. }
  233. else
  234. {
  235. document.getElementsByTagName('body')[0].setAttribute('data-theme',type);
  236. }
  237. },
  238. chooseCoupons(){
  239. this.submitInit()
  240. this.gotoUrl('pages/user/coupon/chooseCoupons?uuid='+this.uuid+"&amount="+this.submitForm.amount+"&stationId="+this.stationId)
  241. },
  242. ckInput(text) {
  243. if (text.indexOf('.') > 0) {
  244. this.$nextTick(() => {
  245. this.otherNum = text.substring(0, text.indexOf('.'))
  246. uni.showToast({
  247. title: "请输入正整数"
  248. })
  249. })
  250. }
  251. var t = Number(text);
  252. if (t < 1) {
  253. this.$nextTick(() => {
  254. this.otherNum = '';
  255. })
  256. }
  257. if (t > 500) {
  258. this.$nextTick(() => {
  259. this.otherNum = 500;
  260. })
  261. }
  262. this.selectJudge();
  263. },
  264. moneyClick(index) {
  265. this.otherNum = ''
  266. this.moneyActiveClass = index;
  267. this.selectJudge();
  268. },
  269. selectJudge(){
  270. this.submitInit()
  271. if(this.submitForm.amount==0){
  272. return
  273. }
  274. if(this.selectObj.id&&this.selectObj.threshold>this.submitForm.amount){
  275. uni.showToast({
  276. title:"请重新选择优惠券"
  277. })
  278. this.selectObj={}
  279. }
  280. },
  281. radioChange(e){},
  282. confirm() {
  283. ////(JSON.stringify(this.submitForm))
  284. if(this.selectObj.id){
  285. this.submitForm.userCouponId=this.selectObj.id
  286. }
  287. if(this.userCardBool&&this.canUse&&this.vin){
  288. this.submitForm.userCardId=this.userCard.id
  289. }
  290. uni.showLoading({
  291. title: "加载中",
  292. mask: true,
  293. })
  294. //this.submitForm.deviceNo = this.detail.deviceNo;
  295. API.startCarCharging(this.submitForm).then((res) => {
  296. //(JSON.stringify(this.res))
  297. this.gotoUrl("pages/searchPile/chargeProcess/dcCharging?id=" + res.data.recordId);
  298. }).catch(error => {
  299. uni.hideLoading()
  300. if (error == '用户账户余额不足!') {
  301. uni.showModal({
  302. title: '支付',
  303. content: '用户账户余额不足,是否充值?',
  304. success: res => {
  305. if (res.confirm) {
  306. //付钱 改为组件
  307. this.gotoUrl("pages/user/finance/recharge");
  308. } else if (res.cancel) {
  309. //('用户点击取消');
  310. }
  311. }
  312. });
  313. } else {
  314. uni.showToast({
  315. title: error
  316. })
  317. }
  318. })
  319. },
  320. getHomePage() {
  321. uni.showLoading({
  322. title: "加载中",
  323. mask: true,
  324. })
  325. API.personalCenter().then((res) => {
  326. this.user = res.data
  327. this.isReady = true;
  328. uni.hideLoading()
  329. }).catch(error => {
  330. uni.showToast({
  331. title: error
  332. })
  333. })
  334. API.userCard({
  335. stationId:this.stationId
  336. }).then((res) => {
  337. console.log(res)
  338. this.userCard=res.data.regUserCard
  339. this.canUse=res.data.canUse
  340. //this.user = res.data
  341. }).catch(error => {
  342. uni.showToast({
  343. title: error
  344. })
  345. })
  346. },
  347. useCoupon(){
  348. var obj={
  349. status:0,
  350. stationId:this.stationId
  351. }
  352. if(this.userCardBool) {
  353. obj.userCardId=this.userCard.id
  354. }
  355. userApi.couponList(obj).then((res) => {
  356. this.listlength= res.data.recordsTotal;
  357. //uni.hideLoading()
  358. }).catch(error => {
  359. uni.showToast({
  360. title: error
  361. })
  362. })
  363. },
  364. submitInit(){
  365. if (this.moneyActiveClass == -1 && !this.otherNum) {
  366. this.submitForm.chargeStrategy = 0;
  367. this.submitForm.amount = 0
  368. } else {
  369. this.submitForm.chargeStrategy = 2;
  370. if (this.otherNum) {
  371. this.submitForm.amount = this.otherNum
  372. } else {
  373. this.submitForm.amount = this.moneyActiveClass
  374. }
  375. }
  376. },
  377. submit() {
  378. this.submitInit()
  379. if (!this.submitForm.channelNo) {
  380. uni.showToast({
  381. title: '请先选择充电通道'
  382. })
  383. return
  384. }
  385. if (this.submitForm.chargeStrategy == 0 && this.user.balance < 1) {
  386. uni.showModal({
  387. title: '支付',
  388. content: '余额不足1元无法开启充满自停,是否充值?',
  389. success: res => {
  390. if (res.confirm) {
  391. //付钱 改为组件
  392. this.gotoUrl("pages/user/finance/recharge");
  393. } else if (res.cancel) {
  394. //('用户点击取消');
  395. }
  396. }
  397. });
  398. } else {
  399. this.confirm()
  400. }
  401. },
  402. }
  403. }
  404. </script>
  405. <style>
  406. page {
  407. background-color: #fff;
  408. }
  409. </style>
  410. <style lang="scss" scoped>
  411. @import "@/_theme.scss";
  412. .listlength{
  413. float: right;
  414. padding-right: 10px;
  415. }
  416. /deep/.u-radio-group {
  417. width: 100%;
  418. }
  419. /deep/.u-radio {
  420. position: relative;
  421. }
  422. /deep/.u-radio__icon-wrap {
  423. position: absolute;
  424. right: 0;
  425. }
  426. .recharge-item:last-child {
  427. @include themeify{
  428. font-size: themed('font-size2') !important;
  429. }
  430. /* font-size: 14px !important;*/
  431. color: #999999;
  432. }
  433. .u-input {
  434. text-align: center !important;
  435. }
  436. .recharge {
  437. padding: 16px;
  438. padding-bottom: 80px;
  439. .title {
  440. @include themeify{
  441. font-size: themed('font-size3');
  442. }
  443. /* font-size: 16px;*/
  444. position: relative;
  445. }
  446. p {
  447. color: #666;
  448. margin-top: 4px;
  449. }
  450. .self-stop.active {
  451. background-color: #EFFFF7;
  452. border-color: #00B962;
  453. color: #00B962;
  454. }
  455. .rechargeMain {
  456. display: flex;
  457. flex-wrap: wrap;
  458. justify-content: space-between;
  459. margin-top: 12px;
  460. margin-bottom: 20px;
  461. .recharge-item {
  462. width: 31%;
  463. border: 1px solid #e3e3e3;
  464. padding: 15px 0;
  465. border-radius: 4px;
  466. text-align: center;
  467. margin-bottom: 10px;
  468. @include themeify{
  469. font-size: themed('font-size3');
  470. }
  471. /* font-size: 16px;*/
  472. }
  473. .active {
  474. background-color: #EFFFF7;
  475. border-color: #00B962;
  476. color: #00B962;
  477. }
  478. }
  479. .self-stop {
  480. width: 105px;
  481. /* height: 48px;
  482. line-height: 48px;*/
  483. border-radius: 4px;
  484. color: #101010;
  485. @include themeify{
  486. font-size: themed('font-size3');
  487. height:themed('font-size19');
  488. line-height:themed('font-size19')
  489. }
  490. /* font-size: 16px;*/
  491. text-align: center;
  492. font-family: Arial;
  493. border: 1px solid rgba(227, 227, 227, 100);
  494. margin-top: 12px;
  495. }
  496. }
  497. .recharge-input {
  498. margin-top: 8px;
  499. margin-bottom: 32px;
  500. }
  501. .recharge-radio {
  502. margin-top: 10px;
  503. .recharge-radio-item {
  504. display: flex;
  505. align-items: center;
  506. }
  507. .recharge-radio-name {
  508. margin-left: 8px;
  509. }
  510. }
  511. .but-box {
  512. width: 89.3%;
  513. height: 44px;
  514. margin: 0 auto;
  515. position: fixed;
  516. bottom: 0;
  517. right: 0;
  518. left: 0;
  519. }
  520. //优惠券
  521. .discounts {
  522. margin-top: 20px;
  523. width: 100%;
  524. .title {
  525. width: 100%;
  526. .title-1 {
  527. /* height: 22px;*/
  528. color: rgba(16, 16, 16, 100);
  529. @include themeify{
  530. font-size: themed('font-size3');
  531. height:themed('font-size6');
  532. }
  533. /* font-size: 16px;*/
  534. }
  535. .title-2 {
  536. margin-left: 4px;
  537. @include themeify{
  538. font-size: themed('font-size2');
  539. line-height:themed('font-size5');
  540. }
  541. /* font-size: 14px;
  542. line-height: 20px;*/
  543. }
  544. .title-3 {
  545. float: right;
  546. @include themeify{
  547. font-size: themed('font-size3');
  548. line-height:themed('font-size5');
  549. }
  550. /* height: 19px;
  551. font-size: 16px;*/
  552. }
  553. }
  554. .select {
  555. position: relative;
  556. /deep/.u-radio {
  557. padding: 18px 16px;
  558. margin-top: 12px;
  559. width: 100%;
  560. height: 48px;
  561. border-radius: 4px;
  562. background-color: rgba(255, 255, 255, 100);
  563. text-align: center;
  564. border: 1px solid rgba(227, 227, 227, 100);
  565. position: relative;
  566. }
  567. // /deep/.u-radio:nth-child(3) {
  568. //
  569. // }
  570. /deep/.u-radio__icon-wrap {
  571. left: 16px;
  572. background-color: #fff;
  573. }
  574. /deep/.u-radio__label {
  575. margin-left: 40px;
  576. }
  577. }
  578. .explain {
  579. width: 64px;
  580. /* height: 24px;
  581. line-height: 24px;*/
  582. position: absolute;
  583. top: 10px;
  584. right: 12px;
  585. border-radius: 4px;
  586. background-color: rgba(255, 255, 255, 100);
  587. text-align: center;
  588. border: 1px solid rgba(227, 227, 227, 100);
  589. color: rgba(0, 185, 98, 100);
  590. /* font-size: 12px;*/
  591. @include themeify{
  592. font-size: themed('font-size1');
  593. line-height:themed('font-size7');
  594. height:themed('font-size7');
  595. }
  596. }
  597. }
  598. // 优惠券2
  599. .discounts2{
  600. margin-top: 20px;
  601. width: 100%;
  602. display: flex;
  603. justify-content: space-between;
  604. .left{
  605. /* width: 70px;*/
  606. // height: 20px;
  607. color: rgba(16, 16, 16, 100);
  608. /* font-size: 20px;*/
  609. @include themeify{
  610. width:themed('buttonWidth1');
  611. font-size: themed('font-size5');
  612. }
  613. }
  614. .right{
  615. /*
  616. height: 16px;
  617. line-height: 28px;*/
  618. color: rgba(255, 61, 0, 100);
  619. @include themeify{
  620. font-size: themed('font-size3');
  621. height: themed('font-size3');
  622. line-height: themed('font-size9');
  623. }
  624. /* font-size: 16px;*/
  625. text-align: right;
  626. display: flex;
  627. }
  628. .iconfont{
  629. @include themeify{
  630. font-size: themed('font-size7');
  631. line-height: themed('font-size10');
  632. }
  633. /* line-height: 29px;*/
  634. text-align: center;
  635. color: #b3b3b3;
  636. /* font-size: 24px;*/
  637. }
  638. }
  639. // 会员活动
  640. .member{
  641. margin-top: 20px;
  642. display: flex;
  643. justify-content: space-between;
  644. .actively{
  645. color: rgba(16, 16, 16, 100);
  646. font-size: 20px;
  647. }
  648. .type{
  649. color: rgba(16, 18, 18, 100);
  650. font-size: 16px;
  651. line-height: 28px;
  652. padding-right: 10px;
  653. }
  654. }
  655. // 尾部
  656. .bottom {
  657. background-color: #fff;
  658. width: 100%;
  659. height: 64px;
  660. line-height: 64px;
  661. position: fixed;
  662. bottom: 0;
  663. left: 0;
  664. z-index: 999;
  665. padding: 12px 16px;
  666. .botton {
  667. //width: 343px;
  668. /* height: 40px;
  669. line-height: 40px;*/
  670. border-radius: 50px;
  671. background-color: rgba(0, 185, 98, 100);
  672. color: rgba(255, 255, 255, 100);
  673. /* font-size: 16px;*/
  674. @include themeify{
  675. font-size: themed('font-size3');
  676. line-height: themed('font-size15');
  677. height: themed('font-size15');
  678. }
  679. text-align: center;
  680. margin: 0 auto;
  681. }
  682. }
  683. .couponsuse{
  684. color: rgba(153, 153, 153, 100);
  685. margin-top: 10px;
  686. @include themeify{
  687. font-size: themed('font-size1');
  688. }
  689. /* font-size: 12px;*/
  690. text-align: left;
  691. font-family: AlibabaPuHui-regular;
  692. }
  693. .to-recharge{
  694. padding: 0 16px;
  695. line-height: 36px;
  696. border-radius: 50px 0px 0px 50px;
  697. background:linear-gradient(#FF9000,#FFB700);
  698. color: rgba(255, 255, 255, 100);
  699. font-size: 16px;
  700. text-align: center;
  701. position: absolute;
  702. right: -16px;
  703. top: 0;
  704. }
  705. </style>