recharge.vue 11 KB

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