recharge.vue 9.7 KB

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