迁移婚礼弹窗组件脚本
This commit is contained in:
@@ -680,154 +680,3 @@
|
||||
}
|
||||
}
|
||||
</style>
|
||||
|
||||
{{-- ═══════════ Alpine.js 组件脚本 ═══════════ --}}
|
||||
<script>
|
||||
function weddingSetupModal() {
|
||||
return {
|
||||
show: false,
|
||||
marriageId: null,
|
||||
tiers: [],
|
||||
selectedTier: null,
|
||||
payBy: 'groom',
|
||||
loading: false,
|
||||
sending: false,
|
||||
error: '',
|
||||
|
||||
|
||||
get myCost() {
|
||||
if (!this.selectedTier) return 0;
|
||||
return this.payBy === 'split' ?
|
||||
Math.ceil(this.selectedTier.amount / 2) :
|
||||
this.selectedTier.amount;
|
||||
},
|
||||
|
||||
async open(marriageId) {
|
||||
this.marriageId = marriageId;
|
||||
this.selectedTier = null;
|
||||
this.payBy = 'groom';
|
||||
this.error = '';
|
||||
this.loading = true;
|
||||
this.show = true;
|
||||
try {
|
||||
const res = await fetch(window.chatContext.marriage.weddingTiersUrl, {
|
||||
headers: {
|
||||
'Accept': 'application/json'
|
||||
}
|
||||
});
|
||||
const data = await res.json();
|
||||
if (data.status === 'success') {
|
||||
this.tiers = data.tiers;
|
||||
if (this.tiers.length > 0) this.selectedTier = this.tiers[0];
|
||||
}
|
||||
} catch {
|
||||
this.tiers = [];
|
||||
}
|
||||
this.loading = false;
|
||||
},
|
||||
|
||||
close() {
|
||||
this.show = false;
|
||||
},
|
||||
|
||||
async doSetup() {
|
||||
if (this.sending || !this.selectedTier) return;
|
||||
this.error = '';
|
||||
this.sending = true;
|
||||
try {
|
||||
// 固定使用立即举办,不再需要用户选择时间
|
||||
const body = {
|
||||
tier_id: this.selectedTier.id,
|
||||
payer_type: this.payBy,
|
||||
ceremony_type: 'immediate',
|
||||
room_id: window.chatContext.roomId,
|
||||
};
|
||||
const res = await fetch(window.chatContext.marriage.weddingSetupUrl(this.marriageId), {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'Accept': 'application/json',
|
||||
'X-CSRF-TOKEN': document.querySelector('meta[name=csrf-token]').content
|
||||
},
|
||||
body: JSON.stringify(body)
|
||||
});
|
||||
const data = await res.json();
|
||||
if (data.status === 'success') {
|
||||
this.close();
|
||||
window.chatDialog?.alert('🎊 婚礼已开始!红包正在分发给在线用户…', '设置成功', '#f59e0b');
|
||||
} else {
|
||||
this.error = data.message || '设置失败';
|
||||
}
|
||||
} catch {
|
||||
this.error = '网络异常,请稍后重试';
|
||||
}
|
||||
this.sending = false;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* 婚礼红包弹窗组件
|
||||
*/
|
||||
function weddingEnvelopeModal() {
|
||||
return {
|
||||
show: false,
|
||||
marriageId: null,
|
||||
ceremonyId: null,
|
||||
title: '',
|
||||
subTitle: '',
|
||||
claimed: false,
|
||||
claiming: false,
|
||||
claimedAmount: 0,
|
||||
|
||||
open(detail) {
|
||||
this.marriageId = detail.marriage_id;
|
||||
this.ceremonyId = detail.ceremony_id;
|
||||
// 兼容两种字段命名:groom_name/bride_name 或 user.username/partner.username
|
||||
const groomName = detail.groom_name ?? detail.user?.username ?? '??';
|
||||
const brideName = detail.bride_name ?? detail.partner?.username ?? '??';
|
||||
this.title = `${groomName} × ${brideName} 婚礼红包`;
|
||||
this.subTitle = detail.tier_name ? `【${detail.tier_name}】普天同庆` : '婚礼庆典红包';
|
||||
this.claimed = false;
|
||||
this.claimedAmount = 0;
|
||||
this.show = true;
|
||||
},
|
||||
|
||||
close() {
|
||||
this.show = false;
|
||||
},
|
||||
|
||||
async doClaim() {
|
||||
if (this.claiming || this.claimed) return;
|
||||
this.claiming = true;
|
||||
try {
|
||||
// 正确路由:/wedding/ceremony/{ceremonyId}/claim
|
||||
const res = await fetch(`/wedding/ceremony/${this.ceremonyId}/claim`, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'Accept': 'application/json',
|
||||
'X-CSRF-TOKEN': document.querySelector('meta[name=csrf-token]').content
|
||||
},
|
||||
body: JSON.stringify({
|
||||
ceremony_id: this.ceremonyId
|
||||
})
|
||||
});
|
||||
const data = await res.json();
|
||||
if (data.ok) {
|
||||
this.claimed = true;
|
||||
this.claimedAmount = data.amount || 0;
|
||||
} else {
|
||||
window.chatDialog?.alert(data.message || '领取失败', '提示', '#f59e0b');
|
||||
if (data.message?.includes('已领取') || data.message?.includes('已过期')) {
|
||||
this.claimed = true;
|
||||
}
|
||||
}
|
||||
} catch {
|
||||
window.chatDialog?.alert('网络异常', '错误', '#cc4444');
|
||||
}
|
||||
this.claiming = false;
|
||||
}
|
||||
};
|
||||
}
|
||||
</script>
|
||||
|
||||
Reference in New Issue
Block a user