<template> <div class="publicContainer"> <!-- 搜索区域 --> <el-form :model="queryParams" ref="queryRef" :inline="true" v-show="showSearch"> <el-form-item label="被通知人" prop="title"> <el-select v-model="queryParams.selectPoprle" multiple clearable placeholder="请选择被通知人"> <el-option v-for="item in selectPoprleList" :key="item.id" :label="item.peopleLabel" :value="item.id" /> </el-select> </el-form-item> <el-form-item label="通知状态" prop="msgState"> <el-select v-model="queryParams.msgState" placeholder="请选择通知状态"> <el-option v-for="item in infoStaticList" :key="item.id" :label="item.staticLabel" :value="item.id" /> </el-select> </el-form-item> <el-form-item label="消息状态" prop="readStatus"> <el-select v-model="queryParams.readStatus" placeholder="请选择消息状态"> <el-option v-for="item in messageStaticList" :key="item.id" :label="item.messageLabel" :value="item.id" /> </el-select> </el-form-item> <el-form-item label="日期" prop="createTime"> <el-date-picker type="daterange" v-model="queryParams.createTime" value-format="YYYY" placeholder="请选择日期" start-placeholder="计划开始日期" · end-placeholder="计划结束日期" ></el-date-picker> </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-row :gutter="10" class="mb8"> <el-col :span="1.5"> <el-button type="primary" plain icon="Plus" @click="handleAdd">新增</el-button> </el-col> <right-toolbar v-model:showSearch="showSearch" @queryTable="getDataList"></right-toolbar> </el-row> <!-- 表格 --> <el-table v-loading="tableLoading" :data="tableData" max-height="650"> <el-table-column label="序号" type="index" width="55" /> <el-table-column label="通知消息" prop="noticeMsg" width="500" /> <el-table-column label="通知状态" prop="msgState"> <template #default="scope"> <span> {{ scope.row.msgState == '0' ? '草稿待发布' : scope.row.msgState == '1' ? '发布' : '' }} </span> </template> </el-table-column> <el-table-column label="消息状态" prop="readStatus" width="300"> <template #default="scope"> <span v-if="scope.row.readStatus == '0'"> {{ '未读' + ':' }} <span v-for="(itme, index) in scope.row.unReadUsers" :key="index"> {{ itme.noticeUserName + ',' }}</span> </span> <span v-if="scope.row.readStatus == '1'"> {{ '全部已读' }} </span> </template> </el-table-column> <el-table-column label="更新日期" prop="createTime" /> <el-table-column label="被通知人" prop="nickName" /> <el-table-column label="通知人电话" prop="phone" /> <el-table-column label="发布人" prop="createBy" /> <el-table-column label="操作" width="160" class-name="small-padding fixed-width"> <template #default="scope"> <el-button link type="warning" icon="Edit" @click="handleUpdate(scope.row)">修改</el-button> <el-button link type="danger" icon="Delete" @click="handleDelete(scope.row)"> 删除 </el-button> </template> </el-table-column> </el-table> <!-- 分页 --> <pagination v-show="total > 0" :total="total" v-model:page="queryParams.pageNum" v-model:limit="queryParams.pageSize" @pagination="getDataList" /> <!-- 新增或修改弹窗 --> <el-dialog :title="dialogTitle" v-model="dialogShow" width="700px" append-to-body> <el-form ref="formRef" :model="formData" :rules="rulesForm" label-width="160px" class="publicForm"> <el-form-item label="被通知人" prop="userIdArray"> <el-select v-model="formData.userIdArray" multiple clearable placeholder="请选择被通知人"> <el-option v-for="item in userList" :key="item.userId" :label="item.nickName" :value="item.userId" /> </el-select> </el-form-item> <el-form-item label="通知人电话:" prop="phone"> <el-input type="text" v-model="formData.phone" placeholder="请输入通知人电话" clearable maxlength="11" /> </el-form-item> <el-form-item label="通知状态" prop="msgState"> <el-select v-model="formData.msgState" placeholder="请选择通知状态"> <el-option v-for="item in infoStaticList" :key="item.id" :label="item.staticLabel" :value="item.id" /> </el-select> </el-form-item> <el-form-item label="通知消息" prop="noticeMsg"> <el-input type="textarea" v-model="formData.noticeMsg" placeholder="请输入通知消息" /> </el-form-item> </el-form> <template #footer> <div class="dialog-footer"> <el-button type="info" @click="cancelForm">取 消</el-button> <!-- <el-button type="primary" @click="saveInfo">存草稿</el-button> --> <el-button type="primary" @click="submitForm">确 定</el-button> </div> </template> </el-dialog> </div> </template> <script setup name="项目通知填报"> import { projectNoticePage, projectNoticeAdd, projectNoticeDel, projectNoticeEdit } from '@/api/publicService/index'; import { listUser } from '@/api/system/user'; import { ref } from 'vue'; import bus from '@/utils/mitt'; const { proxy } = getCurrentInstance(); const tableData = ref([]); const tableLoading = ref(true); const total = ref(0); const dialogShow = ref(false); const dialogTitle = ref(''); const showSearch = ref(true); const allData = reactive({ formData: {}, queryParams: { pageNum: 1, pageSize: 10, noticeState: null, //通知状态 readStatus: null, //消息状态 title: undefined, typeId: undefined, }, rulesForm: { userIdArray: [{ required: true, message: '请选择被通知人', trigger: 'blur' }], msgState: [{ required: true, message: '请选择通知状态', trigger: 'blur' }], noticeMsg: [{ required: true, message: '请输入通知消息', trigger: 'blur' }], phone: [ { pattern: /^1[3|4|5|6|7|8|9][0-9]\d{8}$/, message: '请输入正确的手机号码', trigger: 'blur', required: true, }, ], }, }); const { queryParams, formData, rulesForm } = toRefs(allData); const infoStaticList = ref([ { id: 0, staticLabel: '草稿待发布', }, { id: 1, staticLabel: '发布', }, ]); const messageStaticList = ref([ { id: 0, messageLabel: '未读', }, { id: 1, messageLabel: '全部已读', }, ]); const userList = ref([]); //搜索人员列表 function getUserList() { listUser().then(res => { userList.value = res.data; // userList.value.map(item => { // item.userId = String(item.userId); // }); }); } /** 获取搜索数据列表 */ function getDataList() { tableLoading.value = true; projectNoticePage(queryParams.value).then(response => { tableData.value = response.data; total.value = response.total; tableLoading.value = false; }); } /** 取消按钮 */ function cancelForm() { dialogShow.value = false; } /** 搜索按钮操作 */ function handleQuery() { queryParams.value.pageNum = 1; getDataList(); } /** 重置按钮操作 */ function resetQuery() { proxy.resetForm('queryRef'); handleQuery(); } /** 新增按钮操作 */ function handleAdd() { proxy.resetForm('formRef'); //清空表单 formData.value.content = ' '; dialogShow.value = true; formData.value.msgState = infoStaticList.value[1].id; dialogTitle.value = '新增项目通知'; } /** 修改按钮操作 */ function handleUpdate(row) { dialogShow.value = true; // const postId = row.id; // knowledgeDetail(postId).then(response => { // dialogShow.value = true; dialogTitle.value = '修改项目通知'; formData.value = { ...row }; // nextTick(() => { // formData.value = response.data; // }); // }); } /** 提交按钮 */ function submitForm() { proxy.$refs['formRef'].validate(valid => { if (valid) { if (dialogTitle.value == '修改项目通知') { projectNoticeEdit(formData.value).then(response => { proxy.$modal.msgSuccess('修改成功'); dialogShow.value = false; getDataList(); bus.emit('Refresh'); }); } else { if (formData.value.id) delete formData.value.id; projectNoticeAdd(formData.value).then(response => { proxy.$modal.msgSuccess('新增成功'); dialogShow.value = false; getDataList(); bus.emit('Refresh'); }); } } }); } /** 删除按钮操作 */ function handleDelete(row) { const postIds = row.id; proxy.$modal .confirm('是否确认删除该数据项?') .then(function () { return projectNoticeDel(postIds); }) .then(() => { getDataList(); proxy.$modal.msgSuccess('删除成功'); bus.emit('Refresh'); }) .catch(() => {}); } onMounted(() => { getDataList(); getUserList(); }); </script>