迁移求婚弹窗组件脚本
This commit is contained in:
@@ -683,110 +683,6 @@
|
||||
|
||||
{{-- ═══════════ Alpine.js 组件脚本 ═══════════ --}}
|
||||
<script>
|
||||
/**
|
||||
* 求婚弹窗组件
|
||||
*/
|
||||
function marriageProposeModal() {
|
||||
return {
|
||||
show: false,
|
||||
targetUsername: '',
|
||||
marriageId: null, // 当前对方婚姻/求婚记录 ID(accept/reject 用)
|
||||
rings: [],
|
||||
selectedRing: null,
|
||||
tiers: @json(\App\Models\WeddingTier::where('is_active', true)->orderBy('amount')->get()),
|
||||
selectedTierId: @json(\App\Models\WeddingTier::where('is_active', true)->orderBy('amount')->value('id') ?? ''), // 默认选最小档位
|
||||
loading: false,
|
||||
sending: false,
|
||||
error: '',
|
||||
|
||||
get selectedTier() {
|
||||
if (!this.selectedTierId) return null;
|
||||
return this.tiers.find(t => t.id == this.selectedTierId);
|
||||
},
|
||||
|
||||
get canAfford() {
|
||||
const amount = this.selectedTier ? Number(this.selectedTier.amount) : 0;
|
||||
return window.chatContext.userJjb >= amount;
|
||||
},
|
||||
|
||||
async open(username) {
|
||||
this.targetUsername = username;
|
||||
this.selectedRing = null;
|
||||
this.error = '';
|
||||
this.loading = true;
|
||||
this.show = true;
|
||||
try {
|
||||
const res = await fetch(window.chatContext.marriage.myRingsUrl, {
|
||||
headers: {
|
||||
'Accept': 'application/json'
|
||||
}
|
||||
});
|
||||
const data = await res.json();
|
||||
if (data.status === 'success') {
|
||||
this.rings = data.rings;
|
||||
if (this.rings.length > 0) this.selectedRing = this.rings[0].purchase_id;
|
||||
}
|
||||
} catch {
|
||||
this.rings = [];
|
||||
}
|
||||
this.loading = false;
|
||||
},
|
||||
|
||||
/**
|
||||
* 由 openProposeModal() 传入已预加载的戒指列表,无需二次请求。
|
||||
* @param {string} username 求婚对象用户名
|
||||
* @param {Array} rings 已加载的戒指列表
|
||||
*/
|
||||
openWithRings(username, rings) {
|
||||
this.targetUsername = username;
|
||||
this.error = '';
|
||||
this.loading = false;
|
||||
this.rings = rings;
|
||||
this.selectedRing = rings.length > 0 ? rings[0].purchase_id : null;
|
||||
this.show = true;
|
||||
},
|
||||
|
||||
close() {
|
||||
this.show = false;
|
||||
},
|
||||
|
||||
async doPropose() {
|
||||
if (this.sending || !this.selectedRing) return;
|
||||
|
||||
// 费用信息已在弹窗内展示,此处无需二次确认弹窗
|
||||
|
||||
this.sending = true;
|
||||
this.error = '';
|
||||
try {
|
||||
const res = await fetch(window.chatContext.marriage.proposeUrl, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'Accept': 'application/json',
|
||||
'X-CSRF-TOKEN': document.querySelector('meta[name=csrf-token]').content
|
||||
},
|
||||
body: JSON.stringify({
|
||||
target_username: this.targetUsername,
|
||||
ring_purchase_id: this.selectedRing,
|
||||
wedding_tier_id: this.selectedTierId || null,
|
||||
room_id: window.chatContext.roomId
|
||||
})
|
||||
});
|
||||
const data = await res.json();
|
||||
if (data.status === 'success') {
|
||||
this.close();
|
||||
window.chatDialog?.alert('💍 求婚成功!等待对方回应(有效期 48 小时)', '已发出', '#f43f5e');
|
||||
} else {
|
||||
this.error = data.message || '求婚失败';
|
||||
}
|
||||
} catch {
|
||||
this.error = '网络异常,请稍后重试';
|
||||
}
|
||||
this.sending = false;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* 收到求婚弹窗组件
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user