fix bugs
This commit is contained in:
@@ -20,7 +20,7 @@
|
||||
|
||||
<!-- 步骤1:选择选手信息 -->
|
||||
<view class="step-content" v-if="currentStep === 1">
|
||||
<view class="selected-count">已选:<text class="count">26</text> 人</view>
|
||||
<view class="selected-count">已选:<text class="count">{{ selectedCount }}</text> 人</view>
|
||||
|
||||
<view class="add-player-btn" @click="goToAddPlayer">
|
||||
<text class="add-icon">⊕</text>
|
||||
@@ -82,7 +82,9 @@
|
||||
<view class="info-hint">(注意是否用此号码接收信息)</view>
|
||||
<view class="info-item participants-item">
|
||||
<text class="label">参赛选手:</text>
|
||||
<text class="value participants">{{ eventInfo.participants }}</text>
|
||||
<text class="value participants" style="color: #C93639; font-weight: bold;">
|
||||
{{ eventInfo.participants || '未选择选手' }}
|
||||
</text>
|
||||
<view class="view-cert-btn" @click="showPlayers">
|
||||
<text>查看证件</text>
|
||||
<text class="arrow">›</text>
|
||||
@@ -93,11 +95,11 @@
|
||||
<view class="payment-info">
|
||||
<view class="payment-row">
|
||||
<text class="label">人数:</text>
|
||||
<text class="value">26</text>
|
||||
<text class="value">{{ selectedCount }}</text>
|
||||
</view>
|
||||
<view class="payment-row total">
|
||||
<text class="label">合计:</text>
|
||||
<text class="value price">¥ 29999</text>
|
||||
<text class="value price">¥ {{ totalPrice }}</text>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
@@ -130,7 +132,7 @@
|
||||
<text class="value">{{ eventInfo.contact }}</text>
|
||||
</view>
|
||||
|
||||
<view class="participants-title">参赛选手:26人</view>
|
||||
<view class="participants-title">参赛选手:{{ selectedPlayers.length }}人</view>
|
||||
<view class="participants-detail">
|
||||
<view class="participant-item" v-for="(item, index) in selectedPlayers" :key="index">
|
||||
<view class="participant-name">{{ item.name }}</view>
|
||||
@@ -166,63 +168,199 @@
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import competitionAPI from '@/api/competition.js'
|
||||
import athleteAPI from '@/api/athlete.js'
|
||||
import registrationAPI from '@/api/registration.js'
|
||||
|
||||
export default {
|
||||
data() {
|
||||
return {
|
||||
currentStep: 1,
|
||||
eventId: '',
|
||||
selectedProjects: [],
|
||||
eventInfo: {
|
||||
title: '2025年全国武术散打锦标赛暨第十七届世界武术锦标赛选拔赛',
|
||||
location: '天津市-天津市体育中心',
|
||||
matchTime: '2025.02.01-2025.02.10',
|
||||
projects: '男子组剑术、男子组太极拳、男子组套路、男子组其他项目',
|
||||
contact: '18666666666',
|
||||
participants: '张三、李四、王二、张三、张三、李四、王二、张三、李四'
|
||||
title: '',
|
||||
location: '',
|
||||
matchTime: '',
|
||||
projects: '',
|
||||
contact: '',
|
||||
participants: ''
|
||||
},
|
||||
playerList: [
|
||||
{
|
||||
id: 1,
|
||||
name: '张三',
|
||||
idCard: '123456789000000000',
|
||||
selected: false
|
||||
},
|
||||
{
|
||||
id: 2,
|
||||
name: '张三',
|
||||
idCard: '123456789000000000',
|
||||
selected: true
|
||||
},
|
||||
{
|
||||
id: 3,
|
||||
name: '张三',
|
||||
idCard: '123456789000000000',
|
||||
selected: true
|
||||
}
|
||||
],
|
||||
selectedPlayers: [
|
||||
{
|
||||
name: '张三',
|
||||
idCard: '123456789000000000',
|
||||
number: '123-4567898275'
|
||||
},
|
||||
{
|
||||
name: '李四',
|
||||
idCard: '123456789000000000',
|
||||
number: '123-4567898276'
|
||||
}
|
||||
],
|
||||
showPlayerModal: false
|
||||
playerList: [],
|
||||
selectedPlayers: [],
|
||||
showPlayerModal: false,
|
||||
totalPrice: 0,
|
||||
registrationId: ''
|
||||
};
|
||||
},
|
||||
computed: {
|
||||
selectedCount() {
|
||||
return this.playerList.filter(item => item.selected).length
|
||||
},
|
||||
participantsText() {
|
||||
return this.playerList
|
||||
.filter(item => item.selected)
|
||||
.map(item => item.name)
|
||||
.join('、')
|
||||
}
|
||||
},
|
||||
onLoad(options) {
|
||||
if (options.eventId) {
|
||||
this.eventId = options.eventId;
|
||||
this.eventId = options.eventId
|
||||
this.loadEventDetail(options.eventId)
|
||||
}
|
||||
|
||||
if (options.projects) {
|
||||
try {
|
||||
// 尝试解码(可能被双重编码)
|
||||
let projectsStr = decodeURIComponent(options.projects)
|
||||
|
||||
// 如果还包含 %,说明被双重编码了,再解码一次
|
||||
if (projectsStr.includes('%')) {
|
||||
projectsStr = decodeURIComponent(projectsStr)
|
||||
}
|
||||
|
||||
this.selectedProjects = JSON.parse(projectsStr)
|
||||
} catch (err) {
|
||||
console.error('解析项目数据失败:', err)
|
||||
}
|
||||
}
|
||||
|
||||
// 加载选手列表
|
||||
this.loadPlayerList()
|
||||
},
|
||||
onShow() {
|
||||
// 从新增/编辑页面返回时重新加载列表
|
||||
if (this.currentStep === 1) {
|
||||
this.loadPlayerList()
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
/**
|
||||
* 加载赛事详情
|
||||
*/
|
||||
async loadEventDetail(id) {
|
||||
try {
|
||||
const res = await competitionAPI.getCompetitionDetail(id)
|
||||
|
||||
// 尝试多个可能的时间字段名
|
||||
const startTime = res.startTime || res.competitionStartTime || res.beginTime || res.startDate
|
||||
const endTime = res.endTime || res.competitionEndTime || res.finishTime || res.endDate
|
||||
|
||||
// 如果没有时间字段,尝试使用其他字段
|
||||
let matchTime = this.formatTimeRange(startTime, endTime)
|
||||
if (!matchTime && res.matchTime) {
|
||||
matchTime = res.matchTime
|
||||
} else if (!matchTime && res.competitionTime) {
|
||||
matchTime = res.competitionTime
|
||||
} else if (!matchTime) {
|
||||
matchTime = '待定'
|
||||
}
|
||||
|
||||
this.eventInfo = {
|
||||
title: res.name || res.title || res.competitionName || '未命名赛事',
|
||||
location: res.location || res.address || res.venue || '待定',
|
||||
matchTime: matchTime,
|
||||
projects: this.selectedProjects && this.selectedProjects.length > 0
|
||||
? this.selectedProjects.map(p => p.name).join('、')
|
||||
: '',
|
||||
contact: res.contactPhone || res.contact || res.phone || '',
|
||||
participants: ''
|
||||
}
|
||||
} catch (err) {
|
||||
console.error('加载赛事详情失败:', err)
|
||||
// 设置默认值,防止页面显示空白
|
||||
this.eventInfo = {
|
||||
title: '未命名赛事',
|
||||
location: '待定',
|
||||
matchTime: '待定',
|
||||
projects: '',
|
||||
contact: '',
|
||||
participants: ''
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* 加载选手列表
|
||||
*/
|
||||
async loadPlayerList() {
|
||||
try {
|
||||
const res = await athleteAPI.getAthleteList({
|
||||
current: 1,
|
||||
size: 100
|
||||
})
|
||||
|
||||
let list = []
|
||||
if (res.records) {
|
||||
list = res.records
|
||||
} else if (Array.isArray(res)) {
|
||||
list = res
|
||||
}
|
||||
|
||||
// 数据映射 - 尝试多个可能的字段名
|
||||
this.playerList = list.map(item => ({
|
||||
id: item.id,
|
||||
// 尝试多个可能的姓名字段
|
||||
name: item.name || item.athleteName || item.playerName || item.realName || item.userName || '未命名',
|
||||
// 尝试多个可能的身份证字段
|
||||
idCard: item.idCard || item.idCardNumber || item.idCardNo || item.identityCard || '',
|
||||
selected: false
|
||||
}))
|
||||
} catch (err) {
|
||||
console.error('加载选手列表失败:', err)
|
||||
uni.showToast({
|
||||
title: '加载选手列表失败',
|
||||
icon: 'none'
|
||||
})
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* 格式化时间范围
|
||||
*/
|
||||
formatTimeRange(startTime, endTime) {
|
||||
if (!startTime || !endTime) return ''
|
||||
|
||||
const formatDate = (dateStr) => {
|
||||
if (!dateStr) return ''
|
||||
const date = new Date(dateStr)
|
||||
const year = date.getFullYear()
|
||||
const month = String(date.getMonth() + 1).padStart(2, '0')
|
||||
const day = String(date.getDate()).padStart(2, '0')
|
||||
return `${year}.${month}.${day}`
|
||||
}
|
||||
|
||||
return `${formatDate(startTime)}-${formatDate(endTime)}`
|
||||
},
|
||||
|
||||
/**
|
||||
* 计算总价
|
||||
*/
|
||||
calculateTotalPrice() {
|
||||
const count = this.selectedCount
|
||||
|
||||
if (!this.selectedProjects || this.selectedProjects.length === 0) {
|
||||
return 0
|
||||
}
|
||||
|
||||
// 计算所有项目的总价(将字符串转换为数字)
|
||||
const pricePerProject = this.selectedProjects.reduce((sum, p) => {
|
||||
const price = parseFloat(p.price || 0)
|
||||
return sum + price
|
||||
}, 0)
|
||||
|
||||
const total = count * pricePerProject
|
||||
|
||||
return total.toFixed(2)
|
||||
},
|
||||
|
||||
togglePlayer(item) {
|
||||
item.selected = !item.selected;
|
||||
this.$forceUpdate();
|
||||
const index = this.playerList.findIndex(p => p.id === item.id)
|
||||
if (index !== -1) {
|
||||
const newValue = !this.playerList[index].selected
|
||||
this.$set(this.playerList[index], 'selected', newValue)
|
||||
}
|
||||
},
|
||||
goToAddPlayer() {
|
||||
uni.navigateTo({
|
||||
@@ -234,27 +372,157 @@ export default {
|
||||
url: '/pages/edit-player/edit-player?id=' + item.id
|
||||
});
|
||||
},
|
||||
handleDelete(item) {
|
||||
uni.showModal({
|
||||
title: '删除选手',
|
||||
content: '确定要删除该选手吗?',
|
||||
success: (res) => {
|
||||
if (res.confirm) {
|
||||
const index = this.playerList.findIndex(p => p.id === item.id);
|
||||
if (index > -1) {
|
||||
this.playerList.splice(index, 1);
|
||||
}
|
||||
async handleDelete(item) {
|
||||
try {
|
||||
const confirmRes = await new Promise((resolve) => {
|
||||
uni.showModal({
|
||||
title: '删除选手',
|
||||
content: '确定要删除该选手吗?',
|
||||
success: (res) => resolve(res)
|
||||
})
|
||||
})
|
||||
|
||||
if (confirmRes.confirm) {
|
||||
await athleteAPI.removeAthlete(item.id)
|
||||
|
||||
const index = this.playerList.findIndex(p => p.id === item.id);
|
||||
if (index > -1) {
|
||||
this.playerList.splice(index, 1);
|
||||
}
|
||||
|
||||
uni.showToast({
|
||||
title: '删除成功',
|
||||
icon: 'success'
|
||||
})
|
||||
}
|
||||
});
|
||||
} catch (err) {
|
||||
console.error('删除选手失败:', err)
|
||||
uni.showToast({
|
||||
title: '删除失败',
|
||||
icon: 'none'
|
||||
})
|
||||
}
|
||||
},
|
||||
goToStep2() {
|
||||
this.currentStep = 2;
|
||||
const selected = this.playerList.filter(item => item.selected)
|
||||
|
||||
if (selected.length === 0) {
|
||||
uni.showToast({
|
||||
title: '请至少选择一名选手',
|
||||
icon: 'none'
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
// 更新参赛选手信息
|
||||
const participantsText = selected.map(p => p.name).join('、')
|
||||
|
||||
// 使用 $set 确保响应式更新
|
||||
this.$set(this.eventInfo, 'participants', participantsText)
|
||||
this.totalPrice = this.calculateTotalPrice()
|
||||
|
||||
// 延迟切换步骤,确保数据更新完成
|
||||
this.$nextTick(() => {
|
||||
this.currentStep = 2
|
||||
})
|
||||
},
|
||||
goToStep3() {
|
||||
this.currentStep = 3;
|
||||
async goToStep3() {
|
||||
try {
|
||||
// 获取选中的选手
|
||||
const selected = this.playerList.filter(item => item.selected)
|
||||
|
||||
// 检查必填字段
|
||||
if (!this.eventId) {
|
||||
uni.showToast({
|
||||
title: '赛事ID缺失',
|
||||
icon: 'none'
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
if (!this.selectedProjects || this.selectedProjects.length === 0) {
|
||||
uni.showToast({
|
||||
title: '请选择报名项目',
|
||||
icon: 'none'
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
if (selected.length === 0) {
|
||||
uni.showToast({
|
||||
title: '请选择参赛选手',
|
||||
icon: 'none'
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
// 生成订单号:格式 BMyyyyMMddHHmmss + 随机4位数
|
||||
const now = new Date()
|
||||
const year = now.getFullYear()
|
||||
const month = String(now.getMonth() + 1).padStart(2, '0')
|
||||
const day = String(now.getDate()).padStart(2, '0')
|
||||
const hours = String(now.getHours()).padStart(2, '0')
|
||||
const minutes = String(now.getMinutes()).padStart(2, '0')
|
||||
const seconds = String(now.getSeconds()).padStart(2, '0')
|
||||
const random = String(Math.floor(Math.random() * 10000)).padStart(4, '0')
|
||||
const orderNo = `BM${year}${month}${day}${hours}${minutes}${seconds}${random}`
|
||||
|
||||
// 构建提交数据 - 确保ID都是数字类型
|
||||
const submitData = {
|
||||
orderNo: orderNo,
|
||||
competitionId: parseInt(this.eventId),
|
||||
projectIds: this.selectedProjects.map(p => parseInt(p.id)),
|
||||
athleteIds: selected.map(p => parseInt(p.id)),
|
||||
contactPhone: this.eventInfo.contact || '',
|
||||
totalAmount: parseFloat(this.totalPrice) || 0
|
||||
}
|
||||
|
||||
console.log('=== 提交报名数据 ===')
|
||||
console.log('订单号:', submitData.orderNo)
|
||||
console.log('完整提交数据:', submitData)
|
||||
console.log('赛事ID:', submitData.competitionId, typeof submitData.competitionId)
|
||||
console.log('项目IDs:', submitData.projectIds)
|
||||
console.log('选手IDs:', submitData.athleteIds)
|
||||
console.log('联系电话:', submitData.contactPhone)
|
||||
console.log('总金额:', submitData.totalAmount, typeof submitData.totalAmount)
|
||||
|
||||
// 提交报名订单
|
||||
const res = await registrationAPI.submitRegistration(submitData)
|
||||
|
||||
// 保存报名ID
|
||||
this.registrationId = res.id || res.registrationId
|
||||
|
||||
// 更新选中的选手列表(包含编号)
|
||||
this.selectedPlayers = selected.map(item => ({
|
||||
name: item.name,
|
||||
idCard: item.idCard,
|
||||
number: item.number || `${this.registrationId}-${item.id}`
|
||||
}))
|
||||
|
||||
this.currentStep = 3;
|
||||
|
||||
uni.showToast({
|
||||
title: '报名成功',
|
||||
icon: 'success'
|
||||
})
|
||||
} catch (err) {
|
||||
console.error('提交报名失败:', err)
|
||||
uni.showToast({
|
||||
title: '报名失败,请重试',
|
||||
icon: 'none'
|
||||
})
|
||||
}
|
||||
},
|
||||
showPlayers() {
|
||||
// 更新选中的选手列表
|
||||
this.selectedPlayers = this.playerList
|
||||
.filter(item => item.selected)
|
||||
.map(item => ({
|
||||
name: item.name,
|
||||
idCard: item.idCard,
|
||||
number: ''
|
||||
}))
|
||||
|
||||
this.showPlayerModal = true;
|
||||
},
|
||||
handleClose() {
|
||||
|
||||
Reference in New Issue
Block a user