recharge.vue 9.5 KB

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