recharge.vue 18 KB

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