recharge.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526
  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. this.$nextTick(()=>{
  193. this.otherNum=text.substring(0,text.indexOf('.'))
  194. uni.showToast({
  195. title:"请输入正整数"
  196. })
  197. })
  198. }
  199. var t =Number(text);
  200. if(t<1){
  201. this.$nextTick(()=>{
  202. this.otherNum='';
  203. })
  204. }
  205. if(t>5000){
  206. this.$nextTick(()=>{
  207. this.otherNum=5000;
  208. })
  209. }
  210. },
  211. init1() {
  212. uni.showLoading({
  213. title: "加载中",
  214. mask: true,
  215. })
  216. API.personalCenter().then((res) => {
  217. this.detail = res.data
  218. this.isReady = true;
  219. uni.hideLoading()
  220. }).catch(error => {
  221. uni.showToast({
  222. title: error
  223. })
  224. })
  225. },
  226. init() {
  227. uni.showLoading({
  228. title: "加载中",
  229. mask: true,
  230. })
  231. var data = {
  232. type:2 };
  233. API.marketingData(data).then((res) => {
  234. this.moneyList = res.data.chargingMarketingList
  235. if (this.moneyList.length > 0) {
  236. this.selectItem = this.moneyList[0];
  237. this.moneyActiveClass = this.moneyList[0].id
  238. //(this.moneyActiveClass)
  239. }
  240. for(var i in this.moneyList){
  241. var item =this.moneyList[i]
  242. if(item.imgUrl){
  243. this.selectImg=item
  244. break
  245. }
  246. }
  247. uni.hideLoading()
  248. this.init1()
  249. }).catch(error => {
  250. uni.showToast({
  251. title: error
  252. })
  253. })
  254. },
  255. moneyClick(index,item) {
  256. this.moneyActiveClass = index;
  257. if(item){
  258. this.selectItem=item;
  259. if(item.imgUrl){
  260. this.selectImg=item
  261. }
  262. }
  263. },
  264. // 选中某个单选框时,由radio时触发
  265. radioChange(e) {
  266. // //(e);
  267. },
  268. // 选中任一radio时,由radio-group触发
  269. radioGroupChange(e) {
  270. // //(e);
  271. },
  272. checkboxChange() {
  273. this.checked = !this.checked;
  274. },
  275. alpy(){
  276. uni.showLoading({
  277. title: "加载中",
  278. mask: true,
  279. })
  280. Pay.alpay(this.submitForm).then((response) => {
  281. let qrcode = new QRCode('qrcode', {
  282. width: 200,
  283. height: 200,
  284. text: response.data.qr_code,
  285. correctLevel: QRCode.CorrectLevel.M,
  286. })
  287. this.outOrderNo=response.data.outOrderNo;
  288. var canvas = document.getElementsByTagName('canvas')[0];
  289. this.qrCodeImg = convertCanvasToImage(canvas);
  290. uni.hideLoading()
  291. this.showModel=true
  292. }).catch(error => {
  293. uni.showToast({
  294. title: error
  295. })
  296. })
  297. },
  298. wxpy(){
  299. Pay.wxpay(this.submitForm).then((response) => {
  300. if(!response.result){
  301. uni.showToast({
  302. title: response.message
  303. })
  304. return
  305. }
  306. var data = response.data
  307. uni.hideLoading()
  308. //("Pay+"+new Date().getTime())
  309. wxPayJs(data);
  310. }).catch(error => {
  311. uni.showToast({
  312. title: error
  313. })
  314. })
  315. },
  316. rechargeNow() {
  317. if(!this.checked){
  318. uni.showToast({
  319. title:"请同意《充值协议》后进行充值"
  320. })
  321. return
  322. }
  323. uni.showLoading({
  324. title: "加载中",
  325. mask: true,
  326. })
  327. this.submitForm={};
  328. if(!this.otherNum){
  329. this.submitForm.chargingMarketingId=this.selectItem.id;
  330. }else{
  331. this.submitForm.amount=this.otherNum
  332. }
  333. //(this.submitForm)
  334. if(this.value2=="0"){
  335. this.wxpy()
  336. }else{
  337. this.alpy()
  338. }
  339. }
  340. },
  341. onShow() {
  342. this.checkSubscribe()
  343. if (this.isReady) {
  344. this.init1()
  345. }
  346. }
  347. }
  348. </script>
  349. <style>
  350. page {
  351. background-color: #fff;
  352. }
  353. </style>
  354. <style lang="scss" scoped>
  355. .userBanner{
  356. margin: 16px;
  357. }
  358. /deep/.u-radio-group {
  359. width: 100%;
  360. }
  361. /deep/.u-radio {
  362. position: relative;
  363. }
  364. /deep/.u-radio__icon-wrap {
  365. position: absolute;
  366. right: 0;
  367. }
  368. .recharge {
  369. padding: 16px;
  370. .title {
  371. font-size: 16px;
  372. }
  373. p {
  374. color: #666;
  375. margin-top: 4px;
  376. }
  377. .self-stop.active{
  378. border: 1px solid;
  379. background-color: #EFFFF7;
  380. border-color: #00B962;
  381. color: #00B962;
  382. }
  383. .rechargeMain {
  384. display: flex;
  385. flex-wrap: wrap;
  386. // justify-content: space-between;
  387. margin-top: 12px;
  388. margin-bottom: 20px;
  389. .recharge-item {
  390. width: 31%;
  391. border: 1px solid #e3e3e3;
  392. padding: 15px 0;
  393. border-radius: 4px;
  394. text-align: center;
  395. margin-bottom: 10px;
  396. font-size: 16px;
  397. position: relative;
  398. margin-left: 5px;
  399. }
  400. .amount {
  401. // width: 41.9%;
  402. height: 16px;
  403. line-height: 15px;
  404. border-radius: 0px 4px 0px 4px;
  405. background-color: #ec4530;//rgba(0, 185, 98, 100)
  406. color: rgba(255, 255, 255, 100);
  407. font-size: 10px;
  408. text-align: center;
  409. position: absolute;
  410. top: 0;
  411. right: 0;
  412. }
  413. .active {
  414. background-color: #EFFFF7;
  415. border-color: #00B962;
  416. color: #00B962;
  417. }
  418. }
  419. }
  420. .recharge-input {
  421. margin-top: 8px;
  422. //margin-bottom: 32px;
  423. }
  424. .recharge-radio {
  425. margin-top: 10px;
  426. .recharge-radio-item {
  427. display: flex;
  428. align-items: center;
  429. }
  430. .recharge-radio-name {
  431. margin-left: 8px;
  432. }
  433. }
  434. .recharge-btn {
  435. position: fixed;
  436. left: 16px;
  437. right: 16px;
  438. bottom: 0px;
  439. background-color: #FFF;
  440. padding-bottom: 20px;
  441. }
  442. .success-btn {
  443. margin-top: 10px;
  444. background-color: #00B962 !important;
  445. flex: 1;
  446. border-color: #00B962 !important;
  447. color: #fff !important;
  448. }
  449. .nosuccess-btn {
  450. margin-top: 10px;
  451. background-color: #a7dbc2 !important;
  452. flex: 1;
  453. border-color: #a7dbc2 !important;
  454. color: #fff !important;
  455. }
  456. </style>