charge.vue 17 KB

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