feat: 实现修改货道号弹窗功能,支持批量修改选中商品的货道号

This commit is contained in:
yangmf_0726 committed 2025-11-18 14:10:36 +08:00
1 parent 0cd4621cad
commit ede1f34ef4
1 file changed
+82 -2
@@ -274,6 +274,23 @@
@pagination="getList"
/>
</ContentWrap>
<!-- 修改货道号弹窗 -->
<el-dialog v-model="channelDialogVisible" title="修改货道号" width="500px">
<el-form ref="channelFormRef" :model="channelForm" label-width="100px">
<el-form-item label="货道号" prop="cabinetChannel" :rules="[{ required: true, message: '请输入货道号', trigger: 'blur' }]">
<el-input
v-model="channelForm.cabinetChannel"
placeholder="请输入货道号"
clearable
/>
</el-form-item>
</el-form>
<template #footer>
<el-button @click="channelDialogVisible = false">取消</el-button>
<el-button type="primary" :loading="channelLoading" @click="handleConfirmModifyChannel">确定</el-button>
</template>
</el-dialog>
</template>
<script lang="ts" setup>
import { TabsPaneContext } from 'element-plus'
@@ -299,6 +316,12 @@ const total = ref(0) // 列表的总页数
const list = ref<ProductSpuApi.Spu[]>([]) // 列表的数据
const selectedRows = ref<ProductSpuApi.Spu[]>([]) // 选中的商品
const copyLoading = ref(false) // 复制操作的加载中
const channelDialogVisible = ref(false) // 修改货道号弹窗显示状态
const channelLoading = ref(false) // 修改货道号加载中
const channelFormRef = ref() // 货道号表单引用
const channelForm = ref({
cabinetChannel: '' // 货道号
})
// tabs 数据
const tabsData = ref([
{
@@ -571,8 +594,65 @@ const handleModifyChannel = () => {
message.warning('请至少选择一个商品进行修改货道号')
return
}
// TODO: 实现修改货道号的逻辑
message.info('修改货道号功能待实现')
// 重置表单
channelForm.value.cabinetChannel = ''
channelDialogVisible.value = true
}
/** 确认修改货道号 */
const handleConfirmModifyChannel = async () => {
if (!channelFormRef.value) return
try {
// 表单验证
await channelFormRef.value.validate()
if (!channelForm.value.cabinetChannel) {
message.warning('请输入货道号')
return
}
channelLoading.value = true
// 遍历选中的商品,逐个修改货道号
for (const row of selectedRows.value) {
try {
// 获取商品详情
const productDetail = await ProductSpuApi.getSpu(row.id!)
// 更新 skus 中的货道号,name 使用 spu 的 name,其他参数保持不变
const updatedSkus = productDetail.skus?.map(sku => ({
...sku,
name: productDetail.name, // 使用外层 spu 的 name
cabinetChannel: channelForm.value.cabinetChannel
})) || []
// 准备更新数据,只修改 skus 的货道号,其他参数保持原样
const updateData: ProductSpuApi.Spu = {
...productDetail,
skus: updatedSkus
}
// 调用更新接口
await ProductSpuApi.updateSpu(updateData)
} catch (error) {
console.error(`修改商品 ${row.name} 货道号失败:`, error)
message.error(`修改商品 "${row.name}" 货道号失败`)
}
}
message.success(`成功修改 ${selectedRows.value.length} 个商品的货道号`)
// 关闭弹窗
channelDialogVisible.value = false
// 清空选中
selectedRows.value = []
// 刷新列表
await getList()
} catch (error) {
console.error('修改货道号失败:', error)
} finally {
channelLoading.value = false
}
}
/** 查看商品详情 */