diff --git a/src/views/activity/GroupBuyType.vue b/src/views/activity/GroupBuyType.vue index 6177487..97f5f97 100644 --- a/src/views/activity/GroupBuyType.vue +++ b/src/views/activity/GroupBuyType.vue @@ -69,8 +69,46 @@ - - + + + + 添加字段 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 删除 + + + + @@ -99,15 +137,24 @@ const isEdit = ref(false) const submitLoading = ref(false) const formRef = ref(null) -const form = reactive({ id: '', name: '', price: 0, renewPrice: 0, maxPerson: 5, tag: '', expireTime: null, note: '' }) +const form = reactive({ id: '', name: '', price: 0, renewPrice: 0, maxPerson: 5, tag: '', expireTime: null, noteFields: [] }) const rules = { name: [{ required: true, message: '请输入名称', trigger: 'blur' }], price: [{ required: true, message: '请输入价格', trigger: 'blur' }], renewPrice: [{ required: true, message: '请输入续费价格', trigger: 'blur' }], maxPerson: [{ required: true, message: '请输入拼团人数', trigger: 'blur' }], tag: [{ required: true, message: '请选择标签', trigger: 'change' }], - expireTime: [{ required: true, message: '请选择过期时间', trigger: 'change' }], - note: [{ required: true, message: '请输入备注', trigger: 'blur' }] + expireTime: [{ required: true, message: '请选择过期时间', trigger: 'change' }] +} + +// 添加备注字段 +const addNoteField = () => { + form.noteFields.push({ key: '', label: '', defaultValue: '', type: 'text', required: false }) +} + +// 删除备注字段 +const removeNoteField = (index) => { + form.noteFields.splice(index, 1) } const formatTime = (timeStr) => { @@ -156,13 +203,17 @@ const handleTagChange = (tag) => { const handleAdd = () => { isEdit.value = false - Object.assign(form, { id: '', name: '', price: 0, renewPrice: 0, maxPerson: 5, tag: '', expireTime: null, note: '' }) + Object.assign(form, { id: '', name: '', price: 0, renewPrice: 0, maxPerson: 5, tag: '', expireTime: null, noteFields: [] }) dialogVisible.value = true } const handleEdit = (row) => { isEdit.value = true - Object.assign(form, { id: row.id, name: row.name, price: row.price, renewPrice: row.renewPrice, maxPerson: row.maxPerson, tag: row.tag || '', expireTime: row.expireTime || null, note: row.note || '' }) + let noteFields = [] + try { + noteFields = row.note ? JSON.parse(row.note) : [] + } catch { noteFields = [] } + Object.assign(form, { id: row.id, name: row.name, price: row.price, renewPrice: row.renewPrice, maxPerson: row.maxPerson, tag: row.tag || '', expireTime: row.expireTime || null, noteFields }) dialogVisible.value = true } @@ -172,6 +223,7 @@ const handleSubmit = async () => { if (!valid) return submitLoading.value = true try { + const noteJson = JSON.stringify(form.noteFields.filter(f => f.key)) const data = { name: form.name, price: String(form.price), @@ -179,7 +231,7 @@ const handleSubmit = async () => { max_person: String(form.maxPerson), tag: form.tag, expire_time: form.expireTime ? Math.floor(new Date(form.expireTime).getTime() / 1000) : 0, - note: form.note + note: noteJson } if (isEdit.value) data.id = String(form.id) const res = isEdit.value ? await updateGroupBuyType(data) : await addGroupBuyType(data) @@ -223,4 +275,5 @@ onMounted(() => { fetchTags() }) .header-actions { display: flex; align-items: center; } .table-card { box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1); } .pagination-wrapper { margin-top: 20px; display: flex; justify-content: flex-end; } +.note-fields-container { width: 100%; }