Преглед изворни кода

mp: 支持挖矿转到盈利

joe пре 3 година
родитељ
комит
c7878381be

+ 70 - 2
view/xcx/pages/user_money/index.js

@@ -2,6 +2,9 @@
 import {
     getProductHot
 } from '../../api/store.js';
+import {
+    coinTransfer
+} from '../../api/mine.js'
 import {
     openRechargeSubscribe
 } from '../../utils/SubscribeMessage.js';
@@ -9,6 +12,7 @@ import {
     getUserInfo,
     userActivity
 } from '../../api/user.js';
+import d from '../../utils/d.js';
 
 const app = getApp();
 
@@ -23,6 +27,9 @@ Page({
             'title': '钱包',
             'color': false,
         },
+        showPopup: false,
+        transferAmount: 0, // int 转出数量
+        transferSymbol: '', // 转的种类
         iShidden: false,
         userInfo: {},
         host_product: [],
@@ -69,8 +76,69 @@ Page({
     },
 
     // 点击币
-    onTapCoinItem: function () {
+    onTapCoinItem: function (ev) {
+        // get amount
+        let amount = 0;
+        for (let i = 0; i < this.data.userInfo.coins.length; i++) {
+            if (this.data.userInfo.coins[i].symbol === ev.currentTarget.dataset.id) {
+                amount = this.data.userInfo.coins[i].total;
+            }
+        }
+        // check total to be transfered
+        if (amount < 1) {
+            wx.showToast({
+                title: '金额不足以转入',
+            })
+            return
+        }
+        this.setData({
+            transferAmount: Math.floor(amount),
+            transferSymbol: ev.currentTarget.dataset.id,
+            showPopup: true,
+        })
+    },
 
+    onConfirmTransfer: function () {
+        this.onCancelTransfer()
+        // check if input value valid
+        const regex = new RegExp('^[0-9]+$')
+        if (!regex.test(this.data.transferAmount)) {
+            wx.showToast({
+                title: '您的输入有误',
+            })
+            return
+        }
+        // check if value great than total
+        let total = 0
+        for (let i = 0; i < this.data.userInfo.coins.length; i++) {
+            if (this.data.userInfo.coins[i].symbol === this.data.transferSymbol) {
+                total = this.data.userInfo.coins[i].total;
+            }
+        }
+        if (total < 1 || this.data.transferAmount > total) {
+            wx.showToast({
+                title: '输入错误',
+            })
+            return
+        }
+        // call API
+        let that = this
+        coinTransfer(this.data.transferAmount, this.data.transferSymbol).then(res => {
+            wx.showToast({
+                title: '转出成功',
+            })
+            that.getUserInfo();
+        }).catch(err => {
+            wx.showToast({
+                title: err,
+            })
+        })
+    },
+
+    onCancelTransfer: function () {
+        this.setData({
+            showPopup: false,
+        })
     },
 
     /**
@@ -99,7 +167,7 @@ Page({
             });
         })
     },
-    
+
     /**
      * 获取我的推荐
      */

+ 15 - 5
view/xcx/pages/user_money/index.wxml

@@ -8,8 +8,7 @@
                         <view>总资产(元)</view>
                         <view class='money'>{{userInfo.now_money || 0}}</view>
                     </view>
-                    <view wx:if='{{recharge_switch}}' bindtap="openSubscribe" hover-class='none'
-                        data-url='/pages/user_payment/index' class='recharge font-color'>充值</view>
+                    <view wx:if='{{recharge_switch}}' bindtap="openSubscribe" hover-class='none' data-url='/pages/user_payment/index' class='recharge font-color'>充值</view>
                 </view>
                 <view class='cumulative acea-row row-top'>
                     <view class='item' wx:if="{{recharge_switch}}">
@@ -68,9 +67,8 @@
     </view>
     -->
         <view class="list">
-            <view class='item acea-row row-between-wrapper' wx:for="{{userInfo.coins}}" bindtap='onTapCoinItem'
-                data-index='{{index}}' data-id="{{item.id}}" wx:key='index'>
-                <view class='picTxt acea-row row-between-wrapper'>
+            <view class='item acea-row row-between-wrapper' wx:for="{{userInfo.coins}}" wx:key='index'>
+                <view class='picTxt acea-row row-between-wrapper' bindtap='onTapCoinItem' data-id="{{item.symbol}}">
                     <image class="iconfont" src="{{ item.icon }}"></image>
                     <view class='text'>
                         <view class='line1'>{{ item.symbol }}</view>
@@ -85,6 +83,18 @@
         -->
             </view>
         </view>
+
+        <modal class="modal" confirm-text="转入" cancel-text="取消" hidden="{{!showPopup}}" bindconfirm="onConfirmTransfer" bindcancel="onCancelTransfer">
+            <view class="modal-head">
+                <text>转入到我的盈利</text>
+            </view>
+            <view class="modal-body">
+                <view class="row">
+                    <text>{{ transferSymbol }}:</text>
+                    <input type="number" model:value="{{ transferAmount }}" placeholder="请输入转入数量(限整数)" />
+                </view>
+            </view>
+        </modal>
         <!--
     <view class='list'>
       <view class='item acea-row row-between-wrapper'>

+ 65 - 9
view/xcx/pages/user_money/index.wxss

@@ -135,18 +135,26 @@
 }
 
 .my-account .wrapper .list .item {
+    display: flex;
+    flex-direction: column;
     margin-top: 44rpx;
 }
 
+.my-account .wrapper .list .item .picTxt {
+    display: flex;
+    justify-content: start;
+    align-items: center;
+    width: 100%;
+    font-size: 30rpx;
+    color: #282828;
+}
+
 .my-account .wrapper .list .item .picTxt .iconfont {
     width: 82rpx;
     height: 82rpx;
     border-radius: 50%;
     background-image: linear-gradient(to right, #ff9389 0%, #f9776b 100%);
     text-align: center;
-    line-height: 82rpx;
-    color: #fff;
-    font-size: 40rpx;
 }
 
 .my-account .wrapper .list .item .picTxt .iconfont.yellow {
@@ -157,14 +165,27 @@
     background-image: linear-gradient(to right, #a1d67c 0%, #9dd074 100%);
 }
 
-.my-account .wrapper .list .item .picTxt {
-    width: 428rpx;
-    font-size: 30rpx;
-    color: #282828;
+.my-account .wrapper .list .item .picTxt .text {
+    margin: 0 20rpx;
+    flex: 1;
 }
 
-.my-account .wrapper .list .item .picTxt .text {
-    width: 317rpx;
+.my-account .wrapper .list .item .picTxt button {
+    width: 110rpx;
+    height: 60rpx;
+    color: #fff;
+    font-size: 24rpx;
+    display: flex;
+    justify-content: center;
+    align-items: center;
+    border-radius: 10rpx;
+    padding: 0 6rpx;
+    background-image: linear-gradient(to right, #ff9389 0%, #f9776b 100%);
+}
+
+.my-account .wrapper .list .item .picTxt button:hover {
+    width: 112rpx;
+    height: 64rpx;
 }
 
 .my-account .wrapper .list .item .picTxt .text .infor {
@@ -195,4 +216,39 @@
     width: 30rpx;
     height: 30rpx;
     border-radius: 50%;
+}
+
+.row {
+    display: flex;
+    align-items: center;
+    width: 100%;
+}
+
+.modal {
+    border-radius: 50px;
+}
+
+.modal .modal-head {
+    display: flex;
+    justify-content: center;
+    align-items: center;
+    color: black;
+    font-size: 32rpx;
+    font-weight: 500;
+}
+
+.modal .modal-body {
+    margin: 40rpx 5%;
+    width: 100%;
+    height: auto;
+}
+
+.modal .modal-body text {
+    width: 20%;
+    color: black;
+}
+
+.modal .modal-body input {
+    width: 70%;
+    color: black;
 }