recharge.vue 18 KB

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