recharge.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528
  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. uni.showLoading({
  279. title: "加载中",
  280. mask: true,
  281. })
  282. Pay.alpay(this.submitForm).then((response) => {
  283. let qrcode = new QRCode('qrcode', {
  284. width: 200,
  285. height: 200,
  286. text: response.data.qr_code,
  287. correctLevel: QRCode.CorrectLevel.M,
  288. })
  289. this.outOrderNo=response.data.outOrderNo;
  290. var canvas = document.getElementsByTagName('canvas')[0];
  291. this.qrCodeImg = convertCanvasToImage(canvas);
  292. uni.hideLoading()
  293. this.showModel=true
  294. }).catch(error => {
  295. uni.showToast({
  296. title: error
  297. })
  298. })
  299. },
  300. wxpy(){
  301. Pay.wxpay(this.submitForm).then((response) => {
  302. if(!response.result){
  303. uni.showToast({
  304. title: response.message
  305. })
  306. return
  307. }
  308. var data = response.data
  309. uni.hideLoading()
  310. //("Pay+"+new Date().getTime())
  311. wxPayJs(data);
  312. }).catch(error => {
  313. uni.showToast({
  314. title: error
  315. })
  316. })
  317. },
  318. rechargeNow() {
  319. if(!this.checked){
  320. uni.showToast({
  321. title:"请同意《充值协议》后进行充值"
  322. })
  323. return
  324. }
  325. uni.showLoading({
  326. title: "加载中",
  327. mask: true,
  328. })
  329. this.submitForm={};
  330. if(!this.otherNum){
  331. this.submitForm.chargingMarketingId=this.selectItem.id;
  332. }else{
  333. this.submitForm.amount=this.otherNum
  334. }
  335. //(this.submitForm)
  336. if(this.value2=="0"){
  337. this.wxpy()
  338. }else{
  339. this.alpy()
  340. }
  341. }
  342. },
  343. onShow() {
  344. this.checkSubscribe()
  345. if (this.isReady) {
  346. this.init1()
  347. }
  348. }
  349. }
  350. </script>
  351. <style>
  352. page {
  353. background-color: #fff;
  354. }
  355. </style>
  356. <style lang="scss" scoped>
  357. .userBanner{
  358. margin: 16px;
  359. }
  360. /deep/.u-radio-group {
  361. width: 100%;
  362. }
  363. /deep/.u-radio {
  364. position: relative;
  365. }
  366. /deep/.u-radio__icon-wrap {
  367. position: absolute;
  368. right: 0;
  369. }
  370. .recharge {
  371. padding: 16px;
  372. .title {
  373. font-size: 16px;
  374. }
  375. p {
  376. color: #666;
  377. margin-top: 4px;
  378. }
  379. .self-stop.active{
  380. border: 1px solid;
  381. background-color: #EFFFF7;
  382. border-color: #00B962;
  383. color: #00B962;
  384. }
  385. .rechargeMain {
  386. display: flex;
  387. flex-wrap: wrap;
  388. // justify-content: space-between;
  389. margin-top: 12px;
  390. margin-bottom: 20px;
  391. .recharge-item {
  392. width: 31%;
  393. border: 1px solid #e3e3e3;
  394. padding: 15px 0;
  395. border-radius: 4px;
  396. text-align: center;
  397. margin-bottom: 10px;
  398. font-size: 16px;
  399. position: relative;
  400. margin-left: 5px;
  401. }
  402. .amount {
  403. // width: 41.9%;
  404. height: 16px;
  405. line-height: 15px;
  406. border-radius: 0px 4px 0px 4px;
  407. background-color: #ec4530;//rgba(0, 185, 98, 100)
  408. color: rgba(255, 255, 255, 100);
  409. font-size: 10px;
  410. text-align: center;
  411. position: absolute;
  412. top: 0;
  413. right: 0;
  414. }
  415. .active {
  416. background-color: #EFFFF7;
  417. border-color: #00B962;
  418. color: #00B962;
  419. }
  420. }
  421. }
  422. .recharge-input {
  423. margin-top: 8px;
  424. //margin-bottom: 32px;
  425. }
  426. .recharge-radio {
  427. margin-top: 10px;
  428. .recharge-radio-item {
  429. display: flex;
  430. align-items: center;
  431. }
  432. .recharge-radio-name {
  433. margin-left: 8px;
  434. }
  435. }
  436. .recharge-btn {
  437. position: fixed;
  438. left: 16px;
  439. right: 16px;
  440. bottom: 0px;
  441. background-color: #FFF;
  442. padding-bottom: 20px;
  443. }
  444. .success-btn {
  445. margin-top: 10px;
  446. background-color: #00B962 !important;
  447. flex: 1;
  448. border-color: #00B962 !important;
  449. color: #fff !important;
  450. }
  451. .nosuccess-btn {
  452. margin-top: 10px;
  453. background-color: #a7dbc2 !important;
  454. flex: 1;
  455. border-color: #a7dbc2 !important;
  456. color: #fff !important;
  457. }
  458. </style>