Files
tk-mini-program/pages/NewAddedPk/NewAddedPk.vue

315 lines
7.0 KiB
Vue
Raw Normal View History

2025-05-21 17:03:19 +08:00
<template>
<view v-if="Display" class="Mask" @click="open()">
2025-05-21 22:52:33 +08:00
<view @click.stop>
<view class="container">
<image
class="Fork"
@click="open()"
src="../../static/Fork.png"
mode="scaleToFill"
/>
<view class="Title">发布新PK</view>
<view class="Individual">
<view class="NameAnchor">
<input class="NameAnchorcss" @input="NameAnchor" placeholder="主播名称" />
<view v-if="nameAnchor === '' && Hint === true" class="Hint"
>请填写主播名称</view
>
</view>
2025-05-21 17:03:19 +08:00
2025-05-21 22:52:33 +08:00
<view class="Gender">
<wht-select
style="width: 300rpx"
@change="gender"
:options="Gender"
placeholder="性别"
/>
<view v-if="genders === '' && Hint === true" class="Hint">请选择性别</view>
</view>
</view>
2025-05-21 17:03:19 +08:00
2025-05-21 22:52:33 +08:00
<view class="Accountnumber">
2025-05-22 16:21:07 +08:00
<view class="Coins country">
2025-05-21 22:52:33 +08:00
<wht-select
style="width: 300rpx"
@change="country"
:options="Country"
filterable
placeholder="请选择国家"
/>
<view v-if="countrys === '' && Hint === true" class="Hint">请选择国家</view>
</view>
2025-05-21 17:03:19 +08:00
2025-05-21 22:52:33 +08:00
<view class="Coins">
<view class="number-box">
<view class="number-box-title">金币:</view>
<uni-number-box v-model="numberCoins"></uni-number-box>
2025-05-22 16:21:07 +08:00
<view class="number-box-unit">K</view>
2025-05-21 22:52:33 +08:00
</view>
<view v-if="numberCoins === '' && Hint === true" class="Hint"
>请填写金币数量</view
>
</view>
</view>
2025-05-21 17:03:19 +08:00
2025-05-21 22:52:33 +08:00
<view class="time">
<uni-datetime-picker
type="datetime"
v-model="datetimesingle"
@change="changeLog"
/>
<view v-if="datetimesingle === '' && Hint === true" class="Hint"
>请选择日期</view
>
</view>
2025-05-21 17:03:19 +08:00
2025-05-21 22:52:33 +08:00
<view class="Remarkscss">
<uni-easyinput
type="textarea"
v-model="remarks"
placeholder="备注"
></uni-easyinput>
</view>
2025-05-21 17:03:19 +08:00
2025-05-21 22:52:33 +08:00
<view class="Publish">
<button @click="Publish()" class="Publishcss">发布</button>
</view>
2025-05-21 17:03:19 +08:00
</view>
</view>
</view>
</template>
<script>
2025-05-21 22:52:33 +08:00
import optionsArray from "../../components/NationalDictionary.js";
import request from "../../components/request.js";
2025-05-21 17:03:19 +08:00
export default {
data() {
return {
2025-05-21 22:52:33 +08:00
genders: "", //性别
Gender: [
{ label: "男", value: 1 },
{ label: "女", value: 2 },
],
Country: optionsArray,
countrys: "", //国家
nameAnchor: "", //主播名称
numberCoins: "", //金币数量
remarks: "", //备注
2025-05-21 17:03:19 +08:00
Display: false,
2025-05-21 22:52:33 +08:00
Hint: false,
datetimesingle: "",//日期
id: null, //用户id
2025-05-21 17:03:19 +08:00
};
},
onLoad() {
uni.getStorage({
key: "userinfo",
success: (res) => {
2025-05-21 22:52:33 +08:00
this.id = res.data.id;
2025-05-21 17:03:19 +08:00
},
});
},
methods: {
2025-05-21 22:52:33 +08:00
gender(item) {
this.genders = item.value;
console.log(item);
},
country(item) {
this.countrys = item.value;
console.log(item);
},
2025-05-21 17:03:19 +08:00
handleOverlayClick(event) {
if (event.target === this.$el) {
this.Display = false;
2025-05-21 22:52:33 +08:00
this.Hint = false;
2025-05-21 17:03:19 +08:00
}
},
2025-05-21 22:52:33 +08:00
open() {
if (this.Display) {
this.Display = false;
this.Hint = false;
this.nameAnchor = "";
this.genders = "";
this.numberCoins = "";
this.remarks = "";
this.datetimesingle = "";
this.countrys = "";
} else {
this.Display = true;
}
2025-05-21 17:03:19 +08:00
},
//获取主播名称
NameAnchor: function (event) {
this.nameAnchor = event.target.value;
},
2025-05-21 22:52:33 +08:00
async Publish() {
//判断是否为空
if (
this.nameAnchor === "" ||
this.genders === "" ||
this.numberCoins === "" ||
this.countrys === "" ||
this.datetimesingle === ""
) {
this.Hint = true;
return;
}
//格式化日期
const isoString = this.datetimesingle.replace(" ", "T");
const timestamp = Date.parse(isoString);
if (isNaN(timestamp)) {
throw new Error(`Invalid date format: ${this.datetimesingle}`);
}
this.datetimesingle = Math.floor(timestamp / 1000);
//发送请求
uni.showLoading({
title: "发布中...",
mask: true,
});
const res = await request({
url: "pk/addPkData",
method: "POST",
data: {
anchorId: this.nameAnchor,
pk_time: this.datetimesingle,
sex: this.genders,
country: this.countrys,
coin: this.numberCoins,
remark: this.remarks,
status: 0,
sender_id: this.id,
anchorIcon: "",
},
userInfo: true,
});
if (res.code === 200) {
this.Display = false;
this.Hint = false;
this.nameAnchor = "";
this.genders = "";
this.numberCoins = "";
this.remarks = "";
this.datetimesingle = "";
uni.hideLoading();
uni.showToast({
title: "发布成功",
icon: "success",
duration: 2000,
});
} else {
uni.hideLoading();
uni.showToast({
title: "发布失败",
icon: "none",
duration: 2000,
});
}
},
2025-05-21 17:03:19 +08:00
},
};
</script>
<style scoped>
2025-05-21 22:52:33 +08:00
.Mask {
2025-05-21 17:03:19 +08:00
width: 100vw;
height: 100vh;
background: #00000076;
display: flex;
flex-direction: column-reverse;
}
2025-05-21 22:52:33 +08:00
.Hint {
color: red;
font-size: 20rpx;
}
2025-05-21 17:03:19 +08:00
.container {
display: flex;
background-color: #fff;
flex-direction: column;
width: 100%;
2025-05-21 22:52:33 +08:00
height: 100%;
2025-05-21 17:03:19 +08:00
}
2025-05-21 22:52:33 +08:00
.Fork {
2025-05-21 17:03:19 +08:00
width: 50rpx;
height: 50rpx;
margin-top: 20rpx;
/* margin-bottom: 40rpx; */
margin-left: 90%;
}
2025-05-21 22:52:33 +08:00
.Title {
width: 100%;
height: 30rpx;
font-size: 50rpx;
font-weight: bold;
text-align: center;
margin-top: 40rpx;
margin-bottom: 40rpx;
2025-05-21 17:03:19 +08:00
}
2025-05-21 22:52:33 +08:00
.Individual {
display: flex;
/* justify-content: center; */
2025-05-21 17:03:19 +08:00
}
2025-05-21 22:52:33 +08:00
.NameAnchor {
2025-05-21 17:03:19 +08:00
margin: 40rpx;
}
2025-05-21 22:52:33 +08:00
.time {
width: 90%;
margin-left: 5%;
2025-05-21 17:03:19 +08:00
}
2025-05-21 22:52:33 +08:00
.NameAnchorcss {
width: 300rpx;
height: 85rpx;
border: 1rpx solid #ccc;
border-radius: 10rpx;
text-align: center;
2025-05-21 17:03:19 +08:00
}
2025-05-21 22:52:33 +08:00
.Gender {
width: 300rpx;
height: 80rpx;
2025-05-21 17:03:19 +08:00
margin: 40rpx;
}
2025-05-21 22:52:33 +08:00
.Accountnumber {
display: flex;
}
.Coins {
2025-05-22 16:21:07 +08:00
margin-top: 40rpx;
margin-bottom: 40rpx;
width: 400rpx;
2025-05-21 17:03:19 +08:00
height: 65rpx;
display: flex;
2025-05-21 22:52:33 +08:00
flex-direction: column;
2025-05-21 17:03:19 +08:00
justify-content: center;
2025-05-21 22:52:33 +08:00
/* align-items: center; */
2025-05-21 17:03:19 +08:00
}
2025-05-22 16:21:07 +08:00
.country{
margin-left: 40rpx;
}
2025-05-21 17:03:19 +08:00
.number-box {
2025-05-21 22:52:33 +08:00
display: flex;
text-align: center;
}
.number-box-title {
margin-right: 20rpx;
2025-05-21 17:03:19 +08:00
}
2025-05-21 22:52:33 +08:00
.Remarkscss {
width: 90%;
margin-top: 30rpx;
margin-left: 5%;
margin-right: 5%;
margin-bottom: 50rpx;
border-radius: 10rpx;
2025-05-21 17:03:19 +08:00
}
2025-05-21 22:52:33 +08:00
.Publish {
2025-05-21 17:03:19 +08:00
margin-bottom: 50rpx;
width: 90%;
margin-left: 5%;
}
2025-05-21 22:52:33 +08:00
.Publishcss {
background-color: #0048ff94;
2025-05-21 17:03:19 +08:00
}
</style>