recharge.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708
  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>)<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&&item.marketingCardList.length){
  321. var mk=item.marketingCardList[0]
  322. item.amountRemarkNum=mk.serviceFeeDiscountRate/10
  323. item.amountRemarkHtml=item.amountRemark.substring(item.amountRemark.indexOf('折'))
  324. item.amountRemarkSf=mk.giftMemberLevelStr
  325. }
  326. }
  327. uni.hideLoading()
  328. this.init1()
  329. }).catch(error => {
  330. uni.showToast({
  331. title: error
  332. })
  333. })
  334. },
  335. moneyClick(id,item) {
  336. this.otherNum=item.rechargeAmount;
  337. this.moneyActiveClass = id;
  338. if(item){
  339. this.selectItem=item;
  340. if(item.imgUrl){
  341. this.selectImg=item
  342. }
  343. }
  344. },
  345. // 选中某个单选框时,由radio时触发
  346. radioChange(e) {
  347. // //(e);
  348. },
  349. // 选中任一radio时,由radio-group触发
  350. radioGroupChange(e) {
  351. // //(e);
  352. },
  353. checkboxChange() {
  354. this.checked = !this.checked;
  355. },
  356. alpy(){
  357. var obj={
  358. ...this.submitForm
  359. }
  360. if(obj.amount){
  361. for(var i in this.moneyList){
  362. var item =this.moneyList[i]
  363. if(item.rechargeAmount==obj.amount){
  364. delete obj.amount;
  365. obj.chargingMarketingId=item.id
  366. break
  367. }
  368. }
  369. }
  370. uni.showLoading({
  371. title: "加载中",
  372. mask: true,
  373. })
  374. Pay.alpay(obj).then((response) => {
  375. let qrcode = new QRCode('qrcode', {
  376. width: 200,
  377. height: 200,
  378. text: response.data.qr_code,
  379. correctLevel: QRCode.CorrectLevel.M,
  380. })
  381. this.outOrderNo=response.data.outOrderNo;
  382. var canvas = document.getElementsByTagName('canvas')[0];
  383. this.qrCodeImg = convertCanvasToImage(canvas);
  384. uni.hideLoading()
  385. this.showModel=true
  386. }).catch(error => {
  387. uni.showToast({
  388. title: error
  389. })
  390. })
  391. },
  392. wxpy(){
  393. var obj={
  394. ...this.submitForm
  395. }
  396. if(obj.amount){
  397. for(var i in this.moneyList){
  398. var item =this.moneyList[i]
  399. if(item.rechargeAmount==obj.amount){
  400. delete obj.amount;
  401. obj.chargingMarketingId=item.id
  402. break
  403. }
  404. }
  405. }
  406. //this.moneyList
  407. Pay.wxpay(obj).then((response) => {
  408. if(!response.result){
  409. uni.showToast({
  410. title: response.message
  411. })
  412. return
  413. }
  414. var data = response.data
  415. uni.hideLoading()
  416. //("Pay+"+new Date().getTime())
  417. wxPayJs(data);
  418. }).catch(error => {
  419. uni.showToast({
  420. title: error
  421. })
  422. })
  423. },
  424. rechargeNow() {
  425. if(!this.checked){
  426. uni.showToast({
  427. title:"请同意《充值协议》后进行充值"
  428. })
  429. return
  430. }
  431. if(!this.otherNum){
  432. uni.showToast({
  433. title:"请选择充值金额"
  434. })
  435. return
  436. }
  437. uni.showLoading({
  438. title: "加载中",
  439. mask: true,
  440. })
  441. this.submitForm={};
  442. if(this.moneyActiveClass){
  443. this.submitForm.chargingMarketingId=this.selectItem.id;
  444. }else{
  445. this.submitForm.amount=this.otherNum
  446. }
  447. if (this.recordId) {
  448. this.submitForm.recordId = this.recordId
  449. }
  450. //(this.submitForm)
  451. if(this.value2=="0"){
  452. this.wxpy()
  453. }else{
  454. this.alpy()
  455. }
  456. }
  457. },
  458. onShow() {
  459. // this.checkSubscribe()
  460. if (this.isReady) {
  461. this.init1()
  462. }
  463. }
  464. }
  465. </script>
  466. <style>
  467. page {
  468. background-color: #fff;
  469. }
  470. </style>
  471. <style lang="scss" scoped>
  472. // 优惠
  473. .discounts {
  474. width: 91.4%;
  475. //height: 200rpx;
  476. margin: 16rpx auto 0 auto;
  477. border-radius: 8px;
  478. overflow: hidden;
  479. img {
  480. width: 100%;
  481. height: 80px;
  482. }
  483. }
  484. .rightspan{
  485. float: right;
  486. color: rgba(102, 102, 102, 1);
  487. font-weight: 400;
  488. }
  489. .userBanner{
  490. margin: 16px;
  491. }
  492. ::v-deep .u-radio-group {
  493. width: 100%;
  494. }
  495. ::v-deep .u-radio {
  496. position: relative;
  497. }
  498. ::v-deep .u-radio__icon-wrap {
  499. position: absolute;
  500. right: 0;
  501. }
  502. .recharge {
  503. padding: 16px;
  504. .title {
  505. font-size: 16px;
  506. }
  507. p {
  508. color: #666;
  509. margin-top: 4px;
  510. }
  511. .self-stop.active{
  512. border: 1px solid;
  513. background-color: #EFFFF7;
  514. border-color: #00B962;
  515. color: #00B962;
  516. }
  517. .rechargeMain {
  518. display: flex;
  519. flex-wrap: wrap;
  520. justify-content: space-around;
  521. // justify-content: space-between;
  522. margin-top: 12px;
  523. margin-bottom: 20px;
  524. .recharge-item {
  525. width: 23%;
  526. border: 1px solid #e3e3e3;
  527. padding: 20rpx 0;
  528. border-radius: 4px;
  529. text-align: center;
  530. margin-bottom: 10px;
  531. font-size: 32rpx;
  532. position: relative;
  533. //margin-left: 5px;
  534. }
  535. .recharge-item-rk{
  536. width: 48%;
  537. padding-bottom: 0;
  538. .item-rk{
  539. margin-top: 20rpx;
  540. padding: 8rpx 0;
  541. background-color: rgba(232, 232, 232, 1);
  542. color: rgba(51, 51, 51, 1);
  543. font-size: 24rpx;
  544. }
  545. .item-rk-span{
  546. margin:0 4px ;
  547. color: #ec4530;
  548. }
  549. }
  550. .amount {
  551. // width: 41.9%;
  552. height: 16px;
  553. line-height: 15px;
  554. border-radius: 0px 4px 0px 4px;
  555. background-color: #ec4530;//rgba(0, 185, 98, 100)
  556. color: rgba(255, 255, 255, 100);
  557. font-size: 10px;
  558. text-align: center;
  559. position: absolute;
  560. top: 0;
  561. right: 0;
  562. }
  563. .active {
  564. background-color: #EFFFF7;
  565. border-color: #00B962;
  566. color: #00B962;
  567. .item-rk{
  568. background-color: #53B56B;
  569. color: #fff;
  570. }
  571. .item-rk-span{
  572. color: #fff;
  573. }
  574. }
  575. }
  576. }
  577. .recharge-input {
  578. margin-top: 8px;
  579. //margin-bottom: 32px;
  580. }
  581. .recharge-radio {
  582. margin-top: 10px;
  583. .recharge-radio-item {
  584. display: flex;
  585. align-items: center;
  586. }
  587. .recharge-radio-name {
  588. margin-left: 8px;
  589. }
  590. }
  591. .recharge-btn {
  592. position: fixed;
  593. left: 16px;
  594. right: 16px;
  595. bottom: 0px;
  596. background-color: #FFF;
  597. padding-bottom: 20px;
  598. }
  599. .success-btn {
  600. margin-top: 10px;
  601. background-color: #00B962 !important;
  602. flex: 1;
  603. border-color: #00B962 !important;
  604. color: #fff !important;
  605. }
  606. .nosuccess-btn {
  607. margin-top: 10px;
  608. background-color: #a7dbc2 !important;
  609. flex: 1;
  610. border-color: #a7dbc2 !important;
  611. color: #fff !important;
  612. }
  613. </style>