recharge.vue 12 KB

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