recharge.vue 9.4 KB

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