301 lines
5.8 KiB
Vue
301 lines
5.8 KiB
Vue
<template>
|
||
<view class="edit-player-page">
|
||
<!-- 表单 -->
|
||
<view class="form-container">
|
||
<view class="form-item" @click="showIdTypePicker = true">
|
||
<view class="form-label">证件类型</view>
|
||
<view class="form-value">
|
||
<text>{{ formData.idType }}</text>
|
||
<text class="arrow">›</text>
|
||
</view>
|
||
</view>
|
||
|
||
<view class="form-item">
|
||
<view class="form-label">姓名</view>
|
||
<view class="form-value">
|
||
<input
|
||
class="form-input"
|
||
v-model="formData.name"
|
||
placeholder="请输入姓名"
|
||
/>
|
||
</view>
|
||
</view>
|
||
|
||
<view class="form-item">
|
||
<view class="form-label">证件号码</view>
|
||
<view class="form-value">
|
||
<input
|
||
class="form-input"
|
||
v-model="formData.idCard"
|
||
placeholder="请输入身份证号码"
|
||
/>
|
||
</view>
|
||
</view>
|
||
|
||
<view class="form-item">
|
||
<view class="form-label">队伍</view>
|
||
<view class="form-value">
|
||
<input
|
||
class="form-input"
|
||
v-model="formData.team"
|
||
placeholder="请输入队伍名称"
|
||
/>
|
||
</view>
|
||
</view>
|
||
</view>
|
||
|
||
<!-- 错误提示 -->
|
||
<view class="error-hints" v-if="errors.length > 0">
|
||
<view class="error-item" v-for="(error, index) in errors" :key="index">
|
||
<text class="error-label">{{ error.label }}</text>
|
||
<text class="error-msg">{{ error.message }}</text>
|
||
</view>
|
||
</view>
|
||
|
||
<!-- 提示信息 -->
|
||
<view class="hint-message" v-if="showHint">
|
||
<text class="hint-icon">ℹ</text>
|
||
<text class="hint-text">请完善信息</text>
|
||
</view>
|
||
|
||
<!-- Toast提示 -->
|
||
<view class="toast-message" v-if="showToast">
|
||
<text class="toast-text">{{ toastMessage }}</text>
|
||
</view>
|
||
|
||
<!-- 按钮 -->
|
||
<view class="btn-wrapper">
|
||
<view class="btn save-btn disabled" v-if="!isFormValid">保存</view>
|
||
<view class="btn save-btn" v-else @click="handleSave">保存</view>
|
||
</view>
|
||
</view>
|
||
</template>
|
||
|
||
<script>
|
||
export default {
|
||
data() {
|
||
return {
|
||
formData: {
|
||
idType: '身份证',
|
||
name: '张三',
|
||
idCard: '123456789000000000',
|
||
team: '少林寺武术学院'
|
||
},
|
||
errors: [],
|
||
showHint: false,
|
||
showToast: false,
|
||
toastMessage: '',
|
||
showIdTypePicker: false
|
||
};
|
||
},
|
||
computed: {
|
||
isFormValid() {
|
||
return (
|
||
this.formData.name &&
|
||
this.formData.idCard &&
|
||
this.formData.team &&
|
||
this.validateIdCard(this.formData.idCard)
|
||
);
|
||
}
|
||
},
|
||
watch: {
|
||
'formData.name'(val) {
|
||
this.validateForm();
|
||
},
|
||
'formData.idCard'(val) {
|
||
this.validateForm();
|
||
},
|
||
'formData.team'(val) {
|
||
this.validateForm();
|
||
}
|
||
},
|
||
onLoad(options) {
|
||
if (options.id) {
|
||
// 加载选手数据
|
||
this.loadPlayerData(options.id);
|
||
}
|
||
},
|
||
methods: {
|
||
loadPlayerData(id) {
|
||
// 模拟加载数据
|
||
// 实际应该从后端获取
|
||
},
|
||
validateIdCard(idCard) {
|
||
return /^\d{18}$/.test(idCard);
|
||
},
|
||
validateForm() {
|
||
this.errors = [];
|
||
this.showHint = false;
|
||
|
||
if (!this.formData.name || !this.formData.idCard || !this.formData.team) {
|
||
this.showHint = true;
|
||
this.errors.push({
|
||
label: '有空文本时弹出:',
|
||
message: '按钮置灰'
|
||
});
|
||
}
|
||
|
||
if (this.formData.idCard && !this.validateIdCard(this.formData.idCard)) {
|
||
this.errors.push({
|
||
label: '身份证不足18位:',
|
||
message: '按钮置灰'
|
||
});
|
||
}
|
||
},
|
||
handleSave() {
|
||
if (!this.isFormValid) {
|
||
return;
|
||
}
|
||
|
||
this.toastMessage = '身份证号码格式不正确';
|
||
this.showToast = true;
|
||
setTimeout(() => {
|
||
this.showToast = false;
|
||
}, 2000);
|
||
|
||
// 实际保存逻辑
|
||
// uni.navigateBack();
|
||
}
|
||
}
|
||
};
|
||
</script>
|
||
|
||
<style lang="scss" scoped>
|
||
.edit-player-page {
|
||
min-height: 100vh;
|
||
background-color: #f5f5f5;
|
||
padding-bottom: 200rpx;
|
||
}
|
||
|
||
.form-container {
|
||
background-color: #fff;
|
||
margin: 30rpx;
|
||
border-radius: 16rpx;
|
||
overflow: hidden;
|
||
}
|
||
|
||
.form-item {
|
||
display: flex;
|
||
align-items: center;
|
||
padding: 35rpx 30rpx;
|
||
border-bottom: 1rpx solid #f5f5f5;
|
||
}
|
||
|
||
.form-item:last-child {
|
||
border-bottom: none;
|
||
}
|
||
|
||
.form-label {
|
||
width: 180rpx;
|
||
font-size: 30rpx;
|
||
color: #333333;
|
||
}
|
||
|
||
.form-value {
|
||
flex: 1;
|
||
display: flex;
|
||
align-items: center;
|
||
justify-content: space-between;
|
||
}
|
||
|
||
.form-input {
|
||
flex: 1;
|
||
font-size: 30rpx;
|
||
color: #333333;
|
||
}
|
||
|
||
.arrow {
|
||
font-size: 40rpx;
|
||
color: #cccccc;
|
||
margin-left: 10rpx;
|
||
}
|
||
|
||
.error-hints {
|
||
margin: 30rpx;
|
||
padding: 30rpx;
|
||
background-color: #fff;
|
||
border-radius: 16rpx;
|
||
}
|
||
|
||
.error-item {
|
||
margin-bottom: 15rpx;
|
||
}
|
||
|
||
.error-label {
|
||
font-size: 26rpx;
|
||
color: #C93639;
|
||
margin-right: 10rpx;
|
||
}
|
||
|
||
.error-msg {
|
||
font-size: 26rpx;
|
||
color: #C93639;
|
||
}
|
||
|
||
.hint-message {
|
||
position: fixed;
|
||
top: 50%;
|
||
left: 50%;
|
||
transform: translate(-50%, -50%);
|
||
background-color: rgba(0, 0, 0, 0.7);
|
||
color: #fff;
|
||
padding: 30rpx 50rpx;
|
||
border-radius: 16rpx;
|
||
display: flex;
|
||
align-items: center;
|
||
gap: 15rpx;
|
||
z-index: 9999;
|
||
}
|
||
|
||
.hint-icon {
|
||
font-size: 40rpx;
|
||
}
|
||
|
||
.hint-text {
|
||
font-size: 28rpx;
|
||
}
|
||
|
||
.toast-message {
|
||
position: fixed;
|
||
top: 50%;
|
||
left: 50%;
|
||
transform: translate(-50%, -50%);
|
||
background-color: rgba(0, 0, 0, 0.7);
|
||
color: #fff;
|
||
padding: 30rpx 50rpx;
|
||
border-radius: 16rpx;
|
||
z-index: 9999;
|
||
}
|
||
|
||
.toast-text {
|
||
font-size: 28rpx;
|
||
}
|
||
|
||
.btn-wrapper {
|
||
position: fixed;
|
||
bottom: 0;
|
||
left: 0;
|
||
right: 0;
|
||
padding: 30rpx;
|
||
background-color: #f5f5f5;
|
||
}
|
||
|
||
.btn {
|
||
width: 100%;
|
||
text-align: center;
|
||
padding: 30rpx;
|
||
border-radius: 12rpx;
|
||
font-size: 32rpx;
|
||
font-weight: bold;
|
||
}
|
||
|
||
.save-btn {
|
||
background-color: #C93639;
|
||
color: #fff;
|
||
}
|
||
|
||
.save-btn.disabled {
|
||
background-color: rgba(201, 54, 57, 0.5);
|
||
}
|
||
</style>
|