迁移离婚弹窗组件脚本

This commit is contained in:
2026-04-25 19:20:33 +08:00
parent be0052119f
commit 2e8bfb61c2
3 changed files with 169 additions and 144 deletions
@@ -683,150 +683,6 @@
{{-- ═══════════ Alpine.js 组件脚本 ═══════════ --}}
<script>
/**
* 发起离婚确认弹窗(发起方专用:展示双方结果 + 实时惩罚值)
*/
function divorceConfirmModal() {
return {
show: false,
marriageId: null,
mutualPenalty: 0,
forcedPenalty: 0,
mutualCooldown: 0,
forcedCooldown: 0,
acting: false,
error: '',
open(marriageId, config) {
this.marriageId = marriageId;
this.mutualPenalty = config.mutual_charm_penalty ?? 0;
this.forcedPenalty = config.forced_charm_penalty ?? 0;
this.mutualCooldown = config.mutual_cooldown_days ?? 0;
this.forcedCooldown = config.forced_cooldown_days ?? 0;
this.acting = false;
this.error = '';
this.show = true;
},
close() {
this.show = false;
},
/** 确认发起离婚申请 */
async doConfirm() {
if (this.acting) return;
this.acting = true;
this.error = '';
try {
const res = await fetch(window.chatContext.marriage.divorceUrl(this.marriageId), {
method: 'POST',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json',
'X-CSRF-TOKEN': document.querySelector('meta[name=csrf-token]').content
}
});
const data = await res.json();
this.close();
if (data.ok) {
window.chatDialog?.alert(data.message, '申请已发出 📩', '#6b7280');
} else {
window.chatDialog?.alert(data.message || '操作失败', '错误', '#dc2626');
}
} catch (e) {
this.error = '网络请求失败,请重试。';
} finally {
this.acting = false;
}
}
};
}
/**
* 离婚申请通知弹窗(被申请方专用:三选 + 真实惩罚值)
*/
function divorceRequestModal() {
return {
show: false,
marriageId: null,
initiatorName: '',
mutualPenalty: 0, // 同意后双方各扣魅力
forcedPenalty: 0, // 不同意后申请方被扣魅力
acting: false,
error: '',
open(detail) {
this.marriageId = detail.marriage_id;
this.initiatorName = detail.initiator_name ?? detail.divorcer_username ?? '对方';
this.mutualPenalty = detail.mutual_charm_penalty ?? 0;
this.forcedPenalty = detail.forced_charm_penalty ?? 0;
this.acting = false;
this.error = '';
this.show = true;
},
close() {
this.show = false;
},
/** 同意:协议离婚,双方各扣 mutualPenalty 魅力 */
async doAgree() {
if (this.acting) return;
this.acting = true;
this.error = '';
try {
const res = await fetch(window.chatContext.marriage.confirmDivorceUrl(this.marriageId), {
method: 'POST',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json',
'X-CSRF-TOKEN': document.querySelector('meta[name=csrf-token]').content
},
body: JSON.stringify({
room_id: window.chatContext.roomId
})
});
const data = await res.json();
this.close();
window.chatDialog?.alert(data.message, data.ok ? '操作完成' : '失败', data.ok ? '#6b7280' :
'#cc4444');
} catch (e) {
this.error = '网络请求失败,请重试。';
} finally {
this.acting = false;
}
},
/** 不同意:视为强制离婚,申请方扣魅力 + 赔一半金币 */
async doReject() {
if (this.acting) return;
this.acting = true;
this.error = '';
try {
const res = await fetch(window.chatContext.marriage.rejectDivorceUrl(this.marriageId), {
method: 'POST',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json',
'X-CSRF-TOKEN': document.querySelector('meta[name=csrf-token]').content
},
body: JSON.stringify({
room_id: window.chatContext.roomId
})
});
const data = await res.json();
this.close();
window.chatDialog?.alert(data.message, data.ok ? '已处理' : '失败', data.ok ? '#d97706' : '#cc4444');
} catch (e) {
this.error = '网络请求失败,请重试。';
} finally {
this.acting = false;
}
}
};
}
function weddingSetupModal() {
return {
show: false,