From e037eaafef2d7e092c09f43ea2252f0d0073e88d Mon Sep 17 00:00:00 2001 From: wood chen Date: Wed, 12 Mar 2025 15:50:00 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E4=BB=B7=E6=A0=BC=E7=AE=A1?= =?UTF-8?q?=E7=90=86=E4=B8=AD=E7=9A=84=20channel=5Ftype=20=E7=B1=BB?= =?UTF-8?q?=E5=9E=8B=E8=BD=AC=E6=8D=A2=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 在提交价格表单时,将 channel_type 显式转换为数字类型 - 确保批量添加价格和单个价格提交时 channel_type 正确处理 - 修复可能由于类型不匹配导致的数据提交错误 --- frontend/src/views/Prices.vue | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/frontend/src/views/Prices.vue b/frontend/src/views/Prices.vue index 353acd3..13e4363 100644 --- a/frontend/src/views/Prices.vue +++ b/frontend/src/views/Prices.vue @@ -697,10 +697,17 @@ const handleQuickEdit = (row) => { const submitForm = async () => { try { form.value.created_by = props.user.username + + // 创建一个新对象用于提交,将 channel_type 转换为数字类型 + const formToSubmit = { ...form.value } + if (formToSubmit.channel_type) { + formToSubmit.channel_type = parseInt(formToSubmit.channel_type, 10) + } + let response if (editingPrice.value) { // 更新已存在的价格 - response = await axios.put(`/api/prices/${editingPrice.value.id}`, form.value) + response = await axios.put(`/api/prices/${editingPrice.value.id}`, formToSubmit) } else { // 检查模型是否已存在 const existingPrice = prices.value?.find(p => @@ -717,7 +724,7 @@ const submitForm = async () => { type: 'warning', } ).then(async () => { - response = await axios.put(`/api/prices/${existingPrice.id}`, form.value) + response = await axios.put(`/api/prices/${existingPrice.id}`, formToSubmit) handleSubmitResponse(response) }).catch(() => { // 用户取消更新 @@ -725,7 +732,7 @@ const submitForm = async () => { return } // 创建新价格 - response = await axios.post('/api/prices', form.value) + response = await axios.post('/api/prices', formToSubmit) } handleSubmitResponse(response) } catch (error) { @@ -896,7 +903,12 @@ const submitBatchForms = async () => { try { // 逐个提交数据 for (const form of batchForms.value) { - await axios.post('/api/prices', form) + // 创建一个新对象用于提交,将 channel_type 转换为数字类型 + const formToSubmit = { ...form } + if (formToSubmit.channel_type) { + formToSubmit.channel_type = parseInt(formToSubmit.channel_type, 10) + } + await axios.post('/api/prices', formToSubmit) } await loadPrices() @@ -961,7 +973,7 @@ const handleImport = () => { return { model, billing_type, - channel_type: provider.id.toString(), + channel_type: parseInt(provider.id, 10), // 确保是数字类型 currency: currencyCode, input_price: parseFloat(inputPrice), output_price: parseFloat(outputPrice),