index.vue 12 KB

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