This commit is contained in:
2025-12-12 01:44:41 +08:00
parent 21abcaff53
commit 2f1d732a36
46 changed files with 7756 additions and 484 deletions

View File

@@ -42,6 +42,29 @@
/>
</view>
</view>
<view class="form-item">
<view class="form-label">所属单位</view>
<view class="form-value">
<input
class="form-input"
v-model="formData.organization"
placeholder="请输入所属单位"
/>
</view>
</view>
<view class="form-item">
<view class="form-label">联系电话</view>
<view class="form-value">
<input
class="form-input"
v-model="formData.phone"
type="number"
placeholder="请输入联系电话"
/>
</view>
</view>
</view>
<!-- 错误提示 -->
@@ -72,14 +95,19 @@
</template>
<script>
import athleteAPI from '@/api/athlete.js'
export default {
data() {
return {
playerId: '',
formData: {
idType: '身份证',
name: '张三',
idCard: '123456789000000000',
team: '少林寺武术学院'
name: '',
idCard: '',
team: '',
organization: '',
phone: ''
},
errors: [],
showHint: false,
@@ -94,7 +122,10 @@ export default {
this.formData.name &&
this.formData.idCard &&
this.formData.team &&
this.validateIdCard(this.formData.idCard)
this.formData.organization &&
this.formData.phone &&
this.validateIdCard(this.formData.idCard) &&
this.validatePhone(this.formData.phone)
);
}
},
@@ -107,27 +138,58 @@ export default {
},
'formData.team'(val) {
this.validateForm();
},
'formData.organization'(val) {
this.validateForm();
},
'formData.phone'(val) {
this.validateForm();
}
},
onLoad(options) {
if (options.id) {
// 加载选手数据
this.playerId = options.id
this.loadPlayerData(options.id);
}
},
methods: {
loadPlayerData(id) {
// 模拟加载数据
// 实际应该从后端获取
/**
* 加载选手数据
*/
async loadPlayerData(id) {
try {
const res = await athleteAPI.getAthleteDetail(id)
// 回显数据(使用后端实体类的字段名)
this.formData = {
idType: res.idCardType === 1 ? '身份证' : '其他',
name: res.playerName || '',
idCard: res.idCard || '',
team: res.teamName || '',
organization: res.organization || '',
phone: res.contactPhone || ''
}
} catch (err) {
console.error('加载选手数据失败:', err)
uni.showToast({
title: '加载失败',
icon: 'none'
})
}
},
validateIdCard(idCard) {
return /^\d{18}$/.test(idCard);
// 身份证号验证18位最后一位可以是数字或字母X
return /^\d{17}[\dXx]$/.test(idCard);
},
validatePhone(phone) {
// 手机号验证11位数字
return /^1[3-9]\d{9}$/.test(phone);
},
validateForm() {
this.errors = [];
this.showHint = false;
if (!this.formData.name || !this.formData.idCard || !this.formData.team) {
if (!this.formData.name || !this.formData.idCard || !this.formData.team || !this.formData.organization || !this.formData.phone) {
this.showHint = true;
this.errors.push({
label: '有空文本时弹出:',
@@ -141,20 +203,91 @@ export default {
message: '按钮置灰'
});
}
if (this.formData.phone && !this.validatePhone(this.formData.phone)) {
this.errors.push({
label: '手机号格式不正确:',
message: '按钮置灰'
});
}
},
handleSave() {
/**
* 从身份证号中提取信息
*/
extractInfoFromIdCard(idCard) {
if (!idCard || idCard.length !== 18) {
return {
gender: null,
age: null,
birthDate: null
}
}
// 提取出生日期
const year = idCard.substring(6, 10)
const month = idCard.substring(10, 12)
const day = idCard.substring(12, 14)
const birthDate = `${year}-${month}-${day}`
// 计算年龄
const birthYear = parseInt(year)
const currentYear = new Date().getFullYear()
const age = currentYear - birthYear
// 提取性别(倒数第二位,奇数为男,偶数为女)
const genderCode = parseInt(idCard.substring(16, 17))
const gender = genderCode % 2 === 1 ? 1 : 2
return {
gender,
age,
birthDate
}
},
async handleSave() {
if (!this.isFormValid) {
return;
}
this.toastMessage = '身份证号码格式不正确';
this.showToast = true;
setTimeout(() => {
this.showToast = false;
}, 2000);
try {
// 从身份证号中提取信息
const info = this.extractInfoFromIdCard(this.formData.idCard)
// 实际保存逻辑
// uni.navigateBack();
// 调用API更新选手信息使用后端实体类的字段名
await athleteAPI.submitAthlete({
id: this.playerId,
playerName: this.formData.name,
idCard: this.formData.idCard,
teamName: this.formData.team,
organization: this.formData.organization,
contactPhone: this.formData.phone,
idCardType: 1, // 身份证类型固定为1
gender: info.gender,
age: info.age,
birthDate: info.birthDate
})
// 保存成功
uni.showToast({
title: '保存成功',
icon: 'success'
})
// 延迟返回上一页
setTimeout(() => {
uni.navigateBack()
}, 1500)
} catch (err) {
console.error('保存选手失败:', err)
// 显示错误提示
this.toastMessage = '保存失败,请重试'
this.showToast = true
setTimeout(() => {
this.showToast = false
}, 2000)
}
}
}
};