recharge.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604
  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"
  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&&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? '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. getBannerInfo(code){
  166. newsApi.getBannerInfo(code).then((res) => {
  167. this.bannerList =res.data;
  168. // document.getElementsByClassName("uni-swiper-wrapper")[0].parentNode.style="background-color: rgb(255, 255, 255); height: 300px;"
  169. }).catch(error => {
  170. uni.showToast({
  171. title: error,icon: "none"
  172. })
  173. })
  174. },
  175. focus(){
  176. console.log(0)
  177. uni.pageScrollTo({
  178. scrollTop:999999,
  179. duration:0
  180. })
  181. },
  182. gotoGz(){
  183. this.carhelp.setGzDate()
  184. var url = process.car.gzUrl;
  185. window.location.href=url
  186. },
  187. checkSubscribe(){
  188. API_weixin.checkSubscribe({
  189. openId: this.carhelp.getOpenId()
  190. }).then((res) => {
  191. if(res.data=="0"){
  192. this.show1=true
  193. }else{
  194. //this.init();
  195. this.show2=true;
  196. //this.carhelp.setGzDate()
  197. }
  198. //setGzDate
  199. }).catch(error => {
  200. uni.showToast({
  201. title: error
  202. })
  203. })
  204. },
  205. confirm(){
  206. uni.redirectTo({
  207. url:"/pages/user/finance/rechargeRes?id="+this.outOrderNo
  208. })
  209. },
  210. ckInput(text){
  211. if(text.indexOf('.')>0){
  212. var k =text.split(".")[1]
  213. if(k.length>=3){
  214. this.$nextTick(()=>{
  215. text=parseFloat(text).toFixed(2);
  216. this.otherNum= text
  217. })
  218. }
  219. }
  220. var t =Number(text);
  221. if(t<1){
  222. this.$nextTick(()=>{
  223. this.otherNum='';
  224. })
  225. }
  226. if(t>5000){
  227. this.$nextTick(()=>{
  228. this.otherNum=5000;
  229. })
  230. }
  231. },
  232. init1() {
  233. uni.showLoading({
  234. title: "加载中",
  235. mask: true,
  236. })
  237. API.personalCenter().then((res) => {
  238. this.detail = res.data
  239. this.isReady = true;
  240. uni.hideLoading()
  241. }).catch(error => {
  242. uni.showToast({
  243. title: error
  244. })
  245. })
  246. },
  247. init() {
  248. uni.showLoading({
  249. title: "加载中",
  250. mask: true,
  251. })
  252. var data = {
  253. type:2 };
  254. API.marketingData(data).then((res) => {
  255. this.moneyList = res.data.chargingMarketingList
  256. if (this.moneyList.length > 0) {
  257. this.selectItem = this.moneyList[0];
  258. this.moneyActiveClass = this.moneyList[0].id
  259. //(this.moneyActiveClass)
  260. }
  261. for(var i in this.moneyList){
  262. var item =this.moneyList[i]
  263. if(item.imgUrl){
  264. this.selectImg=item
  265. break
  266. }
  267. }
  268. uni.hideLoading()
  269. this.init1()
  270. }).catch(error => {
  271. uni.showToast({
  272. title: error
  273. })
  274. })
  275. },
  276. moneyClick(index,item) {
  277. this.otherNum='';
  278. this.moneyActiveClass = index;
  279. if(item){
  280. this.selectItem=item;
  281. if(item.imgUrl){
  282. this.selectImg=item
  283. }
  284. }
  285. },
  286. // 选中某个单选框时,由radio时触发
  287. radioChange(e) {
  288. // //(e);
  289. },
  290. // 选中任一radio时,由radio-group触发
  291. radioGroupChange(e) {
  292. // //(e);
  293. },
  294. checkboxChange() {
  295. this.checked = !this.checked;
  296. },
  297. alpy(){
  298. var obj={
  299. ...this.submitForm
  300. }
  301. if(obj.amount){
  302. for(var i in this.moneyList){
  303. var item =this.moneyList[i]
  304. if(item.rechargeAmount==obj.amount){
  305. delete obj.amount;
  306. obj.chargingMarketingId=item.id
  307. break
  308. }
  309. }
  310. }
  311. uni.showLoading({
  312. title: "加载中",
  313. mask: true,
  314. })
  315. Pay.alpay(obj).then((response) => {
  316. let qrcode = new QRCode('qrcode', {
  317. width: 200,
  318. height: 200,
  319. text: response.data.qr_code,
  320. correctLevel: QRCode.CorrectLevel.M,
  321. })
  322. this.outOrderNo=response.data.outOrderNo;
  323. var canvas = document.getElementsByTagName('canvas')[0];
  324. this.qrCodeImg = convertCanvasToImage(canvas);
  325. uni.hideLoading()
  326. this.showModel=true
  327. }).catch(error => {
  328. uni.showToast({
  329. title: error
  330. })
  331. })
  332. },
  333. wxpy(){
  334. var obj={
  335. ...this.submitForm
  336. }
  337. if(obj.amount){
  338. for(var i in this.moneyList){
  339. var item =this.moneyList[i]
  340. if(item.rechargeAmount==obj.amount){
  341. delete obj.amount;
  342. obj.chargingMarketingId=item.id
  343. break
  344. }
  345. }
  346. }
  347. //this.moneyList
  348. Pay.wxpay(obj).then((response) => {
  349. if(!response.result){
  350. uni.showToast({
  351. title: response.message
  352. })
  353. return
  354. }
  355. var data = response.data
  356. uni.hideLoading()
  357. //("Pay+"+new Date().getTime())
  358. wxPayJs(data);
  359. }).catch(error => {
  360. uni.showToast({
  361. title: error
  362. })
  363. })
  364. },
  365. rechargeNow() {
  366. if(!this.checked){
  367. uni.showToast({
  368. title:"请同意《充值协议》后进行充值"
  369. })
  370. return
  371. }
  372. uni.showLoading({
  373. title: "加载中",
  374. mask: true,
  375. })
  376. this.submitForm={};
  377. if(!this.otherNum){
  378. this.submitForm.chargingMarketingId=this.selectItem.id;
  379. }else{
  380. this.submitForm.amount=this.otherNum
  381. }
  382. if (this.recordId) {
  383. this.submitForm.recordId = this.recordId
  384. }
  385. //(this.submitForm)
  386. if(this.value2=="0"){
  387. this.wxpy()
  388. }else{
  389. this.alpy()
  390. }
  391. }
  392. },
  393. onShow() {
  394. // this.checkSubscribe()
  395. if (this.isReady) {
  396. this.init1()
  397. }
  398. }
  399. }
  400. </script>
  401. <style>
  402. page {
  403. background-color: #fff;
  404. }
  405. </style>
  406. <style lang="scss" scoped>
  407. // 优惠
  408. .discounts {
  409. width: 91.4%;
  410. //height: 200rpx;
  411. margin: 16rpx auto 0 auto;
  412. border-radius: 8px;
  413. overflow: hidden;
  414. img {
  415. width: 100%;
  416. height: 80px;
  417. }
  418. }
  419. .rightspan{
  420. float: right;
  421. }
  422. .userBanner{
  423. margin: 16px;
  424. }
  425. ::v-deep.u-radio-group {
  426. width: 100%;
  427. }
  428. ::v-deep.u-radio {
  429. position: relative;
  430. }
  431. ::v-deep.u-radio__icon-wrap {
  432. position: absolute;
  433. right: 0;
  434. }
  435. .recharge {
  436. padding: 16px;
  437. .title {
  438. font-size: 16px;
  439. }
  440. p {
  441. color: #666;
  442. margin-top: 4px;
  443. }
  444. .self-stop.active{
  445. border: 1px solid;
  446. background-color: #EFFFF7;
  447. border-color: #00B962;
  448. color: #00B962;
  449. }
  450. .rechargeMain {
  451. display: flex;
  452. flex-wrap: wrap;
  453. // justify-content: space-between;
  454. margin-top: 12px;
  455. margin-bottom: 20px;
  456. .recharge-item {
  457. width: 31%;
  458. border: 1px solid #e3e3e3;
  459. padding: 15px 0;
  460. border-radius: 4px;
  461. text-align: center;
  462. margin-bottom: 10px;
  463. font-size: 16px;
  464. position: relative;
  465. margin-left: 5px;
  466. }
  467. .amount {
  468. // width: 41.9%;
  469. height: 16px;
  470. line-height: 15px;
  471. border-radius: 0px 4px 0px 4px;
  472. background-color: #ec4530;//rgba(0, 185, 98, 100)
  473. color: rgba(255, 255, 255, 100);
  474. font-size: 10px;
  475. text-align: center;
  476. position: absolute;
  477. top: 0;
  478. right: 0;
  479. }
  480. .active {
  481. background-color: #EFFFF7;
  482. border-color: #00B962;
  483. color: #00B962;
  484. }
  485. }
  486. }
  487. .recharge-input {
  488. margin-top: 8px;
  489. //margin-bottom: 32px;
  490. }
  491. .recharge-radio {
  492. margin-top: 10px;
  493. .recharge-radio-item {
  494. display: flex;
  495. align-items: center;
  496. }
  497. .recharge-radio-name {
  498. margin-left: 8px;
  499. }
  500. }
  501. .recharge-btn {
  502. position: fixed;
  503. left: 16px;
  504. right: 16px;
  505. bottom: 0px;
  506. background-color: #FFF;
  507. padding-bottom: 20px;
  508. }
  509. .success-btn {
  510. margin-top: 10px;
  511. background-color: #00B962 !important;
  512. flex: 1;
  513. border-color: #00B962 !important;
  514. color: #fff !important;
  515. }
  516. .nosuccess-btn {
  517. margin-top: 10px;
  518. background-color: #a7dbc2 !important;
  519. flex: 1;
  520. border-color: #a7dbc2 !important;
  521. color: #fff !important;
  522. }
  523. </style>