|
|
@@ -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({
|
|
|
});
|
|
|
})
|
|
|
},
|
|
|
-
|
|
|
+
|
|
|
/**
|
|
|
* 获取我的推荐
|
|
|
*/
|