phone.vue 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421
  1. <template>
  2. <view class="center">
  3. <view class="status_bar"><!-- 这里是状态栏 --></view>
  4. <view class="content-money">
  5. <view class="body-title">
  6. <view class="goback-box" @click="toBack"><image class="goback" src="../../static/icon/fanhui.png" mode=""></image></view>
  7. <view class="header">充值中心</view>
  8. </view>
  9. <view class="content-bg"></view>
  10. <view class="phone">
  11. <view class="phone-title">充值号码</view>
  12. <view class="input"><input type="text" value="phone" v-model="phone" placeholder="请输入充值号码" placeholder-class="input" /></view>
  13. </view>
  14. </view>
  15. <view class="main-box">
  16. <view class="main-title">请选择充值套餐</view>
  17. <view class="main">
  18. <view class="main-item" v-for="(item, index) in moneyList" :class="{ current: id === item.id }" :key="index" @click="change(item)">
  19. <view class="num">
  20. {{ item.get_money }}
  21. <text>元</text>
  22. </view>
  23. <view class="yuan">售价{{ item.price }}元</view>
  24. </view>
  25. </view>
  26. <view class="zj">
  27. <view class="zj-left">
  28. 应付金额
  29. </view>
  30. <view class="zj-right">
  31. ¥{{money}}元
  32. </view>
  33. </view>
  34. </view>
  35. <view class="list">
  36. <radio-group @change="tabRadio">
  37. <!-- #ifdef APP-PLUS -->
  38. <label>
  39. <view class="box">
  40. <view class="icon iconfont iconzhifubao"></view>
  41. <view class="title-box">
  42. <view class="title"><text>支付宝充值</text></view>
  43. </view>
  44. <view class="right"><radio value="ali" color="#EB001C" :checked="type == 'ali'" /></view>
  45. </view>
  46. </label>
  47. <!-- #endif -->
  48. <label>
  49. <view class="box">
  50. <view class="icon iconfont iconweixin1"></view>
  51. <view class="title-box">
  52. <view class="title"><text>微信充值</text></view>
  53. </view>
  54. <view class="right"><radio value="weixin" color=" #EB001C" :checked="type == 'weixin'" /></view>
  55. </view>
  56. </label>
  57. </radio-group>
  58. </view>
  59. <!-- <view class="explain">
  60. <view class="explain-left">
  61. 充值说明
  62. </view>
  63. <view class="explain-right">
  64. </view>
  65. </view> -->
  66. <view class="btn" @click="!payLoding ? confirm() : ''">
  67. 立即充值
  68. </view>
  69. </view>
  70. </template>
  71. <script>
  72. // #ifdef H5
  73. import { rechargePhoneWechat, getPhone } from '@/api/wallet.js';
  74. // #endif
  75. // #ifdef APP-PLUS
  76. import { rechargePhontApp, rechargePhoneAli, getPhone } from '@/api/wallet.js';
  77. // #endif
  78. import { mapState } from 'vuex';
  79. export default {
  80. data() {
  81. return {
  82. phone: '',
  83. id: '',
  84. money:'',
  85. payLoding: false, //是否加载中
  86. type: 'weixin',
  87. moneyList: []
  88. };
  89. },
  90. onLoad() {
  91. this.loadData();
  92. },
  93. computed: {
  94. // #ifdef H5
  95. ...mapState(['weichatObj']),
  96. // #endif
  97. },
  98. methods: {
  99. // 点击返回 我的页面
  100. toBack() {
  101. uni.navigateBack({});
  102. },
  103. loadData() {
  104. getPhone({}).then(({data}) =>{
  105. this.moneyList = data.recharge_quota;
  106. this.id = data.recharge_quota[0].id;
  107. this.money = data.recharge_quota[0].price;
  108. console.log(data);
  109. })
  110. },
  111. change(money){
  112. this.money = money.price;
  113. this.id = money.id;
  114. },
  115. // 切换选中对象
  116. tabRadio(e) {
  117. this.type = e;
  118. },
  119. confirm() {
  120. let obj = this;
  121. if(obj.phone == ''){
  122. obj.$api.msg("请填写要充值的号码")
  123. return;
  124. }
  125. obj.payLoding = true;
  126. // #ifdef H5
  127. rechargePhoneWechat({ rechar_id: this.id, mobile: this.phone })
  128. .then(e => {
  129. let da = e.data.data;
  130. obj.weichatObj.chooseWXPay({
  131. timestamp: da.timestamp,
  132. nonceStr: da.nonceStr,
  133. package: da.package,
  134. signType: da.signType,
  135. paySign: da.paySign,
  136. success: function(res) {
  137. uni.showToast({
  138. title: '充值成功',
  139. duration: 2000,
  140. position: 'top'
  141. });
  142. }
  143. });
  144. obj.payLoding = false;
  145. })
  146. .catch(e => {
  147. obj.payLoding = false;
  148. console.log(e);
  149. });
  150. // #endif
  151. // #ifdef APP-PLUS
  152. if (this.type == 'weixin') {
  153. rechargePhontApp({ rechar_id: this.id, mobile: this.phone })
  154. .then(e => {
  155. let da = e.data;
  156. let data = {
  157. appid: da.appid,
  158. noncestr: da.noncestr,
  159. package: da.package,
  160. partnerid: da.partnerid,
  161. prepayid: da.prepayid,
  162. timestamp: da.timestamp,
  163. sign: da.sign
  164. };
  165. uni.requestPayment({
  166. provider: 'wxpay',
  167. orderInfo: data,
  168. success(res) {
  169. console.log(res);
  170. },
  171. fail(res) {
  172. console.log('微信掉起失败');
  173. console.log(res, '失败');
  174. }
  175. });
  176. obj.payLoding = false;
  177. })
  178. .catch(e => {
  179. obj.payLoding = false;
  180. console.log(e);
  181. });
  182. } else {
  183. rechargePhoneAli({ rechar_id: this.id, mobile: this.phone }).then(e => {
  184. console.log(e, 'url');
  185. const url = e.msg;
  186. uni.requestPayment({
  187. provider: 'alipay',
  188. orderInfo: url,
  189. success: res => {
  190. console.log(res);
  191. uni.showToast({
  192. title: '支付成功',
  193. duration: 2000
  194. });
  195. },
  196. fail: e => {
  197. console.log(e);
  198. },
  199. complete: () => {}
  200. });
  201. obj.payLoding = false;
  202. }).catch(e =>{
  203. obj.payLoding = false;
  204. });
  205. }
  206. // #endif
  207. },
  208. }
  209. };
  210. </script>
  211. <style lang="scss">
  212. page,.center {
  213. background: #f1f1f1;
  214. height: 100%;
  215. padding-bottom: 30rpx;
  216. }
  217. .status_bar {
  218. height: var(--status-bar-height);
  219. width: 100%;
  220. }
  221. .content-money {
  222. padding-bottom: 30rpx;
  223. position: relative;
  224. height: 520rpx;
  225. .content-bg {
  226. position: absolute;
  227. top: 0;
  228. left: 0;
  229. right: 0;
  230. width: 750rpx;
  231. height: 520rpx;
  232. background: linear-gradient(30deg, #2e58ff, #33eeff);
  233. border-bottom-right-radius: 35%;
  234. border-bottom-left-radius: 35%;
  235. }
  236. .body-title {
  237. height: 80rpx;
  238. text-align: center;
  239. font-size: 35rpx;
  240. position: relative;
  241. .header {
  242. position: absolute;
  243. left: 0;
  244. top: 0;
  245. width: 100%;
  246. font-size: 36rpx;
  247. font-family: PingFang SC;
  248. font-weight: bold;
  249. color: #fffeff;
  250. height: 80rpx;
  251. font-size: 36rpx;
  252. font-weight: 700;
  253. z-index: 9;
  254. display: flex;
  255. justify-content: center;
  256. align-items: center;
  257. }
  258. .goback-box {
  259. position: absolute;
  260. left: 18rpx;
  261. top: 0;
  262. height: 80rpx;
  263. display: flex;
  264. align-items: center;
  265. }
  266. .goback {
  267. z-index: 100;
  268. width: 34rpx;
  269. height: 34rpx;
  270. }
  271. }
  272. }
  273. .phone {
  274. position: relative;
  275. z-index: 10;
  276. padding: 50rpx 27rpx 0;
  277. .phone-title {
  278. font-size: 26rpx;
  279. font-family: PingFang SC;
  280. font-weight: bold;
  281. color: #ffffff;
  282. }
  283. .input {
  284. font-size: 28rpx;
  285. font-family: PingFang SC;
  286. font-weight: bold;
  287. color: #ffffff;
  288. margin-top: 20rpx;
  289. padding-bottom: 20rpx;
  290. border-bottom: 1px solid #e5e5e5;
  291. }
  292. }
  293. .main-box {
  294. position: relative;
  295. z-index: 10;
  296. width: 694rpx;
  297. background: #ffffff;
  298. box-shadow: 0px 0px 20rpx 0px rgba(50, 50, 52, 0.06);
  299. border-radius: 20rpx;
  300. margin: -200rpx auto 0;
  301. padding: 30rpx;
  302. .main-title {
  303. font-size: 28rpx;
  304. font-family: PingFang SC;
  305. font-weight: bold;
  306. color: #010101;
  307. }
  308. .main {
  309. padding-top: 14rpx;
  310. display: flex;
  311. justify-content: space-between;
  312. flex-wrap: wrap;
  313. align-items: center;
  314. .current {
  315. background: linear-gradient(0deg, #2e58ff, #32c6ff) !important;
  316. .num,.yuan{
  317. color: #FFFFFF !important;
  318. }
  319. }
  320. .main-item {
  321. margin-top: 14rpx;
  322. line-height: 1;
  323. width: 204rpx;
  324. height: 130rpx;
  325. background: #d6e9ff;
  326. border-radius: 7rpx;
  327. display: flex;
  328. flex-direction: column;
  329. justify-content: center;
  330. align-items: center;
  331. .num {
  332. font-size: 36rpx;
  333. font-family: PingFang SC;
  334. font-weight: bold;
  335. color: #2e58ff;
  336. text {
  337. display: inline-block;
  338. padding-left: 8rpx;
  339. font-size: 26rpx;
  340. }
  341. }
  342. .yuan {
  343. margin-top: 18rpx;
  344. font-size: 20rpx;
  345. font-family: PingFang SC;
  346. font-weight: bold;
  347. color: #999999;
  348. }
  349. }
  350. }
  351. .zj {
  352. margin-top: 26rpx;
  353. display: flex;
  354. justify-content: space-between;
  355. align-items: center;
  356. .zj-left {
  357. font-size: 28rpx;
  358. font-family: PingFang SC;
  359. font-weight: bold;
  360. color: #333333;
  361. }
  362. .zj-right {
  363. font-size: 28rpx;
  364. font-family: PingFang SC;
  365. font-weight: bold;
  366. color: #FF0000;
  367. }
  368. }
  369. }
  370. .list {
  371. padding-left: 30rpx;
  372. margin-top: 30rpx;
  373. background-color: #ffffff;
  374. .box {
  375. display: flex;
  376. align-items: center;
  377. width: 100%;
  378. height: 120rpx;
  379. border-bottom: 1px solid $border-color-light;
  380. .icon {
  381. font-size: 48rpx;
  382. padding-right: 20rpx;
  383. }
  384. .iconweixin1 {
  385. color: #18bf16;
  386. }
  387. .iconzhifubao {
  388. color: #08aaec;
  389. }
  390. .title-box {
  391. flex-grow: 1;
  392. text-align: left;
  393. .title {
  394. font-size: $font-base + 2rpx;
  395. color: $font-color-base;
  396. }
  397. .node {
  398. font-size: $font-sm;
  399. color: $font-color-light;
  400. }
  401. }
  402. }
  403. }
  404. .btn {
  405. margin: 200rpx auto 0;
  406. width: 696rpx;
  407. height: 84rpx;
  408. background: linear-gradient(0deg, #2E58FF, #32C6FF);
  409. border-radius: 42rpx;
  410. text-align: center;
  411. line-height: 84rpx;
  412. font-size: 32rpx;
  413. font-family: PingFang SC;
  414. font-weight: bold;
  415. color: #FFFFFF;
  416. }
  417. </style>