331 lines
7.6 KiB
Vue
331 lines
7.6 KiB
Vue
<template>
|
||
<div class="co-organizer-manager">
|
||
<div class="header">
|
||
<span class="title">承办方信息</span>
|
||
<el-button type="primary" size="small" @click="handleAdd">
|
||
<el-icon><Plus /></el-icon>
|
||
添加承办方
|
||
</el-button>
|
||
</div>
|
||
|
||
<div v-if="coOrganizers.length === 0" class="empty-state">
|
||
<el-empty description="暂无承办方信息" :image-size="80" />
|
||
</div>
|
||
|
||
<div v-else class="organizer-list">
|
||
<div
|
||
v-for="(organizer, index) in coOrganizers"
|
||
:key="index"
|
||
class="organizer-item"
|
||
>
|
||
<div class="organizer-content">
|
||
<div class="organizer-info">
|
||
<div class="info-row">
|
||
<span class="label">承办方名称:</span>
|
||
<span class="value">{{ organizer.name || '未填写' }}</span>
|
||
<span class="label" v-if="organizer.contact">联系人:</span>
|
||
<span class="value" v-if="organizer.contact">{{ organizer.contact }}</span>
|
||
<span class="label" v-if="organizer.phone">联系电话:</span>
|
||
<span class="value" v-if="organizer.phone">{{ organizer.phone }}</span>
|
||
</div>
|
||
</div>
|
||
<div class="organizer-actions">
|
||
<el-button
|
||
type="danger"
|
||
circle
|
||
size="small"
|
||
@click="handleDelete(index)"
|
||
title="删除"
|
||
>
|
||
<el-icon><Delete /></el-icon>
|
||
</el-button>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
|
||
<!-- 添加/编辑承办方对话框 -->
|
||
<el-dialog
|
||
v-model="dialogVisible"
|
||
:title="dialogTitle"
|
||
width="500px"
|
||
append-to-body
|
||
>
|
||
<el-form
|
||
ref="formRef"
|
||
:model="currentOrganizer"
|
||
:rules="rules"
|
||
label-width="100px"
|
||
>
|
||
<el-form-item label="承办方名称" prop="name">
|
||
<el-input
|
||
v-model="currentOrganizer.name"
|
||
placeholder="请输入承办方名称"
|
||
maxlength="100"
|
||
show-word-limit
|
||
/>
|
||
</el-form-item>
|
||
|
||
<el-form-item label="联系人" prop="contact">
|
||
<el-input
|
||
v-model="currentOrganizer.contact"
|
||
placeholder="请输入联系人姓名"
|
||
maxlength="50"
|
||
/>
|
||
</el-form-item>
|
||
<el-form-item label="联系电话" prop="phone">
|
||
<el-input
|
||
v-model="currentOrganizer.phone"
|
||
placeholder="请输入联系电话"
|
||
maxlength="20"
|
||
/>
|
||
</el-form-item>
|
||
</el-form>
|
||
|
||
<template #footer>
|
||
<div class="dialog-footer">
|
||
<el-button @click="handleCancel">取消</el-button>
|
||
<el-button type="primary" @click="handleConfirm">确定</el-button>
|
||
</div>
|
||
</template>
|
||
</el-dialog>
|
||
</div>
|
||
</template>
|
||
|
||
<script setup lang="ts">
|
||
import { ref, computed, watch } from 'vue';
|
||
import { Plus, Delete } from '@element-plus/icons-vue';
|
||
import { CoOrganizerInfo } from '@/api/stgl/activity/types';
|
||
import type { FormInstance, FormRules } from 'element-plus';
|
||
|
||
interface Props {
|
||
modelValue: CoOrganizerInfo[];
|
||
}
|
||
|
||
interface Emits {
|
||
(e: 'update:modelValue', value: CoOrganizerInfo[]): void;
|
||
(e: 'change', value: CoOrganizerInfo[]): void;
|
||
}
|
||
|
||
const props = withDefaults(defineProps<Props>(), {
|
||
modelValue: () => []
|
||
});
|
||
|
||
const emit = defineEmits<Emits>();
|
||
|
||
const dialogVisible = ref(false);
|
||
const editIndex = ref(-1);
|
||
const formRef = ref<FormInstance>();
|
||
|
||
const coOrganizers = ref<CoOrganizerInfo[]>([...props.modelValue]);
|
||
|
||
// 当前编辑的承办方
|
||
const currentOrganizer = ref<CoOrganizerInfo>({
|
||
name: '',
|
||
contact: '',
|
||
phone: ''
|
||
});
|
||
|
||
// 对话框标题
|
||
const dialogTitle = computed(() => {
|
||
return editIndex.value >= 0 ? '编辑承办方' : '添加承办方';
|
||
});
|
||
|
||
// 表单验证规则
|
||
const rules: FormRules = {
|
||
name: [
|
||
{ required: true, message: '请输入承办方名称', trigger: 'blur' },
|
||
{ min: 1, max: 100, message: '承办方名称长度在1到100个字符', trigger: 'blur' }
|
||
],
|
||
|
||
contact: [
|
||
{ max: 50, message: '联系人姓名长度不能超过50个字符', trigger: 'blur' }
|
||
],
|
||
phone: [
|
||
{ max: 20, message: '联系电话长度不能超过20个字符', trigger: 'blur' },
|
||
{ pattern: /^[0-9\-\s\+\(\)]*$/, message: '请输入正确的电话号码格式', trigger: 'blur' }
|
||
]
|
||
};
|
||
|
||
// 监听props变化
|
||
watch(
|
||
() => props.modelValue,
|
||
(newValue) => {
|
||
coOrganizers.value = [...newValue];
|
||
},
|
||
{ deep: true }
|
||
);
|
||
|
||
// 监听内部数据变化,同步到父组件
|
||
watch(
|
||
coOrganizers,
|
||
(newValue) => {
|
||
emit('update:modelValue', newValue);
|
||
emit('change', newValue);
|
||
},
|
||
{ deep: true }
|
||
);
|
||
|
||
// 添加承办方
|
||
const handleAdd = () => {
|
||
editIndex.value = -1;
|
||
currentOrganizer.value = {
|
||
name: '',
|
||
contact: '',
|
||
phone: ''
|
||
};
|
||
dialogVisible.value = true;
|
||
};
|
||
|
||
|
||
|
||
// 删除承办方
|
||
const handleDelete = (index: number) => {
|
||
ElMessageBox.confirm('确定要删除这个承办方吗?', '提示', {
|
||
confirmButtonText: '确定',
|
||
cancelButtonText: '取消',
|
||
type: 'warning'
|
||
}).then(() => {
|
||
coOrganizers.value.splice(index, 1);
|
||
ElMessage.success('删除成功');
|
||
}).catch(() => {
|
||
// 用户取消删除
|
||
});
|
||
};
|
||
|
||
// 确认添加/编辑
|
||
const handleConfirm = () => {
|
||
if (!formRef.value) return;
|
||
|
||
formRef.value.validate((valid) => {
|
||
if (valid) {
|
||
// 保存当前操作类型和数据,避免状态重置后丢失
|
||
const isEdit = editIndex.value >= 0;
|
||
const currentData = { ...currentOrganizer.value };
|
||
const currentIndex = editIndex.value;
|
||
|
||
// 立即关闭弹窗,避免后续操作影响弹窗状态
|
||
dialogVisible.value = false;
|
||
|
||
// 重置编辑状态
|
||
editIndex.value = -1;
|
||
|
||
// 重置表单
|
||
formRef.value?.resetFields();
|
||
|
||
// 延迟一帧更新数据,确保弹窗已完全关闭
|
||
setTimeout(() => {
|
||
if (isEdit) {
|
||
// 编辑模式
|
||
coOrganizers.value[currentIndex] = currentData;
|
||
ElMessage.success('编辑成功');
|
||
} else {
|
||
// 添加模式
|
||
coOrganizers.value.push(currentData);
|
||
ElMessage.success('添加成功');
|
||
}
|
||
}, 0);
|
||
}
|
||
});
|
||
};
|
||
|
||
// 取消操作
|
||
const handleCancel = () => {
|
||
// 立即关闭弹窗
|
||
dialogVisible.value = false;
|
||
|
||
// 重置编辑状态
|
||
editIndex.value = -1;
|
||
|
||
// 重置表单
|
||
formRef.value?.resetFields();
|
||
};
|
||
</script>
|
||
|
||
<style scoped>
|
||
.co-organizer-manager {
|
||
width: 100%;
|
||
}
|
||
|
||
.header {
|
||
display: flex;
|
||
justify-content: space-between;
|
||
align-items: center;
|
||
margin-bottom: 16px;
|
||
}
|
||
|
||
.title {
|
||
font-size: 14px;
|
||
font-weight: 600;
|
||
color: #303133;
|
||
}
|
||
|
||
.empty-state {
|
||
text-align: center;
|
||
padding: 40px 20px;
|
||
border: 1px dashed #dcdfe6;
|
||
border-radius: 4px;
|
||
background-color: #fafafa;
|
||
}
|
||
|
||
.organizer-list {
|
||
space-y: 12px;
|
||
}
|
||
|
||
.organizer-item {
|
||
border: 1px solid #e4e7ed;
|
||
border-radius: 6px;
|
||
padding: 16px;
|
||
background-color: #fafafa;
|
||
margin-bottom: 12px;
|
||
transition: all 0.3s ease;
|
||
}
|
||
|
||
.organizer-item:hover {
|
||
border-color: #409eff;
|
||
box-shadow: 0 2px 8px rgba(64, 158, 255, 0.1);
|
||
}
|
||
|
||
.organizer-content {
|
||
display: flex;
|
||
justify-content: space-between;
|
||
align-items: flex-start;
|
||
}
|
||
|
||
.organizer-info {
|
||
flex: 1;
|
||
}
|
||
|
||
.info-row {
|
||
display: flex;
|
||
align-items: center;
|
||
flex-wrap: wrap;
|
||
gap: 16px;
|
||
}
|
||
|
||
.label {
|
||
font-size: 13px;
|
||
color: #606266;
|
||
margin-right: 4px;
|
||
}
|
||
|
||
.value {
|
||
font-size: 13px;
|
||
color: #303133;
|
||
font-weight: 500;
|
||
margin-right: 12px;
|
||
}
|
||
|
||
.organizer-actions {
|
||
display: flex;
|
||
flex-direction: column;
|
||
gap: 4px;
|
||
margin-left: 16px;
|
||
}
|
||
|
||
.dialog-footer {
|
||
display: flex;
|
||
justify-content: flex-end;
|
||
gap: 10px;
|
||
}
|
||
</style> |