charge.vue 16 KB

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