recharge.vue 9.0 KB

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