recharge.vue 11 KB

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