indexs.vue 10 KB

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