recharge.vue 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486
  1. <template>
  2. <view class="content">
  3. <view class="bg">
  4. </view>
  5. <view class="listBox">
  6. <view class="list flex">
  7. <view @click="changeMoney(index)" :class="{action:index==actionIndex}" class="item flex"
  8. v-for="(item,index) in moneyList">
  9. <text>{{item.price}}元</text>
  10. </view>
  11. </view>
  12. <view class="flex inputBox">
  13. <text class="text">自定义金额</text>
  14. <input class="input" type="number" v-model="money" />
  15. <text>元</text>
  16. </view>
  17. </view>
  18. <view class="yt-list">
  19. <view class="yt-list-cell b-b" v-if="fx" @click="type='wxpay'">
  20. <view class="cell-tit flex">
  21. <image class="orderIcon" src="../../../static/icon/orderWx.png" mode="widthFix"></image>
  22. <text class="margin-l-10">微信支付</text>
  23. </view>
  24. <image class="checked" v-if="type=='wxpay'" src="../../../static/icon/addressIconXz.png"
  25. mode="widthFix"></image>
  26. <view v-else class="noChecked"></view>
  27. </view>
  28. <!-- #ifdef APP-PLUS -->
  29. <view class="yt-list-cell b-b" @click="type='alipay'">
  30. <view class="cell-tit flex">
  31. <image class="orderIcon" src="../../../static/icon/orderAli.png" mode="widthFix"></image>
  32. <text class="margin-l-10">支付宝</text>
  33. </view>
  34. <image class="checked" v-if="type=='alipay'" src="../../../static/icon/addressIconXz.png"
  35. mode="widthFix">
  36. </image>
  37. <view v-else class="noChecked"></view>
  38. </view>
  39. <!-- #endif -->
  40. <!-- <view class="yt-list-cell b-b" @click="type='commission'">
  41. <view class="cell-tit flex">
  42. <image class="orderIcon" src="../../../static/icon/ye.png" mode="widthFix"></image>
  43. <text class="margin-l-10">佣金({{commissionMoney}})</text>
  44. </view>
  45. <image class="checked" v-if="type=='commission'" src="../../../static/icon/addressIconXz.png"
  46. mode="widthFix">
  47. </image>
  48. <view v-else class="noChecked"></view>
  49. </view> -->
  50. </view>
  51. <view class="base-buttom" :class="{ 'active-bg': payLoding }" @click="!payLoding ? confirm() : ''">确认充值</view>
  52. </view>
  53. </template>
  54. <script>
  55. import {
  56. mapState
  57. } from 'vuex';
  58. import {
  59. commissionPay
  60. } from '@/api/wallet.js';
  61. // #ifdef APP
  62. import {
  63. aliPay,
  64. wxPay
  65. } from '@/api/wallet.js';
  66. // #endif
  67. // #ifdef H5
  68. import weixinObj from "@/plugin/jweixin-module/index.js";
  69. import {
  70. rechargeWechat
  71. } from '@/api/wallet.js';
  72. // #endif
  73. // #ifdef MP
  74. import {
  75. rechargeRoutine
  76. } from '@/api/wallet.js';
  77. // #endif
  78. import {
  79. rechargeIndex,
  80. spreadCommission,
  81. extractBank
  82. } from '@/api/wallet.js';
  83. export default {
  84. data() {
  85. return {
  86. actionIndex: 0, //当前选中的充值金额对象
  87. type: 'alipay',
  88. money: '', //充值金额
  89. payLoding: false, //是否加载中
  90. moneyList: [],
  91. commissionMoney: 0, //可提现佣金
  92. };
  93. },
  94. onLoad(options) {
  95. this.rechargeIndex();
  96. this.extractBank();
  97. console.log("s");
  98. },
  99. computed:{
  100. ...mapState(['fx'])
  101. },
  102. methods: {
  103. //获取用户金额信息
  104. extractBank() {
  105. extractBank({}).then(({
  106. data
  107. }) => {
  108. // 保存佣金信息
  109. this.commissionMoney = data.commissionCount;
  110. });
  111. },
  112. // 金额修改
  113. changeMoney(ind) {
  114. this.actionIndex = ind;
  115. this.money = this.moneyList[ind].price
  116. },
  117. // 查询金额列表
  118. rechargeIndex() {
  119. rechargeIndex().then((e) => {
  120. this.moneyList = e.data.recharge_quota.map((e) => {
  121. e.price = +e.price;
  122. return e
  123. });
  124. // 设置默认金额值
  125. this.money = this.moneyList[0].price
  126. console.log(e);
  127. })
  128. },
  129. // 跳转
  130. navTo(url) {
  131. uni.navigateTo({
  132. url: url
  133. });
  134. },
  135. // 提交
  136. confirm() {
  137. const that = this;
  138. if (that.money < (+that.moneyList[0].price)) {
  139. uni.showModal({
  140. title: '失败',
  141. content: '充值金额不可以低于¥' + that.moneyList[0].price,
  142. showCancel: false
  143. });
  144. return
  145. }
  146. that.payLoding = true;
  147. let pushData = {
  148. price: this.money,
  149. // #ifdef H5
  150. from: 'weixin',
  151. // #endif
  152. // #ifdef APP
  153. from: 'app',
  154. // #endif
  155. }
  156. // 佣金转余额
  157. if (that.type == 'commission') {
  158. that.commissionPay(pushData)
  159. return
  160. }
  161. // 微信支付
  162. if (that.type == 'wxpay') {
  163. that.wxpay(pushData)
  164. return
  165. }
  166. // #ifdef APP
  167. // 支付宝支付
  168. if (that.type == 'alipay') {
  169. console.log('ali');
  170. that.alipay(pushData)
  171. return
  172. }
  173. // #endif
  174. // 微信支付
  175. },
  176. commissionPay(pushData) {
  177. const that = this;
  178. commissionPay(pushData).then((e) => {
  179. that.payLoding = false;
  180. if (e.status == 200) {
  181. that.extractBank()
  182. uni.redirectTo({
  183. url: './paySuccess?type=1'
  184. });
  185. return
  186. }
  187. uni.showToast({
  188. title: e.msg
  189. });
  190. }).catch(() => {
  191. that.payLoding = false;
  192. })
  193. },
  194. // #ifdef APP-PLUS
  195. alipay(pushData) {
  196. const that = this;
  197. aliPay(pushData).then((e) => {
  198. console.log(e.data.data,'jie');
  199. let orderInfo={};
  200. that.payLoding = true;
  201. uni.requestPayment({
  202. provider: that.type,
  203. orderInfo:e.data.data,
  204. success(e) {
  205. uni.redirectTo({
  206. url: './paySuccess?type=1'
  207. });
  208. },fail(e) {
  209. console.log(e);
  210. }
  211. })
  212. }).catch(e => {
  213. that.payLoding = false;
  214. console.log(e,'cuowu');
  215. });
  216. },
  217. // #endif
  218. wxpay(pushData) {
  219. const that = this;
  220. // #ifdef H5
  221. console.log(pushData);
  222. rechargeWechat(pushData)
  223. .then(e => {
  224. let da = e.data;
  225. that.payLoding = false;
  226. weixinObj.chooseWXPay({
  227. timestamp: da.timestamp,
  228. nonceStr: da.nonceStr,
  229. package: da.package,
  230. signType: da.signType,
  231. paySign: da.paySign,
  232. success: function(res) {
  233. uni.redirectTo({
  234. url: './paySuccess?type=1'
  235. });
  236. },
  237. });
  238. })
  239. .catch(e => {
  240. that.payLoding = false;
  241. console.log(e);
  242. });
  243. // #endif
  244. // #ifdef MP
  245. rechargeRoutine(pushData)
  246. .then(e => {
  247. let da = e.data;
  248. wx.requestPayment({
  249. timeStamp: da.timestamp,
  250. nonceStr: da.nonceStr,
  251. package: da.package,
  252. signType: da.signType,
  253. paySign: da.paySign,
  254. success: function(res) {
  255. uni.redirectTo({
  256. url: './paySuccess?type=1'
  257. });
  258. }
  259. })
  260. that.payLoding = false;
  261. })
  262. .catch(e => {
  263. that.payLoding = false;
  264. console.log(e);
  265. });
  266. // #endif
  267. // #ifdef APP
  268. wxPay(pushData).then((res) => {
  269. console.log(res.data,'充值');
  270. that.payLoding = true;
  271. uni.requestPayment({
  272. provider: that.type,
  273. orderInfo: res.data,
  274. success(e) {
  275. uni.redirectTo({
  276. url: './paySuccess?type=1'
  277. });
  278. },
  279. fail(e) {
  280. console.log('错误', e);
  281. }
  282. })
  283. }).catch(e => {
  284. that.payLoding = false;
  285. console.log(e);
  286. });
  287. // #endif
  288. }
  289. }
  290. };
  291. </script>
  292. <style lang="scss">
  293. .yt-list {
  294. background: #fff;
  295. margin: 0 $page-row-spacing;
  296. margin-top: 30rpx;
  297. border-radius: 20rpx;
  298. .yt-list-cell {
  299. display: flex;
  300. align-items: center;
  301. justify-content: space-between;
  302. padding: 10rpx 30rpx 10rpx 40rpx;
  303. line-height: 70rpx;
  304. position: relative;
  305. .checked,
  306. .noChecked {
  307. width: 36rpx;
  308. height: 36rpx;
  309. }
  310. .noChecked {
  311. border: 1px solid $font-color-light;
  312. border-radius: 100rpx;
  313. }
  314. &.cell-hover {
  315. background: #fafafa;
  316. }
  317. &.b-b:after {
  318. left: 30rpx;
  319. }
  320. .cell-icon {
  321. height: 32rpx;
  322. width: 32rpx;
  323. font-size: 22rpx;
  324. color: #fff;
  325. text-align: center;
  326. line-height: 32rpx;
  327. background: #f85e52;
  328. border-radius: 4rpx;
  329. margin-right: 12rpx;
  330. &.hb {
  331. background: #ffaa0e;
  332. }
  333. &.lpk {
  334. background: #3ab54a;
  335. }
  336. }
  337. .cell-more {
  338. align-self: center;
  339. font-size: 24rpx;
  340. color: $font-color-light;
  341. margin-left: 8rpx;
  342. margin-right: -10rpx;
  343. }
  344. .cell-tit {
  345. font-size: 26rpx;
  346. color: $font-color-light;
  347. margin-right: 10rpx;
  348. .orderIcon {
  349. width: 48rpx;
  350. }
  351. }
  352. .cell-tip {
  353. font-size: 26rpx;
  354. color: $font-color-dark;
  355. &.disabled {
  356. color: $font-color-light;
  357. }
  358. &.active {
  359. color: $base-color;
  360. }
  361. &.red {
  362. color: $base-color;
  363. }
  364. }
  365. &.desc-cell {
  366. .cell-tit {
  367. max-width: 90rpx;
  368. }
  369. }
  370. .desc {
  371. text-align: right;
  372. font-size: $font-base;
  373. color: $font-color-light;
  374. }
  375. }
  376. }
  377. page {
  378. height: 100%;
  379. }
  380. .content {
  381. padding-top: 30rpx;
  382. }
  383. .active-bg {
  384. background-color: $color-gray !important;
  385. }
  386. .listBox {
  387. margin: 30rpx;
  388. margin-top: 0;
  389. border-radius: 20rpx;
  390. padding: 20rpx;
  391. background-color: #FFFFFF;
  392. position: relative;
  393. padding-bottom: 30rpx;
  394. .inputBox {
  395. font-size: 28rpx;
  396. font-weight: bold;
  397. color: $font-color-base;
  398. margin: 0 20rpx;
  399. .text {
  400. flex-shrink: 0;
  401. }
  402. .input {
  403. border-bottom: 1px solid $font-color-disabled;
  404. flex-grow: 1;
  405. margin: 0 10rpx;
  406. height: 30rpx;
  407. text-align: center;
  408. }
  409. }
  410. }
  411. .list {
  412. padding-top: 10rpx;
  413. flex-wrap: wrap;
  414. .item {
  415. justify-content: center;
  416. width: 210rpx;
  417. height: 100rpx;
  418. margin-bottom: 20rpx;
  419. background-color: #F5F5F5;
  420. border-radius: 20rpx;
  421. font-size: 28rpx;
  422. font-weight: bold;
  423. color: $font-color-base;
  424. border: 1px solid #F5F5F5;
  425. &.action {
  426. border: 1px solid $color-green;
  427. color: $color-green;
  428. }
  429. }
  430. }
  431. .bg {
  432. background-color: $color-green;
  433. width: 950rpx;
  434. position: absolute;
  435. left: -100rpx;
  436. border-bottom-left-radius: 1000rpx;
  437. border-bottom-right-radius: 1000rpx;
  438. top: 0rpx;
  439. height: 300rpx;
  440. }
  441. .base-buttom {
  442. position: relative;
  443. left: auto;
  444. bottom: auto;
  445. right: auto;
  446. }
  447. </style>