This commit is contained in:
2021-11-11 15:10:51 +08:00
parent ec0724c873
commit b4af257c70
63 changed files with 3189 additions and 832 deletions
+230
View File
@@ -0,0 +1,230 @@
<template>
<van-popup v-model="value" position="bottom" @close="$emit('update:value', false)">
<div class="red-packet" v-if="user">
<img class="avatar" :src="anonymous ? avatar : user.avatar" alt="">
<div class="username-container">
<div class="username" v-if="!edit" @click="onEdit">
<span>{{user.nickname}}</span>
<i class="iconfont icon-bianjisekuai"></i>
</div>
<input class="input-username" ref="input" v-if="edit" v-model="user.nickname" @blur="edit = false">
</div>
<vue-number-scroll v-model="number"></vue-number-scroll>
<div class="money-input">
<input type="tel" v-model="money" v-number-only @change="onMoneyInput">
<span>元</span>
</div>
<!-- <div class="bar">
<span>
<van-checkbox v-model="anonymous" checked-color="#CF9E3B" @change="onAnonymous">匿名参与</van-checkbox>
</span>
<span>查看服务协议</span>
</div> -->
<div class="random-button-group">
<button class="change" @click="changeMoney">换个金额</button>
<button class="next" @click="onNext">下一步</button>
</div>
</div>
</van-popup>
</template>
<script>
import { getRandMoney, getUserData } from '@/api';
import VueNumberScroll from '../vue-number-scroll'
export default {
name: 'random-money',
components: {
VueNumberScroll
},
data(){
return {
avatar: require('@/assets/img/xiaoheshang.jpg'),
edit: false,
anonymous: false,
numberArr: ['3', '.', '9','9'],
number: 0,
money: 0,
user: null,
privateUser: null,
inputNickname: '',
randList: [],
}
},
props: {
value: {
type: Boolean,
default: false,
}
},
mounted(){
this.getRandMoney()
this.getUserData();
},
methods: {
onAnonymous(checked){
this.anonymous = checked;
if(checked){
this.user.nickname = '匿名用户'
} else {
this.user.nickname = this.privateUser.nickname
}
},
onEdit(){
this.edit = true;
this.$nextTick(() => {
this.$refs.input.focus();
})
},
async getUserData(){
const res = await getUserData();
this.user = res;
this.privateUser = Object.assign({}, res);
this.inputNickname = res.nickname;
},
onMoneyInput(e){
console.log(e.target.value)
this.number = this.money
},
changeMoney(){
const rand = Math.floor(Math.random() * this.randList.length);
this.number = Number(this.randList[rand])
this.money = this.number;
},
async getRandMoney(){
const res = await getRandMoney();
this.randList = res;
this.money = Number(res[0])
this.number = Number(res[0])
},
onNext(){
this.$emit('change', {
anonymous: this.anonymous,
money: this.number
})
this.$emit('update:value', false)
}
}
};
</script>
<style lang="scss">
.red-packet{
height: 60vh;
background: #e85042 url('~@/assets/img/red-packet.jpg') top center no-repeat;
background-size: contain;
overflow: hidden;
.avatar{
width: 2rem;
height: 2rem;
display: block;
border-radius: 1.5rem;
border: 2px solid yellow;
margin: 2rem auto .1rem;
}
.username-container{
padding-top: .3rem;
height: 2rem;
.username{
color: white;
font-size: .4rem;
text-align: center;
margin-top: .3rem;
span{
padding-right: .1rem;
}
}
.input-username{
border: 1px solid yellow;
font-size: .4rem;
background: transparent;
margin-left: auto;
margin-right: auto;
display: block;
height: 1rem;
color: white;
padding: .1rem .3rem;
border-radius: 4px;
}
}
.money{
color: yellow;
text-align: center;
height: 1rem;
line-height: 1rem;
font-size: 1rem;
overflow: hidden;
margin-top: .6rem;
margin-bottom: .8rem;
ul{
li{
display: inline-block;
}
}
}
.bar{
display: flex;
justify-content: space-between;
font-size: .4rem;
color: white;
padding: .3rem .6rem;
margin-top: .6rem;
}
.money-input{
border: 1px solid yellow;
height: 1.2rem;
width: 60%;
margin: 0 auto;
color: white;
display: flex;
align-items: center;
border-radius: 2px;
justify-content: space-between;
input{
background: transparent;
border: 1px solid transparent;
flex: 1;
height: 100%;
padding-left: .5rem;
font-size: .5rem;
width: 50%;
}
span{
padding: 0 .2rem;
font-size: .5rem;
}
}
.van-checkbox__label{
color: white;
}
.random-button-group{
text-align: center;
font-size: .5rem;
margin-top: .7rem;
display: flex;
padding: 0 .4rem;
button{
background: transparent;
margin: 0 .2rem;
height: 1.3rem;
border: 1px solid transparent;
color: white;
}
.change{
color: yellow;
border: 1px solid yellow;
border-radius: 4px;
flex: 1.3;
}
.next{
background: yellow;
color: rgb(224, 61, 61);
border-radius: 4px;
flex: 2
}
}
}
</style>