完成调查问卷
This commit is contained in:
324
src/views/system/Questionnaire/addQuestionnaire.vue
Normal file
324
src/views/system/Questionnaire/addQuestionnaire.vue
Normal file
@@ -0,0 +1,324 @@
|
||||
<template>
|
||||
<div class="AddBuildingBox">
|
||||
<PageHeader :title="userid ? '编辑问卷' : '添加问卷'"></PageHeader>
|
||||
<div class="AddBuildingBody">
|
||||
<el-form class="formBody" label-position="right" label-width="130px">
|
||||
<el-card>
|
||||
<template #header>
|
||||
<span>基本信息</span>
|
||||
</template>
|
||||
<el-row>
|
||||
<el-col :span="12">
|
||||
<el-form-item label="参与范围" prop="cardName">
|
||||
<el-radio-group v-model="form.scope">
|
||||
<el-radio v-for="item in com_questionnaire_scope" :value="item.value" :label="item.label" :key="item.value"></el-radio>
|
||||
</el-radio-group>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
</el-row>
|
||||
<el-row v-if="form.scope === '1'">
|
||||
<el-col :span="12">
|
||||
<ul class="checkoutSideUsesbox">
|
||||
<li v-for="(item, index) in checkoutUses" :key="index">
|
||||
<div>
|
||||
<span>姓名:</span>
|
||||
<span>{{ item.name }}</span>
|
||||
</div>
|
||||
<el-icon @click="delteUse(item.id)">
|
||||
<Delete></Delete>
|
||||
</el-icon>
|
||||
</li>
|
||||
<Holder returnvalue="*" ref="HolderRef" :isMultiple="true" :userid="checkoutUses" @change="handleSelect">
|
||||
<template #default>
|
||||
<li @click="OpenUseTablesfun" class="add justify-center">
|
||||
<el-icon>
|
||||
<DocumentAdd></DocumentAdd>
|
||||
</el-icon>
|
||||
<span>添加业主</span>
|
||||
</li>
|
||||
</template>
|
||||
</Holder>
|
||||
</ul>
|
||||
</el-col>
|
||||
</el-row>
|
||||
<el-row>
|
||||
<el-col :span="6">
|
||||
<el-form-item label="时间范围" prop="timedata">
|
||||
<el-date-picker
|
||||
v-model="timedata"
|
||||
value-format="YYYY-MM-DD HH:mm:ss"
|
||||
format="YYYY-MM-DD HH:mm:ss"
|
||||
type="datetimerange"
|
||||
range-separator="到"
|
||||
start-placeholder="开始日期时间"
|
||||
end-placeholder="结束日期时间"
|
||||
placeholder="请选择问卷时间范围"
|
||||
/>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
</el-row>
|
||||
<el-row>
|
||||
<el-col :span="12">
|
||||
<el-form-item label="备注" prop="remark">
|
||||
<el-input :rows="5" type="textarea" placeholder="请输入" v-model="form.remark"></el-input>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
</el-row>
|
||||
</el-card>
|
||||
<el-card class="mt-20px">
|
||||
<template #header>
|
||||
<span>问卷题目</span>
|
||||
</template>
|
||||
<QuestionnaireEdit ref="questionnaireEditRef" :initial-data="editData" @cancel="handleCancel" @save="handleSave" @publish="handlePublish" />
|
||||
</el-card>
|
||||
</el-form>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import Holder from '@/components/Holder/index.vue';
|
||||
import QuestionnaireEdit from './components/QuestionnaireEdit.vue';
|
||||
|
||||
import PageHeader from '@/components/Pageheader/index.vue';
|
||||
import { Delete, DocumentAdd } from '@element-plus/icons-vue';
|
||||
import { getQuestionnaire } from '../test/api';
|
||||
import { QuestionnaireForm, QuestionnaireVO } from '@/api/system/Questionnaire/type';
|
||||
import { addQuestionnaire, updateQuestionnaire } from '@/api/system/Questionnaire';
|
||||
|
||||
const { proxy } = getCurrentInstance() as ComponentInternalInstance;
|
||||
const { com_questionnaire_scope } = toRefs<any>(proxy?.useDict('com_questionnaire_scope'));
|
||||
|
||||
const router = useRouter();
|
||||
const route = useRoute();
|
||||
|
||||
import { useHouseStore } from '@/store/modules/house';
|
||||
import { listResident } from '@/api/system/resident';
|
||||
const houseStore = useHouseStore();
|
||||
|
||||
const form = ref({
|
||||
scope: '0',
|
||||
residents: '',
|
||||
remark: ''
|
||||
});
|
||||
const timedata = ref([]);
|
||||
// ! 路由参数 --------------------------------------------------------------------------------
|
||||
// 打开
|
||||
const HolderRef = ref<InstanceType<typeof Holder>>();
|
||||
function OpenUseTablesfun() {
|
||||
HolderRef.value.open();
|
||||
}
|
||||
// 多选
|
||||
const checkoutUses = ref([]);
|
||||
function handleSelect(val) {
|
||||
checkoutUses.value = val;
|
||||
form.value.residents = val.map((item) => item.id).join(',');
|
||||
}
|
||||
// 删除
|
||||
function delteUse(id: string | number) {
|
||||
checkoutUses.value = checkoutUses.value.filter((item) => item.id !== id);
|
||||
}
|
||||
// ! 编辑问卷 ------------------------------------------------------------------------
|
||||
const questionnaireEditRef = ref<InstanceType<typeof QuestionnaireEdit>>();
|
||||
const editData = ref<QuestionnaireVO | null>(null);
|
||||
|
||||
// ! 路由参数 --------------------------------------------------------------------------------
|
||||
const userid = ref(null);
|
||||
|
||||
if (route.query.id) {
|
||||
userid.value = route.query.id;
|
||||
|
||||
handleEdit(userid.value);
|
||||
} else {
|
||||
handleAdd();
|
||||
}
|
||||
|
||||
//
|
||||
const tableData = ref([]);
|
||||
|
||||
// 新增问卷
|
||||
function handleAdd() {
|
||||
editData.value = null;
|
||||
questionnaireEditRef.value?.reset();
|
||||
}
|
||||
// 编辑问卷
|
||||
async function handleEdit(id: string | number) {
|
||||
const res = await listResident();
|
||||
tableData.value = res.rows;
|
||||
// 父组件自己调用接口获取数据
|
||||
getQuestionnaire(id).then((res) => {
|
||||
editData.value = res.data;
|
||||
editData.value.content = JSON.parse(res.data.content);
|
||||
questionnaireEditRef.value?.init(res.data);
|
||||
form.value = {
|
||||
scope: res.data.scope,
|
||||
residents: res.data.residents,
|
||||
remark: res.data.remark
|
||||
};
|
||||
checkoutUses.value = res.data.residents
|
||||
.split(',')
|
||||
.filter((item) => item)
|
||||
.map((item) => {
|
||||
const find = tableData.value.find((useritem) => useritem.id == item);
|
||||
if (find) {
|
||||
return {
|
||||
name: find.name,
|
||||
id: item
|
||||
};
|
||||
}
|
||||
});
|
||||
timedata.value = [res.data.startTime, res.data.endTime];
|
||||
});
|
||||
}
|
||||
|
||||
// 保存草稿
|
||||
async function handleSave(data: QuestionnaireForm) {
|
||||
try {
|
||||
// 父组件自己调用接口提交
|
||||
console.log(data);
|
||||
if (userid.value) {
|
||||
await updateQuestionnaire({
|
||||
...data,
|
||||
content: JSON.stringify(data.content),
|
||||
status: '0', // 草稿状态
|
||||
startTime: timedata.value[0],
|
||||
endTime: timedata.value[1],
|
||||
...form.value
|
||||
});
|
||||
} else {
|
||||
await addQuestionnaire({
|
||||
...data,
|
||||
content: JSON.stringify(data.content),
|
||||
status: '0', // 草稿状态
|
||||
startTime: timedata.value[0],
|
||||
endTime: timedata.value[1],
|
||||
...form.value
|
||||
});
|
||||
}
|
||||
ElMessage.success('保存成功');
|
||||
handleCancel();
|
||||
} catch (e) {
|
||||
// 错误处理
|
||||
console.log(e);
|
||||
}
|
||||
}
|
||||
|
||||
// 发布问卷
|
||||
async function handlePublish(data: QuestionnaireForm) {
|
||||
try {
|
||||
if (userid.value) {
|
||||
await updateQuestionnaire({
|
||||
...data,
|
||||
content: JSON.stringify(data.content),
|
||||
status: '1', // 发布状态
|
||||
startTime: timedata.value[0],
|
||||
villageId: houseStore.currentVilageInfo.villageId,
|
||||
endTime: timedata.value[1]
|
||||
});
|
||||
} else {
|
||||
await addQuestionnaire({
|
||||
...data,
|
||||
content: JSON.stringify(data.content),
|
||||
status: '1', // 发布状态
|
||||
startTime: timedata.value[0],
|
||||
villageId: houseStore.currentVilageInfo.villageId,
|
||||
endTime: timedata.value[1]
|
||||
});
|
||||
}
|
||||
ElMessage.success('发布成功');
|
||||
handleCancel();
|
||||
} catch (e) {
|
||||
// 错误处理
|
||||
}
|
||||
}
|
||||
// 取消
|
||||
function handleCancel() {
|
||||
// 跳转到列表页或关闭弹窗
|
||||
router.push('/repair/Questionnaire');
|
||||
}
|
||||
</script>
|
||||
|
||||
<style scoped lang="scss">
|
||||
.AddBuildingBox {
|
||||
padding: 15px;
|
||||
height: 100%;
|
||||
width: 100%;
|
||||
overflow: hidden;
|
||||
overflow-y: auto;
|
||||
}
|
||||
.AddBuildingBody {
|
||||
margin-top: 20px;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
justify-content: center;
|
||||
|
||||
position: relative;
|
||||
|
||||
.formBody {
|
||||
.checkoutSideUsesbox {
|
||||
margin-left: 130px;
|
||||
display: grid;
|
||||
grid-template-columns: repeat(5, 1fr);
|
||||
gap: 10px;
|
||||
li {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
height: 35px;
|
||||
font-size: 14px;
|
||||
padding: 0 10px;
|
||||
line-height: 35px;
|
||||
margin-bottom: 10px;
|
||||
background-color: #f3f9ff;
|
||||
border: 1px solid #8fc0f1;
|
||||
|
||||
@media (max-width: 2000px) {
|
||||
font-size: 12px;
|
||||
}
|
||||
@media (max-width: 1650px) {
|
||||
font-size: 10px;
|
||||
}
|
||||
@media (max-width: 1650px) {
|
||||
font-size: 8px;
|
||||
}
|
||||
.el-icon {
|
||||
cursor: pointer;
|
||||
&:hover {
|
||||
color: red;
|
||||
}
|
||||
}
|
||||
&.add {
|
||||
cursor: pointer;
|
||||
justify-content: center;
|
||||
color: #409eff;
|
||||
border: 1px dashed #409eff;
|
||||
background-color: transparent;
|
||||
&:hover {
|
||||
background-color: #40a0ff10;
|
||||
}
|
||||
span {
|
||||
margin-left: 10px;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
&:deep(.el-form-item__content, .el-select, .el-input) {
|
||||
width: 350px !important;
|
||||
margin-right: 10px;
|
||||
.el-cascader {
|
||||
width: 100%;
|
||||
}
|
||||
}
|
||||
.el-form-item {
|
||||
margin-bottom: 20px;
|
||||
align-items: center;
|
||||
}
|
||||
.el-button {
|
||||
width: 100px;
|
||||
height: 35px;
|
||||
margin-right: 20px;
|
||||
}
|
||||
}
|
||||
}
|
||||
</style>
|
||||
330
src/views/system/Questionnaire/components/QuestionnaireEdit.vue
Normal file
330
src/views/system/Questionnaire/components/QuestionnaireEdit.vue
Normal file
@@ -0,0 +1,330 @@
|
||||
<template>
|
||||
<div class="edit-container">
|
||||
<el-row :gutter="20">
|
||||
<!-- 左侧:组件库 -->
|
||||
<el-col :span="4">
|
||||
<el-card shadow="hover" class="component-panel sticky-card">
|
||||
<template #header>
|
||||
<div class="card-header">
|
||||
<span>组件库</span>
|
||||
</div>
|
||||
</template>
|
||||
<draggable
|
||||
:list="componentList"
|
||||
:group="{ name: 'components', pull: 'clone', put: false }"
|
||||
:clone="cloneComponent"
|
||||
item-key="type"
|
||||
class="component-list"
|
||||
>
|
||||
<template #item="{ element }">
|
||||
<div class="component-item">
|
||||
<el-icon><component :is="element.icon" /></el-icon>
|
||||
<span>{{ element.label }}</span>
|
||||
</div>
|
||||
</template>
|
||||
</draggable>
|
||||
</el-card>
|
||||
</el-col>
|
||||
|
||||
<!-- 中间:设计画布 -->
|
||||
<el-col :span="12">
|
||||
<el-card shadow="hover" class="canvas-panel">
|
||||
<template #header>
|
||||
<div class="card-header">
|
||||
<span>设计画布</span>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<div class="question-title-area">
|
||||
<el-input v-model="form.title" placeholder="请输入问卷标题" class="title-input" />
|
||||
<el-input v-model="form.description" type="textarea" placeholder="请输入问卷描述(选填)" />
|
||||
</div>
|
||||
|
||||
<draggable v-model="form.content" group="components" item-key="cid" class="question-list" @add="handleAddQuestion">
|
||||
<template #item="{ element, index }">
|
||||
<div class="question-item" :class="{ 'is-active': activeIndex === index }" @click="selectQuestion(index)">
|
||||
<div class="question-handle">
|
||||
<el-icon><Rank /></el-icon>
|
||||
</div>
|
||||
<div class="question-content">
|
||||
<el-tag size="small" type="success" class="question-type-tag">
|
||||
{{ getComponentLabel(element.type) }}
|
||||
</el-tag>
|
||||
<span>Q{{ index + 1 }}. {{ element.title || '未命名题目' }}</span>
|
||||
</div>
|
||||
<div class="question-actions">
|
||||
<el-button link type="danger" :icon="Delete" @click.stop="deleteQuestion(index)"> 删除 </el-button>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
</draggable>
|
||||
<el-empty v-if="form.content.length === 0" description="请从左侧拖拽组件到此处" />
|
||||
</el-card>
|
||||
</el-col>
|
||||
|
||||
<!-- 右侧:属性配置 -->
|
||||
<el-col style="position: sticky; top: 60px" :span="8">
|
||||
<el-card shadow="hover" class="property-panel sticky-card" v-if="activeQuestion">
|
||||
<template #header>
|
||||
<div class="card-header">
|
||||
<span>属性配置</span>
|
||||
</div>
|
||||
</template>
|
||||
<el-form style="position: sticky; top: 60px" label-width="80px">
|
||||
<el-form-item label="题目标题">
|
||||
<el-input v-model="activeQuestion.title" placeholder="请输入题目标题" />
|
||||
</el-form-item>
|
||||
<el-form-item label="是否必填">
|
||||
<el-switch v-model="activeQuestion.required" />
|
||||
</el-form-item>
|
||||
<!-- 单选/多选特有属性 -->
|
||||
<template v-if="activeQuestion.type === 'radio' || activeQuestion.type === 'checkbox'">
|
||||
<el-divider content-position="left">选项设置</el-divider>
|
||||
<div v-for="(opt, idx) in activeQuestion.options" :key="idx" class="option-item">
|
||||
<el-input v-model="opt.label" placeholder="选项内容" style="width: 200px; margin-right: 10px; margin-bottom: 10px" />
|
||||
<el-button link type="danger" :icon="Delete" @click="activeQuestion.options.splice(idx, 1)"> 删除 </el-button>
|
||||
</div>
|
||||
<el-button type="primary" @click="activeQuestion.options.push({ label: '新选项' })"> 添加选项 </el-button>
|
||||
</template>
|
||||
</el-form>
|
||||
</el-card>
|
||||
<el-empty v-else description="请点击选中一道题目" />
|
||||
</el-col>
|
||||
</el-row>
|
||||
|
||||
<!-- 底部操作栏 -->
|
||||
<div class="footer-actions">
|
||||
<el-button @click="handleCancel">取消</el-button>
|
||||
<el-button type="primary" @click="handleSave">保存草稿</el-button>
|
||||
<el-button type="success" @click="handlePublish">保存并发布</el-button>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts" name="QuestionnaireEdit">
|
||||
import draggable from 'vuedraggable';
|
||||
import { Plus, Delete, Rank, Tickets, Document, Edit } from '@element-plus/icons-vue';
|
||||
import { ComponentItem, QuestionComponentItem, QuestionComponentnaireForm } from '@/api/system/Questionnaire/type';
|
||||
import { ElMessage } from 'element-plus'; // 👈 补充引入
|
||||
// ==================== Props & Emit ====================
|
||||
const props = defineProps<{
|
||||
/** 初始问卷数据(编辑时传入) */
|
||||
initialData?: Partial<QuestionComponentnaireForm>;
|
||||
}>();
|
||||
|
||||
const emit = defineEmits<{
|
||||
/** 取消编辑 */
|
||||
cancel: [];
|
||||
/** 保存草稿 */
|
||||
save: [data: QuestionComponentnaireForm];
|
||||
/** 发布问卷 */
|
||||
publish: [data: QuestionComponentnaireForm];
|
||||
}>();
|
||||
import { markRaw } from 'vue'; // 👈 引入 markRaw
|
||||
// ==================== 响应式数据 ====================
|
||||
const componentList = ref<ComponentItem[]>([
|
||||
{ type: 'radio', label: '单选题', icon: markRaw(Tickets) },
|
||||
{ type: 'checkbox', label: '多选题', icon: markRaw(Tickets) },
|
||||
{ type: 'input', label: '填空题', icon: markRaw(Edit) },
|
||||
{ type: 'textarea', label: '多行文本', icon: markRaw(Document) }
|
||||
]);
|
||||
|
||||
const form = ref<QuestionComponentnaireForm>({
|
||||
id: null,
|
||||
title: '',
|
||||
description: '',
|
||||
content: []
|
||||
});
|
||||
|
||||
const activeIndex = ref<number>(-1);
|
||||
|
||||
// ==================== 计算属性 ====================
|
||||
const activeQuestion = computed<QuestionComponentItem | null>(() => {
|
||||
if (activeIndex.value === -1) return null;
|
||||
return form.value.content[activeIndex.value];
|
||||
});
|
||||
|
||||
// ==================== 辅助方法 ====================
|
||||
function getComponentLabel(type: string): string {
|
||||
const item = componentList.value.find((c) => c.type === type);
|
||||
return item ? item.label : '';
|
||||
}
|
||||
|
||||
// 克隆组件(用于从左侧拖入中间)
|
||||
function cloneComponent(component: ComponentItem): QuestionComponentItem {
|
||||
return {
|
||||
cid: Date.now(), // 生成唯一ID
|
||||
type: component.type,
|
||||
title: 'ces',
|
||||
required: true,
|
||||
options: component.type === 'radio' || component.type === 'checkbox' ? [{ label: '选项1' }, { label: '选项2' }] : []
|
||||
};
|
||||
}
|
||||
|
||||
// 选中题目
|
||||
function selectQuestion(index: number): void {
|
||||
activeIndex.value = index;
|
||||
}
|
||||
|
||||
// 添加题目后的处理
|
||||
function handleAddQuestion(evt: any): void {
|
||||
// 自动选中新添加的题目
|
||||
activeIndex.value = evt.newIndex;
|
||||
}
|
||||
|
||||
// 删除题目
|
||||
function deleteQuestion(index: number): void {
|
||||
form.value.content.splice(index, 1);
|
||||
if (activeIndex.value === index) {
|
||||
activeIndex.value = -1;
|
||||
} else if (activeIndex.value > index) {
|
||||
activeIndex.value--;
|
||||
}
|
||||
}
|
||||
|
||||
// ==================== 业务方法 ====================
|
||||
/** 表单验证 */
|
||||
function validateForm(): boolean {
|
||||
if (!form.value.title.trim()) {
|
||||
ElMessage.error('请输入问卷标题');
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/** 取消 */
|
||||
function handleCancel(): void {
|
||||
emit('cancel');
|
||||
}
|
||||
|
||||
/** 保存草稿 */
|
||||
function handleSave(): void {
|
||||
console.log(form.value, !validateForm());
|
||||
if (!validateForm()) return;
|
||||
emit('save', { ...form.value });
|
||||
}
|
||||
|
||||
/** 发布问卷 */
|
||||
function handlePublish(): void {
|
||||
if (!validateForm()) return;
|
||||
emit('publish', { ...form.value });
|
||||
}
|
||||
|
||||
/** 初始化数据(编辑时调用) */
|
||||
function init(data: Partial<QuestionComponentnaireForm>): void {
|
||||
form.value = {
|
||||
id: null,
|
||||
title: '',
|
||||
description: '',
|
||||
content: [],
|
||||
...data
|
||||
};
|
||||
|
||||
// 处理content字符串转对象(如果是从数据库取的)
|
||||
if (typeof form.value.content === 'string') {
|
||||
try {
|
||||
form.value.content = JSON.parse(form.value.content);
|
||||
} catch (e) {
|
||||
form.value.content = [];
|
||||
}
|
||||
}
|
||||
|
||||
activeIndex.value = -1;
|
||||
}
|
||||
|
||||
/** 重置表单 */
|
||||
function reset(): void {
|
||||
form.value = {
|
||||
id: null,
|
||||
title: '',
|
||||
description: '',
|
||||
content: []
|
||||
};
|
||||
activeIndex.value = -1;
|
||||
}
|
||||
|
||||
// ==================== 生命周期 ====================
|
||||
onMounted(() => {
|
||||
// 如果传入了初始数据,自动初始化
|
||||
if (props.initialData) {
|
||||
init(props.initialData);
|
||||
}
|
||||
});
|
||||
|
||||
// ==================== 暴露方法 ====================
|
||||
defineExpose({ init, reset });
|
||||
</script>
|
||||
|
||||
<style scoped lang="scss">
|
||||
.edit-container {
|
||||
position: relative;
|
||||
|
||||
.component-list {
|
||||
.component-item {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
padding: 10px;
|
||||
margin-bottom: 10px;
|
||||
background: #f4f4f5;
|
||||
border-radius: 4px;
|
||||
cursor: move;
|
||||
.el-icon {
|
||||
margin-right: 8px;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.question-title-area {
|
||||
margin-bottom: 20px;
|
||||
padding: 10px;
|
||||
border: 1px dashed #dcdfe6;
|
||||
.title-input {
|
||||
font-size: 18px;
|
||||
font-weight: bold;
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
}
|
||||
|
||||
.question-list {
|
||||
min-height: 200px;
|
||||
.question-item {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
padding: 12px;
|
||||
margin-bottom: 10px;
|
||||
border: 1px solid #ebeef5;
|
||||
background: #fff;
|
||||
border-radius: 4px;
|
||||
&:hover {
|
||||
border-color: #409eff;
|
||||
}
|
||||
&.is-active {
|
||||
border-color: #409eff;
|
||||
background: #ecf5ff;
|
||||
}
|
||||
|
||||
.question-handle {
|
||||
cursor: move;
|
||||
padding: 0 10px;
|
||||
color: #909399;
|
||||
}
|
||||
.question-content {
|
||||
flex: 1;
|
||||
.question-type-tag {
|
||||
margin-right: 8px;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
.canvas-panel {
|
||||
}
|
||||
.footer-actions {
|
||||
width: 100%;
|
||||
background: #fff;
|
||||
padding: 10px 20px;
|
||||
margin-top: 60px;
|
||||
text-align: right;
|
||||
border-top: 1px solid #dcdfe6;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
251
src/views/system/Questionnaire/index.vue
Normal file
251
src/views/system/Questionnaire/index.vue
Normal file
@@ -0,0 +1,251 @@
|
||||
<template>
|
||||
<div class="p-2">
|
||||
<transition :enter-active-class="proxy?.animate.searchAnimate.enter" :leave-active-class="proxy?.animate.searchAnimate.leave">
|
||||
<div v-show="showSearch" class="mb-[10px]">
|
||||
<el-card shadow="hover">
|
||||
<el-form ref="queryFormRef" :model="queryParams" :inline="true">
|
||||
<el-form-item label="问卷标题" prop="title">
|
||||
<el-input v-model="queryParams.title" placeholder="请输入问卷标题" clearable @keyup.enter="handleQuery" />
|
||||
</el-form-item>
|
||||
<!-- <el-form-item label="参与范围" prop="scope">
|
||||
<el-input v-model="queryParams.scope" placeholder="请输入参与范围 0全体业主 1部分业主" clearable @keyup.enter="handleQuery" />
|
||||
</el-form-item> -->
|
||||
<el-form-item>
|
||||
<el-button type="primary" icon="Search" @click="handleQuery">搜索</el-button>
|
||||
<el-button icon="Refresh" @click="resetQuery">重置</el-button>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
</el-card>
|
||||
</div>
|
||||
</transition>
|
||||
|
||||
<el-card shadow="never">
|
||||
<template #header>
|
||||
<el-row :gutter="10" class="mb8">
|
||||
<el-col :span="1.5">
|
||||
<el-button type="primary" plain icon="Plus" @click="handleAdd" v-hasPermi="['questionnaire:questionnaire:add']">新增</el-button>
|
||||
</el-col>
|
||||
<el-col :span="1.5">
|
||||
<el-button type="success" plain icon="Edit" :disabled="single" @click="handleUpdate()" v-hasPermi="['questionnaire:questionnaire:edit']"
|
||||
>修改</el-button
|
||||
>
|
||||
</el-col>
|
||||
<el-col :span="1.5">
|
||||
<el-button
|
||||
type="danger"
|
||||
plain
|
||||
icon="Delete"
|
||||
:disabled="multiple"
|
||||
@click="handleDelete()"
|
||||
v-hasPermi="['questionnaire:questionnaire:remove']"
|
||||
>删除</el-button
|
||||
>
|
||||
</el-col>
|
||||
<right-toolbar v-model:showSearch="showSearch" @queryTable="getList"></right-toolbar>
|
||||
</el-row>
|
||||
</template>
|
||||
|
||||
<el-table v-loading="loading" border :data="questionnaireList" @selection-change="handleSelectionChange">
|
||||
<el-table-column type="selection" width="55" align="center" />
|
||||
<el-table-column label="问卷标题" align="center" prop="title" />
|
||||
<el-table-column label="问卷描述" align="center" prop="description" />
|
||||
<el-table-column label="状态" align="center" prop="status">
|
||||
<template #default="scope">
|
||||
<dict-tag :options="com_questionnaire_status" :value="scope.row.status"></dict-tag>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="参与范围" align="center" prop="scope">
|
||||
<template #default="scope">
|
||||
<dict-tag :options="com_questionnaire_scope" :value="scope.row.scope"></dict-tag>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="备注" align="center" prop="remark" />
|
||||
<el-table-column label="操作" align="center" fixed="right" width="200">
|
||||
<template #default="scope">
|
||||
<el-tooltip content="修改" placement="top">
|
||||
<el-button
|
||||
link
|
||||
type="primary"
|
||||
icon="Edit"
|
||||
@click="handleUpdate(scope.row)"
|
||||
v-hasPermi="['questionnaire:questionnaire:edit']"
|
||||
></el-button>
|
||||
</el-tooltip>
|
||||
<el-tooltip content="删除" placement="top">
|
||||
<el-button
|
||||
link
|
||||
type="primary"
|
||||
icon="Delete"
|
||||
@click="handleDelete(scope.row)"
|
||||
v-hasPermi="['questionnaire:questionnaire:remove']"
|
||||
></el-button>
|
||||
</el-tooltip>
|
||||
</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
|
||||
<pagination v-show="total > 0" :total="total" v-model:page="queryParams.pageNum" v-model:limit="queryParams.pageSize" @pagination="getList" />
|
||||
</el-card>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup name="Questionnaire" lang="ts">
|
||||
import { listQuestionnaire, getQuestionnaire, delQuestionnaire, addQuestionnaire, updateQuestionnaire } from '@/api/system/Questionnaire/index';
|
||||
import { QuestionnaireVO, QuestionnaireQuery, QuestionnaireForm } from '@/api/system/Questionnaire/type';
|
||||
|
||||
const { proxy } = getCurrentInstance() as ComponentInternalInstance;
|
||||
|
||||
const { com_questionnaire_scope } = toRefs<any>(proxy?.useDict('com_questionnaire_scope'));
|
||||
const { com_questionnaire_status } = toRefs<any>(proxy?.useDict('com_questionnaire_status'));
|
||||
console.log(com_questionnaire_scope);
|
||||
|
||||
const questionnaireList = ref<QuestionnaireVO[]>([]);
|
||||
const buttonLoading = ref(false);
|
||||
const loading = ref(true);
|
||||
const showSearch = ref(true);
|
||||
const ids = ref<Array<string | number>>([]);
|
||||
const single = ref(true);
|
||||
const multiple = ref(true);
|
||||
const total = ref(0);
|
||||
|
||||
const queryFormRef = ref<ElFormInstance>();
|
||||
const questionnaireFormRef = ref<ElFormInstance>();
|
||||
|
||||
const dialog = reactive<DialogOption>({
|
||||
visible: false,
|
||||
title: ''
|
||||
});
|
||||
|
||||
const initFormData: QuestionnaireForm = {
|
||||
id: undefined,
|
||||
villageId: undefined,
|
||||
title: undefined,
|
||||
description: undefined,
|
||||
content: undefined,
|
||||
status: undefined,
|
||||
scope: undefined,
|
||||
residents: undefined,
|
||||
remark: undefined
|
||||
};
|
||||
const data = reactive<PageData<QuestionnaireForm, QuestionnaireQuery>>({
|
||||
form: { ...initFormData },
|
||||
queryParams: {
|
||||
pageNum: 1,
|
||||
pageSize: 10,
|
||||
villageId: undefined,
|
||||
title: undefined,
|
||||
description: undefined,
|
||||
content: undefined,
|
||||
status: undefined,
|
||||
scope: undefined,
|
||||
residents: undefined,
|
||||
params: {}
|
||||
},
|
||||
rules: {
|
||||
id: [{ required: true, message: '问卷ID不能为空', trigger: 'blur' }],
|
||||
title: [{ required: true, message: '问卷标题不能为空', trigger: 'blur' }],
|
||||
content: [{ required: true, message: '问卷题目结构不能为空', trigger: 'blur' }]
|
||||
}
|
||||
});
|
||||
|
||||
const { queryParams, form, rules } = toRefs(data);
|
||||
|
||||
/** 查询问卷调查列表 */
|
||||
const getList = async () => {
|
||||
loading.value = true;
|
||||
const res = await listQuestionnaire(queryParams.value);
|
||||
questionnaireList.value = res.rows;
|
||||
total.value = res.total;
|
||||
loading.value = false;
|
||||
};
|
||||
|
||||
/** 取消按钮 */
|
||||
const cancel = () => {
|
||||
reset();
|
||||
dialog.visible = false;
|
||||
};
|
||||
|
||||
/** 表单重置 */
|
||||
const reset = () => {
|
||||
form.value = { ...initFormData };
|
||||
questionnaireFormRef.value?.resetFields();
|
||||
};
|
||||
|
||||
/** 搜索按钮操作 */
|
||||
const handleQuery = () => {
|
||||
queryParams.value.pageNum = 1;
|
||||
getList();
|
||||
};
|
||||
|
||||
/** 重置按钮操作 */
|
||||
const resetQuery = () => {
|
||||
queryFormRef.value?.resetFields();
|
||||
handleQuery();
|
||||
};
|
||||
|
||||
/** 多选框选中数据 */
|
||||
const handleSelectionChange = (selection: QuestionnaireVO[]) => {
|
||||
ids.value = selection.map((item) => item.id);
|
||||
single.value = selection.length != 1;
|
||||
multiple.value = !selection.length;
|
||||
};
|
||||
|
||||
const router = useRouter();
|
||||
/** 新增按钮操作 */
|
||||
const handleAdd = () => {
|
||||
router.push({
|
||||
path: '/repair/addQuestionnaire'
|
||||
});
|
||||
};
|
||||
|
||||
/** 修改按钮操作 */
|
||||
const handleUpdate = async (row?: QuestionnaireVO) => {
|
||||
router.push({
|
||||
path: '/repair/addQuestionnaire',
|
||||
query: {
|
||||
id: row.id
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
/** 提交按钮 */
|
||||
const submitForm = () => {
|
||||
questionnaireFormRef.value?.validate(async (valid: boolean) => {
|
||||
if (valid) {
|
||||
buttonLoading.value = true;
|
||||
if (form.value.id) {
|
||||
await updateQuestionnaire(form.value).finally(() => (buttonLoading.value = false));
|
||||
} else {
|
||||
await addQuestionnaire(form.value).finally(() => (buttonLoading.value = false));
|
||||
}
|
||||
proxy?.$modal.msgSuccess('操作成功');
|
||||
dialog.visible = false;
|
||||
await getList();
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
/** 删除按钮操作 */
|
||||
const handleDelete = async (row?: QuestionnaireVO) => {
|
||||
const _ids = row?.id || ids.value;
|
||||
await proxy?.$modal.confirm('是否确认删除问卷调查编号为"' + _ids + '"的数据项?').finally(() => (loading.value = false));
|
||||
await delQuestionnaire(_ids);
|
||||
proxy?.$modal.msgSuccess('删除成功');
|
||||
await getList();
|
||||
};
|
||||
|
||||
/** 导出按钮操作 */
|
||||
const handleExport = () => {
|
||||
proxy?.download(
|
||||
'questionnaire/questionnaire/export',
|
||||
{
|
||||
...queryParams.value
|
||||
},
|
||||
`questionnaire_${new Date().getTime()}.xlsx`
|
||||
);
|
||||
};
|
||||
|
||||
onMounted(() => {
|
||||
getList();
|
||||
});
|
||||
</script>
|
||||
Reference in New Issue
Block a user