charge.vue 17 KB

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