diff --git a/src/views/marketing/Voucher.vue b/src/views/marketing/Voucher.vue index cd070d3..44c575f 100644 --- a/src/views/marketing/Voucher.vue +++ b/src/views/marketing/Voucher.vue @@ -295,9 +295,39 @@ const handleEdit = (row) => { dialogType.value = 'edit' dialogVisible.value = true - // 转换日期字符串为日期选择器格式 - const startTime = row.startTime ? new Date(row.startTime).toLocaleString('zh-CN', {year: 'numeric', month: '2-digit', day: '2-digit', hour: '2-digit', minute: '2-digit', second: '2-digit'}).replace(/\//g, '-') : '' - const endTime = row.endTime ? new Date(row.endTime).toLocaleString('zh-CN', {year: 'numeric', month: '2-digit', day: '2-digit', hour: '2-digit', minute: '2-digit', second: '2-digit'}).replace(/\//g, '-') : '' + console.log('编辑代金券原始数据:', row) + + // 转换时间为日期字符串(YYYY-MM-DD HH:mm:ss 格式) + let startTime = '' + let endTime = '' + + if (row.startTime) { + // 处理字符串格式的时间(如 "2026-01-08T00:00:00+08:00") + const start = new Date(row.startTime) + if (!isNaN(start.getTime())) { + startTime = start.getFullYear() + '-' + + String(start.getMonth() + 1).padStart(2, '0') + '-' + + String(start.getDate()).padStart(2, '0') + ' ' + + String(start.getHours()).padStart(2, '0') + ':' + + String(start.getMinutes()).padStart(2, '0') + ':' + + String(start.getSeconds()).padStart(2, '0') + } + } + + if (row.endTime) { + // 处理字符串格式的时间(如 "2026-02-25T00:00:00+08:00") + const end = new Date(row.endTime) + if (!isNaN(end.getTime())) { + endTime = end.getFullYear() + '-' + + String(end.getMonth() + 1).padStart(2, '0') + '-' + + String(end.getDate()).padStart(2, '0') + ' ' + + String(end.getHours()).padStart(2, '0') + ':' + + String(end.getMinutes()).padStart(2, '0') + ':' + + String(end.getSeconds()).padStart(2, '0') + } + } + + console.log('转换后的时间:', { startTime, endTime }) Object.assign(voucherForm, { code_id: row.id, @@ -309,12 +339,14 @@ const handleEdit = (row) => { max_amount: row.maxAmount ? row.maxAmount / 100 : 0, max_times: row.maxTimes || 0, user_times: row.userTimes || 0, - duration_days: row.duration ? row.duration / 86400 : 30, // 秒转天 + duration_days: row.duration ? Math.round(row.duration / 86400) : 30, // 秒转天 timeRange: startTime && endTime ? [startTime, endTime] : [], renew: row.renew || false, can_stacking: row.canStacking || false, can_combine: row.canCombine || false }) + + console.log('表单数据:', voucherForm) } // 管理代金券 diff --git a/src/views/product/ProductList.vue b/src/views/product/ProductList.vue index 332687f..b3c1cb9 100644 --- a/src/views/product/ProductList.vue +++ b/src/views/product/ProductList.vue @@ -392,7 +392,7 @@