charge.vue 17 KB

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