<template>
|
<div class="app-container">
|
<div style="margin-bottom: 10px">
|
<el-form style="display: flex;flex-wrap: wrap;">
|
<el-form-item>
|
<el-button
|
type="primary"
|
plain
|
icon="Plus"
|
@click="openDialog('add',{})"
|
v-hasPermi="['needIdentify:list:add']"
|
>新增</el-button>
|
</el-form-item>
|
<el-form-item label="单位名称:" v-if="data.isAdmin" style="margin-left: 20px">
|
<el-select v-model="data.queryParams.companyId" placeholder="请选择" filterable clearable>
|
<el-option
|
v-for="item in data.companyList"
|
:key="item.id"
|
:label="item.name"
|
:value="item.id">
|
</el-option>
|
</el-select>
|
</el-form-item>
|
<el-form-item label="年份:" style="margin-left: 20px">
|
<el-date-picker
|
v-model="data.queryParams.year"
|
type="year"
|
value-format="YYYY"
|
placeholder="请选择年份"
|
style="width: 240px"
|
/>
|
</el-form-item>
|
<el-form-item>
|
<el-button type="primary" style="margin-left: 30px" @click="searchClick">查询</el-button>
|
<el-button plain @click="reset">重置</el-button>
|
<el-button type="primary" plain @click="copyMenu">复制</el-button>
|
</el-form-item>
|
<el-form-item style="margin-left: 15px">
|
<el-button
|
type="primary"
|
@click="exportData"
|
>导出</el-button>
|
</el-form-item>
|
</el-form>
|
</div>
|
<!-- 表格数据 -->
|
<el-table v-loading="loading" :data="dataList" :border="true" @selection-change="handleSelectionChange">
|
<el-table-column type="selection" width="55" />
|
<el-table-column type="index" label="序号" width="80" align="center"></el-table-column>
|
<el-table-column label="名称" align="center">
|
<template #default="scope">
|
<span>{{scope.row.year}}年度{{scope.row.deptName}}相关方期望或要求识别表</span>
|
</template>
|
</el-table-column>
|
<el-table-column label="部门" prop="deptName" align="center" />
|
<el-table-column label="年份" prop="year" align="center" />
|
<el-table-column label="操作" align="center" class-name="small-padding fixed-width" width="160">
|
<template #default="scope">
|
<el-button link type="primary" @click="openDialog('review',scope.row)" >查看</el-button>
|
<el-button link type="primary" @click="openDialog('edit',scope.row)" v-hasPermi="['needIdentify:list:edit']">编辑</el-button>
|
<el-button link type="danger" @click="handleDelete(scope.row)" v-hasPermi="['needIdentify:list:del']">删除</el-button>
|
</template>
|
</el-table-column>
|
</el-table>
|
|
<div class="pag-container">
|
<el-pagination
|
v-model:current-page="data.queryParams.pageNum"
|
v-model:page-size="data.queryParams.pageSize"
|
:page-sizes="[10,15,20,25]"
|
layout="total, sizes, prev, pager, next, jumper"
|
:total="total"
|
@size-change="handleSizeChange"
|
@current-change="handleCurrentChange"
|
/>
|
</div>
|
<editDialog ref="noticeRef" @getList = "getList"></editDialog>
|
<el-dialog
|
v-model="copyVisible"
|
width="500px"
|
:before-close="handleClose"
|
:close-on-press-escape="false"
|
:close-on-click-modal="false"
|
>
|
<span v-if="isAdmin" style="display: block; margin-bottom: 8px">单位名称:</span>
|
<el-select
|
v-model="chooseCompanyId"
|
v-if="isAdmin"
|
placeholder="请选择单位"
|
filterable
|
clearable
|
style="width: 100%; margin-bottom: 15px"
|
>
|
<el-option
|
v-for="item in companyList"
|
:key="item.id"
|
:label="item.name"
|
:value="item.id"
|
>
|
</el-option>
|
</el-select>
|
<span style="display: block; margin-bottom: 8px">将以下年份数据</span>
|
<el-date-picker
|
v-model="queryParams.year"
|
type="year"
|
value-format="YYYY"
|
placeholder="请选择年份"
|
style="width: 100%; margin-bottom: 15px"
|
|
/>
|
<span style="display: block; margin-bottom: 8px">复制到:</span>
|
<el-date-picker
|
v-model="chooseYear"
|
type="year"
|
value-format="YYYY"
|
placeholder="请选择年份"
|
style="width: 100%; margin-bottom: 15px"
|
/>
|
|
<div class="dialog-footer" style="display: flex; justify-content: right">
|
<el-button @click="handleClose" size="default">取 消</el-button>
|
<el-button
|
type="primary"
|
@click="onSubmitCopy"
|
size="default"
|
v-preReClick
|
>确认</el-button
|
>
|
</div>
|
</el-dialog>
|
</div>
|
</template>
|
|
<script setup>
|
import {getCurrentInstance, onMounted, reactive, ref, toRefs} from "vue";
|
import editDialog from "./components/editDialog.vue"
|
import {ElMessage, ElMessageBox} from "element-plus";
|
import {getCompany} from "@/api/onlineEducation/company";
|
import Cookies from "js-cookie";
|
import {generateWordDocument} from "@/utils/exportWord";
|
import {delTable, getTable} from "@/api/qualityObjectives/table";
|
import {delNeedDiscren, getNeedDiscren, copyNeed} from "@/api/need/need";
|
const { proxy } = getCurrentInstance();
|
const loading = ref(false);
|
const noticeRef = ref();
|
const deptRef = ref()
|
const loadingCompany = ref(false)
|
const choosedData = ref([])
|
const data = reactive({
|
queryParams: {
|
pageNum: 1,
|
pageSize: 10,
|
companyId: null,
|
year: '',
|
type: ''
|
},
|
companyList: [],
|
isAdmin: false,
|
copyVisible: false,
|
chooseCompanyId: null,
|
chooseYear: null
|
});
|
const dataList = ref([]);
|
const total = ref(0);
|
|
const { queryParams, isAdmin, copyVisible, chooseCompanyId, chooseYear, companyList } = toRefs(data);
|
|
onMounted(() => {
|
const userInfo = JSON.parse(Cookies.get('userInfo'))
|
data.isAdmin = userInfo.userType === 0;
|
if(data.isAdmin){
|
data.queryParams.companyId = null
|
}else {
|
data.queryParams.companyId = userInfo.companyId
|
data.chooseCompanyId = userInfo.companyId
|
}
|
getNowYear()
|
getList();
|
if(data.isAdmin){
|
getCompanyList()
|
}
|
});
|
const getNowYear = () =>{
|
data.queryParams.year = new Date().getFullYear().toString()
|
}
|
const copyMenu = () => {
|
if (!data.queryParams.year) {
|
ElMessage.warning("请先选择要复制的年份");
|
return;
|
}
|
data.copyVisible = true;
|
};
|
|
const handleClose = () => {
|
data.chooseCompanyId = null
|
data.chooseYear = null
|
data.copyVisible = false
|
};
|
|
const onSubmitCopy = async () => {
|
if (data.isAdmin && !data.chooseCompanyId) {
|
ElMessage.warning("请先选择单位");
|
return;
|
}
|
if (!data.chooseYear) {
|
ElMessage.warning("请选择目标年份");
|
return;
|
}
|
ElMessageBox.confirm("该操作将覆盖目标年份的数据,是否继续?", "提示", {
|
confirmButtonText: "确定",
|
cancelButtonText: "取消",
|
type: "warning",
|
})
|
.then(async () => {
|
const p = {
|
companyId: data.chooseCompanyId,
|
sourceYear: data.queryParams.year,
|
targetYear: data.chooseYear
|
};
|
const r = await copyNeed(p);
|
if (r.code === 200) {
|
ElMessage.success(r.message);
|
await handleClose();
|
await getList();
|
} else {
|
ElMessage.warning(r.message);
|
}
|
})
|
.catch((err) => {});
|
};
|
|
const getList = async () => {
|
loading.value = true;
|
const res = await getNeedDiscren(data.queryParams);
|
if(res.code === 200){
|
dataList.value = res.data.list
|
total.value = res.data.total
|
}else{
|
ElMessage.warning(res.message)
|
}
|
loading.value = false;
|
|
}
|
|
const searchClick = () => {
|
getList();
|
}
|
|
const openDialog = (type, value) => {
|
noticeRef.value.openDialog(type, value,data.companyList);
|
}
|
|
const selectValue = (val) => {
|
data.companyList.forEach(item => {
|
if(item.name === val){
|
data.queryParams.companyId = item.id
|
}
|
})
|
}
|
|
const getCompanyList = async ()=>{
|
const queryParams = {
|
pageNum: 1,
|
pageSize: 999
|
}
|
const res = await getCompany(queryParams)
|
if (res.code == 200) {
|
data.companyList = res.data.list?res.data.list:[]
|
} else {
|
ElMessage.warning(res.message)
|
}
|
}
|
|
const handleSizeChange = (val) => {
|
data.queryParams.pageSize = val
|
getList()
|
}
|
const handleCurrentChange = (val) => {
|
data.queryParams.pageNum = val
|
getList()
|
}
|
|
/** 重置新增的表单以及其他数据 */
|
function reset() {
|
if(data.isAdmin){
|
data.queryParams = {
|
companyId: '',
|
pageNum: 1,
|
pageSize: 10,
|
year: '',
|
type: ''
|
}
|
choosedData.value = []
|
data.companyList = [];
|
getCompanyList()
|
}else {
|
data.queryParams = {
|
companyId: data.queryParams.companyId,
|
pageNum: 1,
|
pageSize: 10,
|
year: '',
|
type: ''
|
}
|
}
|
getNowYear()
|
getList();
|
|
}
|
const exportData = () => {
|
if(choosedData.value && choosedData.value.length === 0){
|
ElMessage.warning('请选择需要导出的数据')
|
}else {
|
startGeneration()
|
}
|
}
|
const templatePath = ref('/needIdentifyExample.docx')
|
const startGeneration = async () => {
|
const data = JSON.parse(JSON.stringify(choosedData.value))
|
data.forEach(item => {
|
item.fictionTime = item.fictionTime.substring(0,10)
|
item.tableData = item.expectContents.map((i,index) => {
|
return{
|
...i,
|
expectContentMesses: i.expectContentMesses.map((q,qindex) => {
|
return{
|
...q,
|
first: qindex == 0,
|
num: index+1,
|
stakeholder: i.stakeholder
|
}
|
})
|
}
|
})
|
console.log('xxx',item.tableData)
|
try {
|
generateWordDocument(templatePath.value, item, item.companyName + `_相关方期望和需求识别表.docx`);
|
} catch (error){
|
ElMessage({
|
type: 'warning',
|
message: '导出失败'
|
});
|
}
|
})
|
}
|
function idGroupToTree(data) {
|
const groups = data.reduce((map, item) => {
|
map.has(item.type) || map.set(item.type, []);
|
map.get(item.type).push(item);
|
return map;
|
}, new Map());
|
return Array.from(groups).map(([type, items]) => ({
|
type,
|
children: items
|
}));
|
}
|
const handleSelectionChange = (val) => {
|
choosedData.value = val
|
}
|
const handleDelete = (val) => {
|
ElMessageBox.confirm(
|
'确定删除此条数据?',
|
'提示',
|
{
|
confirmButtonText: '确定',
|
cancelButtonText: '取消',
|
type: 'warning',
|
})
|
.then( async() => {
|
const res = await delNeedDiscren(val.id);
|
if(res.code === 200){
|
ElMessage({
|
type: 'success',
|
message: '删除成功'
|
});
|
getList();
|
}else{
|
ElMessage.warning(res.message)
|
}
|
})
|
}
|
|
</script>
|
<style lang="scss">
|
.pag-container{
|
float: right;
|
margin-top: 10px;
|
}
|
</style>
|