import { models, db, _ } from '../../utils/cloudbase.js' Page({ data: { selectedReasons: [], feedback: '' // 新增 feedback 字段 }, onLoad(options) { // 页面加载时的初始化操作 }, handleCheckboxChange(e) { console.log('checkbox change:', e.detail.value); // e.detail.value 是一个数组 this.setData({ selectedReasons: e.detail.value }); }, handleFeedbackInput(e) { this.setData({ feedback: e.detail.value }); }, async confirmLogout() { const { selectedReasons, feedback } = this.data; if (selectedReasons.length === 0) { wx.showToast({ title: '请选择注销原因', icon: 'none' }); return; } if (!feedback.trim()) { wx.showToast({ title: '请输入意见或建议', icon: 'none' }); return; } // 弹出确认框 const that = this; // 保证作用域正确 wx.showModal({ title: '提示', content: '确定要注销吗?', success: async function (res) { if (res.confirm) { // 获取本地用户信息 const userInfo = wx.getStorageSync('userInfo'); if (!userInfo || !userInfo._id) { wx.showToast({ title: '用户信息异常', icon: 'none' }); return; } const reasonStr = that.data.selectedReasons.join(','); try { const { data } = await models.wx_user.update({ data: { delete: 1, // 逻辑删除 log_off: reasonStr, }, filter: { where: { _id: { $eq: userInfo._id, } } }, envType: "prod" }); if (data.count > 0) { // 注销成功,清除本地缓存 wx.removeStorageSync('userInfo'); wx.showToast({ title: '注销成功', icon: 'success', duration: 2000 }); // 可选:跳转到登录页 setTimeout(() => { wx.redirectTo({ url: '/pages/logins/logins' }); }, 2000); } else { wx.showToast({ title: '注销失败', icon: 'none' }); } } catch (err) { console.error('注销失败:', err); wx.showToast({ title: '服务器错误', icon: 'none' }); } } else { console.log('用户取消注销'); } } }); } });