recharge.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744
  1. <template>
  2. <view>
  3. <ujp-navbar title="充值"></ujp-navbar>
  4. <view class="discounts" v-if="bannerList.length">
  5. <u-swiper bg-color="#fff" :img-mode="'scaleToFill'" height="160" :list="bannerList" @click="clickBanner"
  6. :name="'picUrl'">
  7. </u-swiper>
  8. </view>
  9. <view class="recharge">
  10. <view class="title oldTextjp" oldstyle="font-size:20px">选择充值金额
  11. <span class="oldTextjp2 rightspan " oldstyle="font-size:16px;" >当前余额
  12. <span style="color: #FF5722;margin-left: 8px;" >{{detail.balance>0?detail.balance.toFixed(2):'0.00'}}元</span>
  13. </span>
  14. </view>
  15. <view class="rechargeMain">
  16. <view class="tip-box">
  17. 近半年您已花费<span>560元</span>充电,参与充值送折扣卡活动推荐充值<span>500元</span>,预计可省<span>24.8元</span>。
  18. </view>
  19. <view class="recharge-item" v-for="(item,index) in moneyList" :class="{
  20. active:otherNum==item.rechargeAmount||moneyActiveClass == item.id ,
  21. 'recharge-item-rk':item.amountRemark
  22. }"
  23. :key="item.id" @click="moneyClick(item.id,item)">
  24. {{item.amountDesc?item.amountDesc:item.rechargeAmount+'元'}}
  25. <view class="item-rk" v-if="item.amountRemark">送<span class="item-rk-span" >{{item.amountRemarkNum}}</span>折卡</view>
  26. </view>
  27. <p style=" font-size: 14px;" v-show="selectItem.amountRemark">
  28. 充值满
  29. <span style="color: red;">{{selectItem.amountDesc}}</span>立送服务费<span style="color: red;">{{selectItem.amountRemarkNum}}折半年卡</span>1张(<span style="color: red;">有效期180天,不限充电度数</span>)<span v-if="selectItem.amountRemarkSf">和{{selectItem.amountRemarkSf}}身份</span>,活动所充金额仅用于支付本平台充电费用(含电费和服务费),不可转赠、提现、退款,
  30. <span style="color: #ff8600;margin-left: 16px;" @click="gotoUrl('pages/temporary/activity20250501?source=99',1)">点击查看活动详情</span>
  31. </p>
  32. </view>
  33. <p class="oldTextjp2" oldstyle="font-size:16px">其他充值金额</p>
  34. <view style="margin-bottom: 32px;">
  35. <view
  36. :class="otherNum&&selectItem.rechargeAmount!=otherNum? 'active' : ''"
  37. class="recharge-input self-stop">
  38. <u-input v-model="otherNum" @input="ckInput" @focus="focus" type="digit" :border="true" />
  39. </view>
  40. <view style="color: rgba(153, 153, 153, 100);
  41. font-size: 12px;
  42. text-align: left;
  43. font-family: AlibabaPuHui-regular;"><span style="color:red">*</span>单次充值金额不超过5000元。</view>
  44. </view>
  45. <view class="title oldTextjp" oldstyle="font-size:20px">选择支付方式</view>
  46. <view class="recharge-radio" style="padding-bottom: 170px;">
  47. <u-radio-group v-model="value2" @change="radioGroupChange" :wrap="true" width="100%">
  48. <u-radio active-color="#00B962" @change="radioChange" v-for="(item, index) in list" :key="index"
  49. :name="item.id" :disabled="item.disabled" width="100%">
  50. <view class="recharge-radio-item">
  51. <u-icon :name="item.icon" custom-prefix="custom-icon" :color="item.color" size="48">
  52. </u-icon>
  53. <view class="recharge-radio-name oldTextjp2" oldstyle="font-size:18px">
  54. {{item.name}}
  55. </view>
  56. </view>
  57. </u-radio>
  58. </u-radio-group>
  59. </view>
  60. <u-modal v-model="showModel"
  61. :show-cancel-button="true"
  62. @confirm="confirm"
  63. confirm-text="支付成功?"
  64. title="扫码支付" >
  65. <view style="
  66. text-align: center;
  67. ">
  68. <img id="qrcode2" :src="qrCodeImg" >
  69. </view>
  70. <view style="
  71. text-align: center;
  72. ">请使用支付宝扫码</view>
  73. </u-modal>
  74. <img id="qrcode" style="display: none;" >
  75. <view class="recharge-btn" v-if="show2">
  76. <view v-if="show2">
  77. <u-checkbox-group>
  78. <u-checkbox active-color="green" v-model="checked" shape="circle" @change="checkboxChange()"></u-checkbox>
  79. </u-checkbox-group>
  80. 我已阅读并同意<span @click="gotoUrl('pages/article/details?code=CZXY')" style="color:#00B962" >《充值协议》</span>
  81. </view>
  82. <u-button
  83. :class="checked?'success-btn':'nosuccess-btn'"
  84. shape="circle" type="success" @click="rechargeNow">
  85. <span>{{recordId?'充值并启动':'立即充值'}}</span>
  86. </u-button>
  87. </view>
  88. <u-modal v-model="show1" @confirm="gotoGz"
  89. cancel-text="暂不关注"
  90. confirm-text="前往关注"
  91. confirm-color="#53b56b"
  92. :show-cancel-button="true"
  93. ref="uModal2" :asyncClose="true"
  94. >
  95. <view style="padding: 15px;"
  96. >请先关注<span style=" color: #53b56b;">{{projectName}}</span>公众号,然后进行余额充值</view>
  97. </u-modal>
  98. <view class="recharge-btn transactionClass" v-if="!show2">
  99. <u-button
  100. class="success-btn"
  101. shape="circle" type="success" @click="gotoGz">
  102. <span>关注公众号</span>
  103. </u-button>
  104. </view>
  105. </view>
  106. </view>
  107. </template>
  108. <script>
  109. import * as API_weixin from '@/apis/weixin.js'
  110. import * as newsApi from '@/apis/news.js'
  111. import * as Pay from '@/apis/weixin.js'
  112. import QRCode from 'qrcodejs2'
  113. import {
  114. convertCanvasToImage,
  115. } from '@/utils'
  116. import {
  117. wxPayJs
  118. } from '@/utils/wxpay'
  119. import * as API from '@/apis/finance.js'
  120. export default {
  121. data() {
  122. return {
  123. show1:false,
  124. show2:true,
  125. submitNum:0,
  126. submitNumCk:1,
  127. showModel:false,
  128. selectItem:{},
  129. userId: '',
  130. outOrderNo:'',
  131. detail: {},
  132. moneyActiveClass: 1,
  133. submitForm:{},
  134. qrCodeImg:"",
  135. bannerList:[],
  136. selectImg:null,
  137. moneyList: [
  138. ],
  139. list: [{
  140. id:'0',
  141. name: '微信支付',
  142. icon: 'wechat-pay-fill',
  143. color: '#22ac38',
  144. },
  145. {
  146. id:'1',
  147. name: '支付宝支付',
  148. icon: 'alipay-fill',
  149. color: '#1677ff',
  150. },
  151. ],
  152. // u-radio-group的v-model绑定的值如果设置为某个radio的name,就会被默认选中
  153. value2: '0',
  154. otherNum:"",
  155. value1: '',
  156. checked: true,
  157. projectName:"",
  158. recordId:"",
  159. }
  160. },
  161. onLoad(op) {
  162. this.projectName=process.car.ProjectName;
  163. if(op.recordId){
  164. this.recordId=op.recordId;
  165. }
  166. },
  167. onReady() {
  168. if (this.carhelp.getPersonInfo()) {
  169. this.userId = this.carhelp.getPersonInfo().id;
  170. }
  171. this.init();
  172. this.getBannerInfo("userinfo")
  173. },
  174. methods: {
  175. clickBanner(index, bl, modout) {
  176. var uurl = "";
  177. var mod = this.bannerList[index]
  178. var mod = {}
  179. if (modout) {
  180. mod = modout;
  181. }else{
  182. mod =this.bannerList[index]
  183. }
  184. mod.clickUrl = mod.linkUrl
  185. if (mod.linkPicUrl && !bl) {
  186. this.showOss = true;
  187. this.showOssImg = mod.linkPicUrl;
  188. this.showOssIndex = index;
  189. } else if (mod.clickUrl == null) {
  190. } else if (mod.clickUrl.indexOf('http') == 0) {
  191. window.location = mod.clickUrl + uurl;
  192. } else if (mod.clickUrl.slice(-5) == 'login' && this.userId) {
  193. } else if (mod.clickUrl.indexOf('#/') == 0) {
  194. if (mod.clickUrl.indexOf("?") == -1) {
  195. mod.clickUrl += '?';
  196. }
  197. var url = mod.clickUrl.split("#")[1]
  198. //window.location = mod.clickUrl;
  199. uni.navigateTo({
  200. url: url + uurl
  201. })
  202. } else if (mod.clickUrl == '#' || mod.clickUrl == '') {
  203. } else {
  204. uni.navigateTo({
  205. url: mod.clickUrl + uurl
  206. })
  207. }
  208. },
  209. getBannerInfo(code){
  210. newsApi.getBannerInfo(code).then((res) => {
  211. this.bannerList =res.data;
  212. // document.getElementsByClassName("uni-swiper-wrapper")[0].parentNode.style="background-color: rgb(255, 255, 255); height: 300px;"
  213. }).catch(error => {
  214. uni.showToast({
  215. title: error,icon: "none"
  216. })
  217. })
  218. },
  219. focus(){
  220. console.log(0)
  221. uni.pageScrollTo({
  222. scrollTop:999999,
  223. duration:0
  224. })
  225. },
  226. gotoGz(){
  227. this.carhelp.setGzDate()
  228. var url = process.car.gzUrl;
  229. window.location.href=url
  230. },
  231. checkSubscribe(){
  232. API_weixin.checkSubscribe({
  233. openId: this.carhelp.getOpenId()
  234. }).then((res) => {
  235. if(res.data=="0"){
  236. this.show1=true
  237. }else{
  238. //this.init();
  239. this.show2=true;
  240. //this.carhelp.setGzDate()
  241. }
  242. //setGzDate
  243. }).catch(error => {
  244. uni.showToast({
  245. title: error
  246. })
  247. })
  248. },
  249. confirm(){
  250. uni.redirectTo({
  251. url:"/pages/user/finance/rechargeRes?id="+this.outOrderNo
  252. })
  253. },
  254. ckInput(text){
  255. if(text.indexOf('.')>0){
  256. var k =text.split(".")[1]
  257. if(k.length>=3){
  258. this.$nextTick(()=>{
  259. text=parseFloat(text).toFixed(2);
  260. this.otherNum= text
  261. })
  262. }
  263. }
  264. var t =Number(text);
  265. if(t<1){
  266. this.$nextTick(()=>{
  267. this.otherNum='';
  268. })
  269. }
  270. if(t>5000){
  271. this.$nextTick(()=>{
  272. this.otherNum=5000;
  273. })
  274. }
  275. this.moneyActiveClass=''
  276. for(var i in this.moneyList){
  277. var item=this.moneyList[i]
  278. if(this.otherNum==item.rechargeAmount){
  279. this.moneyClick(item.id,item)
  280. }
  281. }
  282. },
  283. init1() {
  284. uni.showLoading({
  285. title: "加载中",
  286. mask: true,
  287. })
  288. API.personalCenter().then((res) => {
  289. this.detail = res.data
  290. this.isReady = true;
  291. uni.hideLoading()
  292. }).catch(error => {
  293. uni.showToast({
  294. title: error
  295. })
  296. })
  297. },
  298. init() {
  299. uni.showLoading({
  300. title: "加载中",
  301. mask: true,
  302. })
  303. var data = {
  304. type:2 };
  305. API.marketingData(data).then((res) => {
  306. this.moneyList = res.data.chargingMarketingList
  307. if (this.moneyList.length > 0) {
  308. // this.selectItem = this.moneyList[0];
  309. // this.moneyActiveClass = this.moneyList[0].id
  310. //(this.moneyActiveClass)
  311. this.moneyClick( this.moneyList[0].id,this.moneyList[0])
  312. }
  313. for(var i in this.moneyList){
  314. var item =this.moneyList[i]
  315. if(item.imgUrl&&!this.selectImg){
  316. this.selectImg=item
  317. }
  318. if(item.rechargeAmount==100){
  319. // this.selectItem = this.moneyList[i];
  320. // this.moneyActiveClass = this.moneyList[i].id
  321. this.moneyClick(item.id,item)
  322. }
  323. if(item.amountRemark&&item.marketingCardList.length){
  324. var mk=item.marketingCardList[0]
  325. item.amountRemarkNum=mk.serviceFeeDiscountRate/10
  326. item.amountRemarkHtml=item.amountRemark.substring(item.amountRemark.indexOf('折'))
  327. item.amountRemarkSf=mk.giftMemberLevelStr
  328. }
  329. }
  330. uni.hideLoading()
  331. this.init1()
  332. }).catch(error => {
  333. uni.showToast({
  334. title: error
  335. })
  336. })
  337. },
  338. moneyClick(id,item) {
  339. this.otherNum=item.rechargeAmount;
  340. this.moneyActiveClass = id;
  341. if(item){
  342. this.selectItem=item;
  343. if(item.imgUrl){
  344. this.selectImg=item
  345. }
  346. }
  347. },
  348. // 选中某个单选框时,由radio时触发
  349. radioChange(e) {
  350. // //(e);
  351. },
  352. // 选中任一radio时,由radio-group触发
  353. radioGroupChange(e) {
  354. // //(e);
  355. },
  356. checkboxChange() {
  357. this.checked = !this.checked;
  358. },
  359. alpy(){
  360. var obj={
  361. ...this.submitForm
  362. }
  363. if(obj.amount){
  364. for(var i in this.moneyList){
  365. var item =this.moneyList[i]
  366. if(item.rechargeAmount==obj.amount){
  367. delete obj.amount;
  368. obj.chargingMarketingId=item.id
  369. break
  370. }
  371. }
  372. }
  373. uni.showLoading({
  374. title: "加载中",
  375. mask: true,
  376. })
  377. Pay.alpay(obj).then((response) => {
  378. let qrcode = new QRCode('qrcode', {
  379. width: 200,
  380. height: 200,
  381. text: response.data.qr_code,
  382. correctLevel: QRCode.CorrectLevel.M,
  383. })
  384. this.outOrderNo=response.data.outOrderNo;
  385. var canvas = document.getElementsByTagName('canvas')[0];
  386. this.qrCodeImg = convertCanvasToImage(canvas);
  387. uni.hideLoading()
  388. this.showModel=true
  389. }).catch(error => {
  390. uni.showToast({
  391. title: error
  392. })
  393. })
  394. },
  395. wxpy(){
  396. var obj={
  397. ...this.submitForm
  398. }
  399. if(obj.amount){
  400. for(var i in this.moneyList){
  401. var item =this.moneyList[i]
  402. if(item.rechargeAmount==obj.amount){
  403. delete obj.amount;
  404. obj.chargingMarketingId=item.id
  405. break
  406. }
  407. }
  408. }
  409. //this.moneyList
  410. Pay.wxpay(obj).then((response) => {
  411. if(!response.result){
  412. uni.showToast({
  413. title: response.message
  414. })
  415. return
  416. }
  417. var data = response.data
  418. uni.hideLoading()
  419. //("Pay+"+new Date().getTime())
  420. wxPayJs(data);
  421. }).catch(error => {
  422. uni.showToast({
  423. title: error
  424. })
  425. })
  426. },
  427. rechargeNow() {
  428. if(!this.checked){
  429. uni.showToast({
  430. title:"请同意《充值协议》后进行充值"
  431. })
  432. return
  433. }
  434. if(!this.otherNum){
  435. uni.showToast({
  436. title:"请选择充值金额"
  437. })
  438. return
  439. }
  440. uni.showLoading({
  441. title: "加载中",
  442. mask: true,
  443. })
  444. this.submitForm={};
  445. if(this.moneyActiveClass){
  446. this.submitForm.chargingMarketingId=this.selectItem.id;
  447. }else{
  448. this.submitForm.amount=this.otherNum
  449. }
  450. if (this.recordId) {
  451. this.submitForm.recordId = this.recordId
  452. }
  453. //(this.submitForm)
  454. if(this.value2=="0"){
  455. this.wxpy()
  456. }else{
  457. this.alpy()
  458. }
  459. }
  460. },
  461. onShow() {
  462. // this.checkSubscribe()
  463. if (this.isReady) {
  464. this.init1()
  465. }
  466. }
  467. }
  468. </script>
  469. <style>
  470. page {
  471. background-color: #fff;
  472. }
  473. </style>
  474. <style lang="scss" scoped>
  475. // 优惠
  476. .discounts {
  477. width: 91.4%;
  478. //height: 200rpx;
  479. margin: 16rpx auto 0 auto;
  480. border-radius: 8px;
  481. overflow: hidden;
  482. img {
  483. width: 100%;
  484. height: 80px;
  485. }
  486. }
  487. .rightspan{
  488. float: right;
  489. color: rgba(102, 102, 102, 1);
  490. font-weight: 400;
  491. }
  492. .userBanner{
  493. margin: 16px;
  494. }
  495. ::v-deep .u-radio-group {
  496. width: 100%;
  497. }
  498. ::v-deep .u-radio {
  499. position: relative;
  500. }
  501. ::v-deep .u-radio__icon-wrap {
  502. position: absolute;
  503. right: 0;
  504. }
  505. .recharge {
  506. padding: 16px;
  507. .title {
  508. font-size: 16px;
  509. }
  510. p {
  511. color: #666;
  512. margin-top: 4px;
  513. }
  514. .self-stop.active{
  515. border: 1px solid;
  516. background-color: #EFFFF7;
  517. border-color: #00B962;
  518. color: #00B962;
  519. }
  520. .rechargeMain {
  521. display: flex;
  522. flex-wrap: wrap;
  523. justify-content: space-around;
  524. // justify-content: space-between;
  525. margin-top: 12px;
  526. margin-bottom: 20px;
  527. .recharge-item {
  528. width: 23%;
  529. border: 1px solid #e3e3e3;
  530. padding: 20rpx 0;
  531. border-radius: 4px;
  532. text-align: center;
  533. margin-bottom: 10px;
  534. font-size: 32rpx;
  535. position: relative;
  536. font-weight: bold;
  537. //margin-left: 5px;
  538. }
  539. .recharge-item-rk{
  540. width: 23%;
  541. padding-bottom: 0;
  542. .item-rk{
  543. font-weight: 400;
  544. // margin-top: 20rpx;
  545. padding: 8rpx 0;
  546. // background-color: rgba(232, 232, 232, 1);
  547. color: rgba(51, 51, 51, 1);
  548. font-size: 24rpx;
  549. }
  550. .item-rk-span{
  551. margin:0 4px ;
  552. color: #ec4530;
  553. }
  554. }
  555. .amount {
  556. // width: 41.9%;
  557. height: 16px;
  558. line-height: 15px;
  559. border-radius: 0px 4px 0px 4px;
  560. background-color: #ec4530;//rgba(0, 185, 98, 100)
  561. color: rgba(255, 255, 255, 100);
  562. font-size: 10px;
  563. text-align: center;
  564. position: absolute;
  565. top: 0;
  566. right: 0;
  567. }
  568. .active {
  569. background-color: #EFFFF7;
  570. border-color: #00B962;
  571. color: #00B962;
  572. .item-rk{
  573. //background-color: #53B56B;
  574. color:#53B56B
  575. }
  576. .item-rk-span{
  577. color: #53B56B
  578. }
  579. }
  580. }
  581. }
  582. .recharge-input {
  583. margin-top: 8px;
  584. //margin-bottom: 32px;
  585. }
  586. .recharge-radio {
  587. margin-top: 10px;
  588. .recharge-radio-item {
  589. display: flex;
  590. align-items: center;
  591. }
  592. .recharge-radio-name {
  593. margin-left: 8px;
  594. }
  595. }
  596. .recharge-btn {
  597. position: fixed;
  598. left: 16px;
  599. right: 16px;
  600. bottom: 0px;
  601. background-color: #FFF;
  602. padding-bottom: 20px;
  603. }
  604. .success-btn {
  605. margin-top: 10px;
  606. background-color: #00B962 !important;
  607. flex: 1;
  608. border-color: #00B962 !important;
  609. color: #fff !important;
  610. }
  611. .nosuccess-btn {
  612. margin-top: 10px;
  613. background-color: #a7dbc2 !important;
  614. flex: 1;
  615. border-color: #a7dbc2 !important;
  616. color: #fff !important;
  617. }
  618. .tip-box {
  619. position: relative;
  620. background-color: #fff;
  621. border: 1px solid #f5a623;
  622. border-radius: 8px;
  623. padding: 10px 15px;
  624. color: #333;
  625. width: 400px;
  626. margin-bottom: 20px;
  627. background: #FEF8E9;
  628. }
  629. .tip-box::before {
  630. content: "";
  631. position: absolute;
  632. top: 100%;
  633. left: 20px;
  634. border-left: 10px solid transparent;
  635. border-right: 10px solid transparent;
  636. border-top: 10px solid #f5a623;
  637. }
  638. .tip-box span {
  639. color: #f5a623;
  640. font-weight: bold;
  641. }
  642. </style>