recharge.vue 14 KB

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