recharge.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709
  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="recharge-item" v-for="(item,index) in moneyList" :class="{
  17. active:otherNum==item.rechargeAmount||moneyActiveClass == item.id ,
  18. 'recharge-item-rk':item.amountRemark
  19. }"
  20. :key="item.id" @click="moneyClick(item.id,item)">
  21. {{item.amountDesc?item.amountDesc:item.rechargeAmount+'元'}}
  22. <view class="item-rk" v-if="item.amountRemark">送<span class="item-rk-span" >{{item.amountRemarkNum}}</span>{{item.amountRemarkHtml}}</view>
  23. </view>
  24. <p style=" font-size: 14px;" v-show="selectItem.amountRemark">
  25. 充值满
  26. <span style="color: red;">{{selectItem.amountDesc}}</span>立送服务费<span style="color: red;">{{selectItem.amountRemarkNum}}折半年卡</span>1张(<span style="color: red;">有效期180天,不限充电度数</span>)1<span v-if="selectItem.amountRemarkSf">和{{selectItem.amountRemarkSf}}身份</span>,活动所充金额仅用于支付本平台充电费用(含电费和服务费),不可转赠、提现、退款,
  27. <span style="color: #ff8600;margin-left: 16px;" @click="gotoUrl('pages/temporary/activity20250501?source=99',1)">点击查看活动详情</span>
  28. </p>
  29. </view>
  30. <p class="oldTextjp2" oldstyle="font-size:16px">其他充值金额</p>
  31. <view style="margin-bottom: 32px;">
  32. <view
  33. :class="otherNum&&selectItem.rechargeAmount!=otherNum? 'active' : ''"
  34. class="recharge-input self-stop">
  35. <u-input v-model="otherNum" @input="ckInput" @focus="focus" type="digit" :border="true" />
  36. </view>
  37. <view style="color: rgba(153, 153, 153, 100);
  38. font-size: 12px;
  39. text-align: left;
  40. font-family: AlibabaPuHui-regular;"><span style="color:red">*</span>单次充值金额不超过5000元。</view>
  41. </view>
  42. <view class="title oldTextjp" oldstyle="font-size:20px">选择支付方式</view>
  43. <view class="recharge-radio" style="padding-bottom: 170px;">
  44. <u-radio-group v-model="value2" @change="radioGroupChange" :wrap="true" width="100%">
  45. <u-radio active-color="#00B962" @change="radioChange" v-for="(item, index) in list" :key="index"
  46. :name="item.id" :disabled="item.disabled" width="100%">
  47. <view class="recharge-radio-item">
  48. <u-icon :name="item.icon" custom-prefix="custom-icon" :color="item.color" size="48">
  49. </u-icon>
  50. <view class="recharge-radio-name oldTextjp2" oldstyle="font-size:18px">
  51. {{item.name}}
  52. </view>
  53. </view>
  54. </u-radio>
  55. </u-radio-group>
  56. </view>
  57. <u-modal v-model="showModel"
  58. :show-cancel-button="true"
  59. @confirm="confirm"
  60. confirm-text="支付成功?"
  61. title="扫码支付" >
  62. <view style="
  63. text-align: center;
  64. ">
  65. <img id="qrcode2" :src="qrCodeImg" >
  66. </view>
  67. <view style="
  68. text-align: center;
  69. ">请使用支付宝扫码</view>
  70. </u-modal>
  71. <img id="qrcode" style="display: none;" >
  72. <view class="recharge-btn" v-if="show2">
  73. <view v-if="show2">
  74. <u-checkbox-group>
  75. <u-checkbox active-color="green" v-model="checked" shape="circle" @change="checkboxChange()"></u-checkbox>
  76. </u-checkbox-group>
  77. 我已阅读并同意<span @click="gotoUrl('pages/article/details?code=CZXY')" style="color:#00B962" >《充值协议》</span>
  78. </view>
  79. <u-button
  80. :class="checked?'success-btn':'nosuccess-btn'"
  81. shape="circle" type="success" @click="rechargeNow">
  82. <span>{{recordId?'充值并启动':'立即充值'}}</span>
  83. </u-button>
  84. </view>
  85. <u-modal v-model="show1" @confirm="gotoGz"
  86. cancel-text="暂不关注"
  87. confirm-text="前往关注"
  88. confirm-color="#53b56b"
  89. :show-cancel-button="true"
  90. ref="uModal2" :asyncClose="true"
  91. >
  92. <view style="padding: 15px;"
  93. >请先关注<span style=" color: #53b56b;">{{projectName}}</span>公众号,然后进行余额充值</view>
  94. </u-modal>
  95. <view class="recharge-btn transactionClass" v-if="!show2">
  96. <u-button
  97. class="success-btn"
  98. shape="circle" type="success" @click="gotoGz">
  99. <span>关注公众号</span>
  100. </u-button>
  101. </view>
  102. </view>
  103. </view>
  104. </template>
  105. <script>
  106. import * as API_weixin from '@/apis/weixin.js'
  107. import * as newsApi from '@/apis/news.js'
  108. import * as Pay from '@/apis/weixin.js'
  109. import QRCode from 'qrcodejs2'
  110. import {
  111. convertCanvasToImage,
  112. } from '@/utils'
  113. import {
  114. wxPayJs
  115. } from '@/utils/wxpay'
  116. import * as API from '@/apis/finance.js'
  117. export default {
  118. data() {
  119. return {
  120. show1:false,
  121. show2:true,
  122. submitNum:0,
  123. submitNumCk:1,
  124. showModel:false,
  125. selectItem:{},
  126. userId: '',
  127. outOrderNo:'',
  128. detail: {},
  129. moneyActiveClass: 1,
  130. submitForm:{},
  131. qrCodeImg:"",
  132. bannerList:[],
  133. selectImg:null,
  134. moneyList: [
  135. ],
  136. list: [{
  137. id:'0',
  138. name: '微信支付',
  139. icon: 'wechat-pay-fill',
  140. color: '#22ac38',
  141. },
  142. {
  143. id:'1',
  144. name: '支付宝支付',
  145. icon: 'alipay-fill',
  146. color: '#1677ff',
  147. },
  148. ],
  149. // u-radio-group的v-model绑定的值如果设置为某个radio的name,就会被默认选中
  150. value2: '0',
  151. otherNum:"",
  152. value1: '',
  153. checked: true,
  154. projectName:"",
  155. recordId:"",
  156. }
  157. },
  158. onLoad(op) {
  159. this.projectName=process.car.ProjectName;
  160. if(op.recordId){
  161. this.recordId=op.recordId;
  162. }
  163. },
  164. onReady() {
  165. if (this.carhelp.getPersonInfo()) {
  166. this.userId = this.carhelp.getPersonInfo().id;
  167. }
  168. this.init();
  169. this.getBannerInfo("userinfo")
  170. },
  171. methods: {
  172. clickBanner(index, bl, modout) {
  173. var uurl = "";
  174. var mod = this.bannerList[index]
  175. var mod = {}
  176. if (modout) {
  177. mod = modout;
  178. }else{
  179. mod =this.bannerList[index]
  180. }
  181. mod.clickUrl = mod.linkUrl
  182. if (mod.linkPicUrl && !bl) {
  183. this.showOss = true;
  184. this.showOssImg = mod.linkPicUrl;
  185. this.showOssIndex = index;
  186. } else if (mod.clickUrl == null) {
  187. } else if (mod.clickUrl.indexOf('http') == 0) {
  188. window.location = mod.clickUrl + uurl;
  189. } else if (mod.clickUrl.slice(-5) == 'login' && this.userId) {
  190. } else if (mod.clickUrl.indexOf('#/') == 0) {
  191. if (mod.clickUrl.indexOf("?") == -1) {
  192. mod.clickUrl += '?';
  193. }
  194. var url = mod.clickUrl.split("#")[1]
  195. //window.location = mod.clickUrl;
  196. uni.navigateTo({
  197. url: url + uurl
  198. })
  199. } else if (mod.clickUrl == '#' || mod.clickUrl == '') {
  200. } else {
  201. uni.navigateTo({
  202. url: mod.clickUrl + uurl
  203. })
  204. }
  205. },
  206. getBannerInfo(code){
  207. newsApi.getBannerInfo(code).then((res) => {
  208. this.bannerList =res.data;
  209. // document.getElementsByClassName("uni-swiper-wrapper")[0].parentNode.style="background-color: rgb(255, 255, 255); height: 300px;"
  210. }).catch(error => {
  211. uni.showToast({
  212. title: error,icon: "none"
  213. })
  214. })
  215. },
  216. focus(){
  217. console.log(0)
  218. uni.pageScrollTo({
  219. scrollTop:999999,
  220. duration:0
  221. })
  222. },
  223. gotoGz(){
  224. this.carhelp.setGzDate()
  225. var url = process.car.gzUrl;
  226. window.location.href=url
  227. },
  228. checkSubscribe(){
  229. API_weixin.checkSubscribe({
  230. openId: this.carhelp.getOpenId()
  231. }).then((res) => {
  232. if(res.data=="0"){
  233. this.show1=true
  234. }else{
  235. //this.init();
  236. this.show2=true;
  237. //this.carhelp.setGzDate()
  238. }
  239. //setGzDate
  240. }).catch(error => {
  241. uni.showToast({
  242. title: error
  243. })
  244. })
  245. },
  246. confirm(){
  247. uni.redirectTo({
  248. url:"/pages/user/finance/rechargeRes?id="+this.outOrderNo
  249. })
  250. },
  251. ckInput(text){
  252. if(text.indexOf('.')>0){
  253. var k =text.split(".")[1]
  254. if(k.length>=3){
  255. this.$nextTick(()=>{
  256. text=parseFloat(text).toFixed(2);
  257. this.otherNum= text
  258. })
  259. }
  260. }
  261. var t =Number(text);
  262. if(t<1){
  263. this.$nextTick(()=>{
  264. this.otherNum='';
  265. })
  266. }
  267. if(t>5000){
  268. this.$nextTick(()=>{
  269. this.otherNum=5000;
  270. })
  271. }
  272. this.moneyActiveClass=''
  273. for(var i in this.moneyList){
  274. var item=this.moneyList[i]
  275. if(this.otherNum==item.rechargeAmount){
  276. this.moneyClick(item.id,item)
  277. }
  278. }
  279. },
  280. init1() {
  281. uni.showLoading({
  282. title: "加载中",
  283. mask: true,
  284. })
  285. API.personalCenter().then((res) => {
  286. this.detail = res.data
  287. this.isReady = true;
  288. uni.hideLoading()
  289. }).catch(error => {
  290. uni.showToast({
  291. title: error
  292. })
  293. })
  294. },
  295. init() {
  296. uni.showLoading({
  297. title: "加载中",
  298. mask: true,
  299. })
  300. var data = {
  301. type:2 };
  302. API.marketingData(data).then((res) => {
  303. this.moneyList = res.data.chargingMarketingList
  304. if (this.moneyList.length > 0) {
  305. // this.selectItem = this.moneyList[0];
  306. // this.moneyActiveClass = this.moneyList[0].id
  307. //(this.moneyActiveClass)
  308. this.moneyClick( this.moneyList[0].id,this.moneyList[0])
  309. }
  310. for(var i in this.moneyList){
  311. var item =this.moneyList[i]
  312. if(item.imgUrl&&!this.selectImg){
  313. this.selectImg=item
  314. }
  315. if(item.rechargeAmount==100){
  316. // this.selectItem = this.moneyList[i];
  317. // this.moneyActiveClass = this.moneyList[i].id
  318. this.moneyClick(item.id,item)
  319. }
  320. if(item.amountRemark){
  321. item.amountRemarkNum=item.amountRemark.substring(1,item.amountRemark.indexOf('折'))
  322. item.amountRemarkHtml=item.amountRemark.substring(item.amountRemark.indexOf('折'))
  323. if(item.amountRemark.indexOf('、')!=-1){
  324. item.amountRemarkSf=item.amountRemark.substring(item.amountRemark.indexOf('、')+1)
  325. }else{
  326. item.amountRemarkSf=""
  327. }
  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. uni.showLoading({
  435. title: "加载中",
  436. mask: true,
  437. })
  438. this.submitForm={};
  439. if(!this.otherNum){
  440. uni.showToast({
  441. title:"请选择充值金额"
  442. })
  443. return
  444. }
  445. if(!this.otherNum){
  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. //margin-left: 5px;
  537. }
  538. .recharge-item-rk{
  539. width: 48%;
  540. padding-bottom: 0;
  541. .item-rk{
  542. margin-top: 20rpx;
  543. padding: 8rpx 0;
  544. background-color: rgba(232, 232, 232, 1);
  545. color: rgba(51, 51, 51, 1);
  546. font-size: 24rpx;
  547. }
  548. .item-rk-span{
  549. margin:0 4px ;
  550. color: #ec4530;
  551. }
  552. }
  553. .amount {
  554. // width: 41.9%;
  555. height: 16px;
  556. line-height: 15px;
  557. border-radius: 0px 4px 0px 4px;
  558. background-color: #ec4530;//rgba(0, 185, 98, 100)
  559. color: rgba(255, 255, 255, 100);
  560. font-size: 10px;
  561. text-align: center;
  562. position: absolute;
  563. top: 0;
  564. right: 0;
  565. }
  566. .active {
  567. background-color: #EFFFF7;
  568. border-color: #00B962;
  569. color: #00B962;
  570. .item-rk{
  571. background-color: #53B56B;
  572. color: #fff;
  573. }
  574. .item-rk-span{
  575. color: #fff;
  576. }
  577. }
  578. }
  579. }
  580. .recharge-input {
  581. margin-top: 8px;
  582. //margin-bottom: 32px;
  583. }
  584. .recharge-radio {
  585. margin-top: 10px;
  586. .recharge-radio-item {
  587. display: flex;
  588. align-items: center;
  589. }
  590. .recharge-radio-name {
  591. margin-left: 8px;
  592. }
  593. }
  594. .recharge-btn {
  595. position: fixed;
  596. left: 16px;
  597. right: 16px;
  598. bottom: 0px;
  599. background-color: #FFF;
  600. padding-bottom: 20px;
  601. }
  602. .success-btn {
  603. margin-top: 10px;
  604. background-color: #00B962 !important;
  605. flex: 1;
  606. border-color: #00B962 !important;
  607. color: #fff !important;
  608. }
  609. .nosuccess-btn {
  610. margin-top: 10px;
  611. background-color: #a7dbc2 !important;
  612. flex: 1;
  613. border-color: #a7dbc2 !important;
  614. color: #fff !important;
  615. }
  616. </style>