sendGift.vue
4.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
<template>
<view class="sendGiftAlert" v-if="showSendGift">
<view class="sendGift">
<view class="giftPad">
<view class="giftList">
<view class="giftItem" v-for="(item,index) in giftList" :key="index" @click="chooseGift(index)">
<view class="giftImg">
<view class="giftImgActive" :class="{active:giftIndex == index}">
<image :src="item.image" mode=""></image>
</view>
</view>
<view class="giftName">{{item.price}}地主币</view>
</view>
</view>
<view class="giftForm">
<view class="inpItem">
<view class="inpKey">余额</view>
<view class="inpVal">{{wallet.landlord_money}}地主币</view>
</view>
<view class="inpItem">
<view class="inpKey">数量</view>
<view class="inpVal">
<input type="number" v-model="inpNum" @keyup="inpNum = inpNum.length === 1 ? inpNum.replace(/[^1-9]/g, '') : inpNum.replace(/\D/g, '')" placeholder="请输入数量" placeholder-class="inpValPh"/>
</view>
</view>
<view class="inpItem">
<view class="inpKey">总计</view>
<view class="inpVal">{{jbNum}}地主币</view>
</view>
</view>
<view class="bottomBtn" @click="sendGift">
送出礼物
</view>
</view>
<view class="closeBtn" @click="closeSendGift">
<image src="../static/image/cross@2x.png" mode=""></image>
</view>
</view>
</view>
</template>
<script>
// var apiUrl = 'http://landlord.t.brotop.cn/api'
var apiUrl = 'http://app.zhaodizhu.cn/api'
export default{
data(){
return{
showSendGift:false,
wallet:{},//我的钱包
inpNum:'',//输入礼物数量
giftList:[],
giftIndex:-1
}
},
props:{
toUserId:{
type:Number
}
},
computed:{
jbNum(){
if(this.giftIndex != -1){
return this.inpNum * this.giftList[this.giftIndex].price
}
}
},
mounted() {
uni.request({
url:this.apiUrl + '/gift/lis',
method:'POST',
success: (res) => {
this.giftList = res.data.data
this.showSendGift = true
}
})
uni.request({
url:apiUrl+'/wallet/index',
method:'POST',
header: {
'content-type': 'application/x-www-form-urlencoded',
'token': uni.getStorageSync('token')
},
success: (res) => {
this.wallet = res.data.data
}
})
},
methods:{
//送出礼物
sendGift(){
if(this.giftIndex == -1){
uni.showToast({
title:'请选择礼物',
icon:'none'
})
return
}
if(this.inpNum == '' || this.inpNum <= 0){
uni.showToast({
title:'请输入正确数量',
icon:'none'
})
return
}
this.$request('/gift/give',{
gift_id:this.giftList[this.giftIndex].id,
user_id:this.toUserId,
number:this.inpNum
}).then((res)=>{
if(res.code == 1){
this.$emit('closeSendGift')
uni.showToast({
title:'送出礼物成功'
})
}else{
uni.showModal({
title:'提示',
content:'地主币不足,是否充值',
confirmText:'去充值',
success: (res) => {
if(res.confirm){
this.$href('/pages/my/recharge')
}
}
})
uni.showToast({
title:res.msg,
icon:'none'
})
}
})
},
//选择礼物
chooseGift(index){
this.giftIndex = index
},
closeSendGift(){
this.$emit('closeSendGift')
}
}
}
</script>
<style lang="scss" scoped>
/* 送礼物弹框 */
.sendGiftAlert{
position: fixed;top: 0;left: 0;right: 0;bottom: 0;background: rgba(0,0,0,0.5);z-index: 21;
.sendGift{
width: 100%;
position: absolute;
height: 630rpx;
bottom: 0;
background: #fff;
border-radius: 50rpx 50rpx 0 0;
.giftPad{
padding: 40rpx 32rpx 0 32rpx;
.giftList{
display: flex;
justify-content: center;
.giftItem{
.giftImg{
display: flex;
justify-content: center;
image{width: 120rpx;height: 120rpx;}
.giftImgActive{
width: 140rpx;
display: flex;
justify-content: center;
border-radius: 10rpx;
}
.giftImgActive.active{
background: #e0e3ef;
}
}
.giftName{
text-align: center;
color: #e8c760;
font-size: 28rpx;
}
}
}
.giftForm{
padding: 32rpx;
.inpItem{
height: 88rpx;
display: flex;
justify-content: space-between;
align-items: center;
.inpVal{
input{text-align: end;}
.inpValPh{
text-align: end;
}
}
}
}
.bottomBtn{
height:88rpx;
background: #35655f;
text-align: center;
line-height: 88rpx;
font-size: 32rpx;
color: #fff;
border-radius: 50rpx;
}
}
.closeBtn{
position: absolute;
width: 44rpx;
height: 44rpx;
right: 32rpx;
top: 32rpx;
image{width: 44rpx;height: 44rpx;}
}
}
}
</style>