index.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491
  1. <template>
  2. <view>
  3. <form @submit="submitSub" report-submit='true'>
  4. <view class="payment-top acea-row row-column row-center-wrapper">
  5. <span class="name">我的余额</span>
  6. <view class="pic">
  7. ¥<span class="pic-font">{{ userinfo.now_money || 0 }}</span>
  8. </view>
  9. </view>
  10. <view class="payment">
  11. <view class="nav acea-row row-around row-middle">
  12. <view class="item" :class="active==index?'on':''" v-for="(item,index) in navRecharge" :key="index" @click="navRecharges(index)">{{item}}</view>
  13. </view>
  14. <view class='tip picList' v-if='!active'>
  15. <view class="pic-box pic-box-color acea-row row-center-wrapper row-column" :class="activePic == index ? 'pic-box-color-active' : ''"
  16. v-for="(item, index) in picList" :key="index" @click="picCharge(index, item)">
  17. <view class="pic-number-pic">
  18. {{ item.price }}<span class="pic-number"> 元</span>
  19. </view>
  20. <view class="pic-number">赠送:{{ item.give_money }} 元</view>
  21. </view>
  22. <view class="pic-box pic-box-color acea-row row-center-wrapper" :class="activePic == picList.length ? 'pic-box-color-active' : ''"
  23. @click="picCharge(picList.length)">
  24. <input type="number" placeholder="其他" v-model="money" class="pic-box-money pic-number-pic" :class="activePic == picList.length ? 'pic-box-color-active' : ''" />
  25. </view>
  26. <view class="tips-box">
  27. <view class="tips mt-30">注意事项:</view>
  28. <view class="tips-samll" v-for="item in rechargeAttention" :key="item">
  29. {{ item }}
  30. </view>
  31. </view>
  32. </view>
  33. <view class="tip" v-else>
  34. <view class='input'><text>¥</text><input placeholder="0.00" type='number' placeholder-class='placeholder' :value="number" name="number"></input></view>
  35. <view class="tips-title">
  36. <view style="font-weight: bold; font-size: 26rpx;">提示:</view>
  37. <view style="margin-top: 10rpx;">当前佣金为 <text class='font-color'>¥{{userinfo.brokerage_price || 0}}</text></view>
  38. </view>
  39. <view class="tips-box">
  40. <view class="tips mt-30">注意事项:</view>
  41. <view class="tips-samll" v-for="item in rechargeAttention" :key="item">
  42. {{ item }}
  43. </view>
  44. </view>
  45. </view>
  46. <button class='but bg-color' formType="submit"> {{active ? '立即转入': '立即充值' }}</button>
  47. </view>
  48. </form>
  49. <!-- #ifdef MP -->
  50. <authorize @onLoadFun="onLoadFun" :isAuto="isAuto" :isShowAuth="isShowAuth" @authColse="authColse"></authorize>
  51. <!-- #endif -->
  52. </view>
  53. </template>
  54. <script>
  55. import {
  56. getUserInfo,
  57. rechargeRoutine,
  58. rechargeWechat,
  59. getRechargeApi
  60. } from '@/api/user.js';
  61. import {
  62. toLogin
  63. } from '@/libs/login.js';
  64. import {
  65. mapGetters
  66. } from "vuex";
  67. // #ifdef MP
  68. import authorize from '@/components/Authorize';
  69. // #endif
  70. export default {
  71. components: {
  72. // #ifdef MP
  73. authorize
  74. // #endif
  75. },
  76. data() {
  77. let that = this;
  78. return {
  79. now_money: 0,
  80. navRecharge: ['账户充值', '佣金转入'],
  81. active: 0,
  82. number: '',
  83. userinfo: {},
  84. placeholder: "0.00",
  85. from: '',
  86. isAuto: false, //没有授权的不会自动授权
  87. isShowAuth: false, //是否隐藏授权
  88. picList: [],
  89. activePic: 0,
  90. money: "",
  91. numberPic:'',
  92. rechar_id:0,
  93. rechargeAttention:[]
  94. };
  95. },
  96. computed: mapGetters(['isLogin']),
  97. onLoad(options) {
  98. // #ifdef H5
  99. this.from = this.$wechat.isWeixin() ? "weixin" : "weixinh5"
  100. // #endif
  101. if (this.isLogin) {
  102. this.getUserInfo();
  103. this.getRecharge();
  104. } else {
  105. // #ifdef H5 || APP-PLUS
  106. toLogin();
  107. // #endif
  108. // #ifdef MP
  109. this.isAuto = true;
  110. this.$set(this, 'isShowAuth', true)
  111. // #endif
  112. }
  113. },
  114. methods: {
  115. /**
  116. * 选择金额
  117. */
  118. picCharge(idx, item) {
  119. this.activePic = idx;
  120. if (item === undefined) {
  121. this.rechar_id = 0;
  122. this.numberPic = "";
  123. } else {
  124. this.money = "";
  125. this.rechar_id = item.id;
  126. this.numberPic = item.price;
  127. }
  128. },
  129. /**
  130. * 充值额度选择
  131. */
  132. getRecharge() {
  133. getRechargeApi()
  134. .then(res => {
  135. this.picList = res.data.recharge_quota;
  136. if (this.picList[0]) {
  137. this.rechar_id = this.picList[0].id;
  138. this.numberPic = this.picList[0].price;
  139. }
  140. this.rechargeAttention = res.data.recharge_attention || [];
  141. })
  142. .catch(res => {
  143. this.$dialog.toast({
  144. mes: res
  145. });
  146. });
  147. },
  148. onLoadFun: function() {
  149. this.getUserInfo();
  150. this.getRecharge();
  151. },
  152. // 授权关闭
  153. authColse: function(e) {
  154. this.isShowAuth = e
  155. },
  156. navRecharges: function(index) {
  157. this.active = index;
  158. },
  159. /**
  160. * 获取用户信息
  161. */
  162. getUserInfo: function() {
  163. let that = this;
  164. getUserInfo().then(res => {
  165. that.$set(that, 'userinfo', res.data);
  166. })
  167. },
  168. /*
  169. * 用户充值
  170. */
  171. submitSub: function(e) {
  172. let that = this
  173. let value = e.detail.value.number;
  174. // 转入余额
  175. if (that.active) {
  176. if (parseFloat(value) < 0 || parseFloat(value) == NaN || value == undefined || value == "") {
  177. return that.$util.Tips({
  178. title: '请输入金额'
  179. });
  180. }
  181. uni.showModal({
  182. title: '转入余额',
  183. content: '转入余额后无法再次转出,确认是否转入余额',
  184. success(res) {
  185. if (res.confirm) {
  186. // #ifdef MP || APP-PLUS
  187. rechargeRoutine({
  188. price: parseFloat(value),
  189. type: 1
  190. })
  191. // #endif
  192. // #ifdef H5
  193. rechargeWechat({
  194. price: parseFloat(value),
  195. from: that.from,
  196. type: 1
  197. })
  198. // #endif
  199. .then(res => {
  200. // that.$set(that, 'userinfo.now_money', that.$util.$h.Add(value, that.userinfo.now_money))
  201. return that.$util.Tips({
  202. title: '转入成功',
  203. icon: 'success'
  204. }, {
  205. tab: 5,
  206. url: '/pages/users/user_money/index'
  207. });
  208. }).catch(err => {
  209. return that.$util.Tips({
  210. title: err
  211. })
  212. });
  213. } else if (res.cancel) {
  214. return that.$util.Tips({
  215. title: '已取消'
  216. });
  217. }
  218. },
  219. })
  220. } else {
  221. uni.showLoading({
  222. title: '正在支付',
  223. })
  224. // #ifdef MP || APP-PLUS
  225. let money = parseFloat(this.money);
  226. if( this.rechar_id == 0){
  227. if(Number.isNaN(money)){
  228. return that.$util.Tips({title: '充值金额必须为数字'});
  229. }
  230. if(money <= 0){
  231. return that.$util.Tips({title: '充值金额不能为0'});
  232. }
  233. }else{
  234. money = this.numberPic
  235. }
  236. rechargeRoutine({
  237. price: money,
  238. type: 0,
  239. rechar_id: this.rechar_id
  240. }).then(res => {
  241. uni.hideLoading();
  242. let jsConfig = res.data;
  243. uni.requestPayment({
  244. timeStamp: jsConfig.timestamp,
  245. nonceStr: jsConfig.nonceStr,
  246. package: jsConfig.package,
  247. signType: jsConfig.signType,
  248. paySign: jsConfig.paySign,
  249. success: function(res) {
  250. that.$set(that, 'userinfo.now_money', that.$util.$h.Add(value, that.userinfo.now_money));
  251. return that.$util.Tips({
  252. title: '支付成功',
  253. icon: 'success'
  254. }, {
  255. tab: 5,
  256. url: '/pages/users/user_money/index'
  257. });
  258. },
  259. fail: function() {
  260. return that.$util.Tips({
  261. title: '支付失败'
  262. });
  263. },
  264. complete: function(res) {
  265. if (res.errMsg == 'requestPayment:cancel') return that.$util.Tips({
  266. title: '取消支付'
  267. });
  268. }
  269. })
  270. }).catch(err => {
  271. uni.hideLoading();
  272. return that.$util.Tips({
  273. title: err
  274. })
  275. });
  276. // #endif
  277. // #ifdef H5
  278. rechargeWechat({
  279. price: that.rechar_id == 0 ? that.money : that.numberPic,
  280. from: that.from,
  281. rechar_id: that.rechar_id
  282. }).then(res => {
  283. let data = res.data;
  284. if (data.type == "weixinh5") {
  285. location.replace(data.data.mweb_url);
  286. return that.$util.Tips({
  287. title: '支付成功',
  288. icon: 'success'
  289. }, {
  290. tab: 5,
  291. url: '/pages/users/user_money/index'
  292. });
  293. } else {
  294. that.$wechat.pay(data.data)
  295. .finally(() => {
  296. that.$set(that, 'userinfo.now_money', that.$util.$h.Add(value, that.userinfo.now_money));
  297. return that.$util.Tips({
  298. title: '支付成功',
  299. icon: 'success'
  300. }, {
  301. tab: 5,
  302. url: '/pages/users/user_money/index'
  303. });
  304. })
  305. .catch(function() {
  306. return that.$util.Tips({
  307. title: '支付失败'
  308. });
  309. });
  310. }
  311. })
  312. // #endif
  313. }
  314. }
  315. }
  316. }
  317. </script>
  318. <style lang="scss">
  319. page {
  320. width: 100%;
  321. height: 100%;
  322. background-color: #fff;
  323. }
  324. .payment {
  325. position: relative;
  326. top: -60rpx;
  327. width: 100%;
  328. background-color: #fff;
  329. border-radius: 10rpx;
  330. padding-top: 25rpx;
  331. border-top-right-radius: 39rpx;
  332. border-top-left-radius: 39rpx;
  333. }
  334. .payment .nav {
  335. height: 75rpx;
  336. line-height: 75rpx;
  337. padding: 0 100rpx;
  338. }
  339. .payment .nav .item {
  340. font-size: 30rpx;
  341. color: #333;
  342. }
  343. .payment .nav .item.on {
  344. font-weight: bold;
  345. border-bottom: 4rpx solid #e83323;
  346. }
  347. .payment .input {
  348. display: flex;
  349. align-items: center;
  350. justify-content: center;
  351. border-bottom: 1px dashed #dddddd;
  352. margin: 60rpx auto 0 auto;
  353. padding-bottom: 20rpx;
  354. font-size: 56rpx;
  355. color: #333333;
  356. flex-wrap: nowrap;
  357. }
  358. .payment .input text {
  359. padding-left: 106rpx;
  360. }
  361. .payment .input input {
  362. padding-right: 106rpx;
  363. width: 300rpx;
  364. height: 94rpx;
  365. text-align: center;
  366. font-size: 70rpx;
  367. }
  368. .payment .placeholder {
  369. color: #d0d0d0;
  370. height: 100%;
  371. line-height: 94rpx;
  372. }
  373. .payment .tip {
  374. font-size: 26rpx;
  375. color: #888888;
  376. padding: 0 30rpx;
  377. margin-top: 25rpx;
  378. }
  379. .payment .but {
  380. color: #fff;
  381. font-size: 30rpx;
  382. width: 700rpx;
  383. height: 86rpx;
  384. border-radius: 50rpx;
  385. margin: 46rpx auto 0 auto;
  386. line-height: 86rpx;
  387. }
  388. .payment-top {
  389. width: 100%;
  390. height: 350rpx;
  391. background-color: #e83323;
  392. .name {
  393. font-size: 26rpx;
  394. color: rgba(255, 255, 255, 0.8);
  395. margin-top: -38rpx;
  396. margin-bottom: 30rpx;
  397. }
  398. .pic {
  399. font-size: 32rpx;
  400. color: #fff;
  401. }
  402. .pic-font {
  403. font-size: 78rpx;
  404. color: #fff;
  405. }
  406. }
  407. .picList {
  408. display: flex;
  409. flex-wrap: wrap;
  410. margin: 30rpx 0;
  411. .pic-box {
  412. width: 32%;
  413. height: auto;
  414. border-radius: 20rpx;
  415. margin-top: 21rpx;
  416. padding: 20rpx 0;
  417. margin-right: 12rpx;
  418. &:nth-child(3n) {
  419. margin-right: 0;
  420. }
  421. }
  422. .pic-box-color {
  423. background-color: #f4f4f4;
  424. color: #656565;
  425. }
  426. .pic-number {
  427. font-size: 22rpx;
  428. }
  429. .pic-number-pic {
  430. font-size: 38rpx;
  431. margin-right: 10rpx;
  432. text-align: center;
  433. }
  434. .pic-box-color-active {
  435. background-color: #ec3323 !important;
  436. color: #fff !important;
  437. }
  438. }
  439. .tips-box{
  440. .tips {
  441. font-size: 28rpx;
  442. color: #333333;
  443. font-weight: 800;
  444. margin-bottom: 14rpx;
  445. margin-top: 20rpx;
  446. }
  447. .tips-samll {
  448. font-size: 24rpx;
  449. color: #333333;
  450. margin-bottom: 14rpx;
  451. }
  452. .tip-box {
  453. margin-top: 30rpx;
  454. }
  455. }
  456. .tips-title{
  457. margin-top: 20rpx;
  458. font-size: 24rpx;
  459. color: #333;
  460. }
  461. </style>