210 lines
8.4 KiB
Vue
210 lines
8.4 KiB
Vue
<template>
|
|
<div class="divBox">
|
|
<el-card class="box-card">
|
|
<div class="clearfix" slot="header">
|
|
<el-form :inline="true" :model="queryParams" size="small">
|
|
<el-form-item label="许愿树">
|
|
<el-select v-model="queryParams.tree_id" placeholder="请选择许愿树" clearable>
|
|
<el-option v-for="item in treeList" :key="item.id" :label="item.name" :value="item.id" />
|
|
</el-select>
|
|
</el-form-item>
|
|
<el-form-item label="节点标题">
|
|
<el-input v-model="queryParams.title" placeholder="请输入标题" clearable />
|
|
</el-form-item>
|
|
<el-form-item label="状态">
|
|
<el-select v-model="queryParams.status" placeholder="请选择" clearable>
|
|
<el-option label="启用" :value="1" />
|
|
<el-option label="禁用" :value="0" />
|
|
</el-select>
|
|
</el-form-item>
|
|
<el-form-item>
|
|
<el-button type="primary" @click="handleSearch">搜索</el-button>
|
|
<el-button @click="handleReset">重置</el-button>
|
|
<el-button type="success" @click="handleAdd">新增节点</el-button>
|
|
</el-form-item>
|
|
</el-form>
|
|
</div>
|
|
|
|
<el-table v-loading="loading" :data="tableData" border style="width: 100%">
|
|
<el-table-column prop="id" label="ID" width="80" align="center" />
|
|
<el-table-column prop="tree_name" label="所属许愿树" width="150" />
|
|
<el-table-column prop="title" label="节点标题" min-width="150" />
|
|
<el-table-column prop="description" label="描述" min-width="200" show-overflow-tooltip />
|
|
<el-table-column label="开启时间" width="180" align="center">
|
|
<template slot-scope="scope">
|
|
<span v-if="scope.row.open_time">{{ scope.row.open_time }}</span>
|
|
<el-tag v-else type="success" size="small">立即开启</el-tag>
|
|
</template>
|
|
</el-table-column>
|
|
<el-table-column prop="message_count" label="留言数" width="80" align="center" />
|
|
<el-table-column label="状态" width="100" align="center">
|
|
<template slot-scope="scope">
|
|
<el-switch v-model="scope.row.status" :active-value="1" :inactive-value="0" @change="handleStatusChange(scope.row)" />
|
|
</template>
|
|
</el-table-column>
|
|
<el-table-column prop="create_time" label="创建时间" width="160" align="center" />
|
|
<el-table-column label="操作" width="150" align="center" fixed="right">
|
|
<template slot-scope="scope">
|
|
<el-button type="text" size="small" @click="handleEdit(scope.row)">编辑</el-button>
|
|
<el-button type="text" size="small" style="color: #f56c6c" @click="handleDelete(scope.row)">删除</el-button>
|
|
</template>
|
|
</el-table-column>
|
|
</el-table>
|
|
|
|
<el-pagination style="margin-top: 20px; text-align: right" @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page="queryParams.page" :page-sizes="[10, 20, 50, 100]" :page-size="queryParams.limit" layout="total, sizes, prev, pager, next, jumper" :total="total" />
|
|
</el-card>
|
|
|
|
<el-dialog :title="dialogTitle" :visible.sync="dialogVisible" width="600px" @close="handleDialogClose">
|
|
<el-form ref="formRef" :model="formData" :rules="formRules" label-width="100px">
|
|
<el-form-item label="许愿树" prop="tree_id">
|
|
<el-select v-model="formData.tree_id" placeholder="请选择许愿树" style="width: 100%">
|
|
<el-option v-for="item in treeList" :key="item.id" :label="item.name" :value="item.id" />
|
|
</el-select>
|
|
</el-form-item>
|
|
<el-form-item label="节点标题" prop="title">
|
|
<el-input v-model="formData.title" placeholder="请输入节点标题" maxlength="100" show-word-limit />
|
|
</el-form-item>
|
|
<el-form-item label="描述" prop="description">
|
|
<el-input v-model="formData.description" type="textarea" :rows="3" placeholder="请输入描述" maxlength="500" show-word-limit />
|
|
</el-form-item>
|
|
<el-form-item label="图标URL" prop="icon">
|
|
<el-input v-model="formData.icon" placeholder="请输入图标URL" />
|
|
</el-form-item>
|
|
<el-form-item label="开启时间" prop="open_time">
|
|
<el-date-picker v-model="formData.open_time" type="datetime" placeholder="不设置则立即开启" value-format="yyyy-MM-dd HH:mm:ss" style="width: 100%" />
|
|
</el-form-item>
|
|
<el-form-item label="排序" prop="sort">
|
|
<el-input-number v-model="formData.sort" :min="0" :max="9999" />
|
|
</el-form-item>
|
|
<el-form-item label="状态" prop="status">
|
|
<el-switch v-model="formData.status" :active-value="1" :inactive-value="0" />
|
|
</el-form-item>
|
|
</el-form>
|
|
<span slot="footer">
|
|
<el-button @click="dialogVisible = false">取消</el-button>
|
|
<el-button type="primary" @click="handleSubmit">确定</el-button>
|
|
</span>
|
|
</el-dialog>
|
|
</div>
|
|
</template>
|
|
|
|
<script>
|
|
import { wishTreeListApi, wishTreeNodeListApi, wishTreeNodeSaveApi, wishTreeNodeUpdateApi, wishTreeNodeDeleteApi, wishTreeNodeStatusApi } from '@/api/wishTree';
|
|
|
|
export default {
|
|
name: 'WishTreeNode',
|
|
data() {
|
|
return {
|
|
loading: false,
|
|
treeList: [],
|
|
tableData: [],
|
|
total: 0,
|
|
queryParams: { page: 1, limit: 10, tree_id: '', title: '', status: '' },
|
|
dialogVisible: false,
|
|
dialogTitle: '新增节点',
|
|
formData: { id: null, tree_id: '', title: '', description: '', icon: '', open_time: null, sort: 0, status: 1 },
|
|
formRules: {
|
|
tree_id: [{ required: true, message: '请选择许愿树', trigger: 'change' }],
|
|
title: [{ required: true, message: '请输入节点标题', trigger: 'blur' }],
|
|
},
|
|
};
|
|
},
|
|
created() {
|
|
this.getTreeList();
|
|
this.getList();
|
|
},
|
|
methods: {
|
|
async getTreeList() {
|
|
try {
|
|
const res = await wishTreeListApi({ page: 1, limit: 1000 });
|
|
this.treeList = res.list || [];
|
|
} catch (error) {
|
|
console.error(error);
|
|
}
|
|
},
|
|
async getList() {
|
|
this.loading = true;
|
|
try {
|
|
const res = await wishTreeNodeListApi(this.queryParams);
|
|
this.tableData = res.list || [];
|
|
this.total = res.total || 0;
|
|
} catch (error) {
|
|
console.error(error);
|
|
}
|
|
this.loading = false;
|
|
},
|
|
handleSearch() {
|
|
this.queryParams.page = 1;
|
|
this.getList();
|
|
},
|
|
handleReset() {
|
|
this.queryParams = { page: 1, limit: 10, tree_id: '', title: '', status: '' };
|
|
this.getList();
|
|
},
|
|
handleAdd() {
|
|
this.dialogTitle = '新增节点';
|
|
this.formData = { id: null, tree_id: '', title: '', description: '', icon: '', open_time: null, sort: 0, status: 1 };
|
|
this.dialogVisible = true;
|
|
},
|
|
handleEdit(row) {
|
|
this.dialogTitle = '编辑节点';
|
|
this.formData = { ...row };
|
|
this.dialogVisible = true;
|
|
},
|
|
handleDelete(row) {
|
|
this.$confirm('确定要删除该节点吗?删除后该节点下的所有留言也会被删除。', '提示', {
|
|
confirmButtonText: '确定',
|
|
cancelButtonText: '取消',
|
|
type: 'warning',
|
|
}).then(async () => {
|
|
try {
|
|
await wishTreeNodeDeleteApi(row.id);
|
|
this.$message.success('删除成功');
|
|
this.getList();
|
|
} catch (error) {
|
|
console.error(error);
|
|
}
|
|
});
|
|
},
|
|
async handleStatusChange(row) {
|
|
try {
|
|
await wishTreeNodeStatusApi(row.id);
|
|
this.$message.success('状态修改成功');
|
|
} catch (error) {
|
|
row.status = row.status === 1 ? 0 : 1;
|
|
console.error(error);
|
|
}
|
|
},
|
|
handleSubmit() {
|
|
this.$refs.formRef.validate(async (valid) => {
|
|
if (!valid) return;
|
|
try {
|
|
const api = this.formData.id ? wishTreeNodeUpdateApi : wishTreeNodeSaveApi;
|
|
await api(this.formData);
|
|
this.$message.success(this.formData.id ? '编辑成功' : '新增成功');
|
|
this.dialogVisible = false;
|
|
this.getList();
|
|
} catch (error) {
|
|
console.error(error);
|
|
}
|
|
});
|
|
},
|
|
handleDialogClose() {
|
|
this.$refs.formRef && this.$refs.formRef.resetFields();
|
|
},
|
|
handleSizeChange(val) {
|
|
this.queryParams.limit = val;
|
|
this.getList();
|
|
},
|
|
handleCurrentChange(val) {
|
|
this.queryParams.page = val;
|
|
this.getList();
|
|
},
|
|
},
|
|
};
|
|
</script>
|
|
|
|
<style scoped>
|
|
.divBox { padding: 20px; }
|
|
</style>
|