<template>
|
<div class="home-container">
|
<div style="height: 100%">
|
<el-row class="homeCard">
|
<el-col :span="8">
|
<div class="grid-content topInfo">
|
<el-input v-model="searchWord" placeholder="时间策略名称"></el-input>
|
<el-button type="primary" @click="searchRecord">查询</el-button>
|
<el-button plain @click="clearSearch">重置</el-button>
|
</div>
|
</el-col>
|
</el-row>
|
<div class="homeCard">
|
<div class="main-card">
|
<el-row class="cardTop">
|
<el-col :span="12" class="mainCardBtn">
|
<el-button type="primary" :icon="Plus" size="default" @click="dialogAddRecord = true">新增</el-button>
|
<!-- <el-button type="warning" :icon="Edit" size="default" plain>修改</el-button>-->
|
<!-- <el-button type="danger" :icon="Delete" size="default" plain @click="deleteBatchBtn">删除</el-button>-->
|
</el-col>
|
<el-button type="primary" :icon="Refresh" size="default" @click="reLoadData()" />
|
</el-row>
|
<el-table ref="multipleTableRef" :data="tableData" style="width: 100%" height="calc(100% - 100px)" :header-cell-style="{ background: '#fafafa' }" @selection-change="handleSelectionChange">
|
<!-- <el-table-column type="selection" width="100" />-->
|
<el-table-column property="groupStrategyName" label="班组策略名称" />
|
<el-table-column property="timeStrategy" label="时间策略" width="180" :show-overflow-tooltip="true" />
|
<el-table-column property="cycleName" label="循环类型" :show-overflow-tooltip="true" />
|
<el-table-column property="groupNames" label="班组" />
|
<el-table-column property="cycleStartTime" label="排班开始时间" width="160" />
|
<el-table-column property="groupStrategyInfo" label="描述信息" />
|
<el-table-column fixed="right" label="操作" align="center" width="250">
|
<template #default="scope">
|
<el-button link type="primary" size="small" :icon="View" @click="viewRecord(scope.row)">查看</el-button>
|
<el-button link type="primary" size="small" :icon="Edit" @click="editRecordBtn(scope.$index, scope.row)">修改</el-button>
|
<el-button link type="danger" size="small" :icon="Delete" @click="deleteRecordBtn(scope.row)">删除</el-button>
|
</template>
|
</el-table-column>
|
</el-table>
|
<div class="pageBtn">
|
<el-pagination v-model:currentPage="pageIndex" v-model:page-size="pageSize" :page-sizes="[10, 15]" small="false" background layout="total, sizes, prev, pager, next, jumper" :total="totalSize" @size-change="handleSizeChange" @current-change="handleCurrentChange" />
|
</div>
|
</div>
|
</div>
|
</div>
|
<el-dialog v-model="dialogDetails" title="班组策略">
|
<el-form :model="details" label-width="120px">
|
<el-form-item label="策略名称">
|
<el-input v-model="details.groupStrategyName" readonly />
|
</el-form-item>
|
<el-form-item label="时间策略">
|
<el-input v-model="details.timeStrategy" readonly />
|
</el-form-item>
|
<el-form-item label="循环类型">
|
<el-input v-model="details.cycleName" readonly />
|
</el-form-item>
|
<el-form-item label="班组">
|
<el-input v-model="details.groupNames" type="textarea" readonly />
|
</el-form-item>
|
<el-form-item label="排班开始时间">
|
<el-input v-model="details.cycleStartTime" readonly />
|
</el-form-item>
|
<el-form-item label="描述信息" v-if="details.groupStrategyInfo">
|
<el-input v-model="details.groupStrategyInfo" type="textarea" readonly />
|
</el-form-item>
|
<el-form-item>
|
<el-button type="primary" @click="dialogDetails = false" size="default">确认</el-button>
|
</el-form-item>
|
</el-form>
|
</el-dialog>
|
<el-dialog v-model="dialogAddRecord" title="班组策略编辑" @close="closeAdd" @open="openAdd">
|
<el-form :model="addRecord" label-width="120px" ref="addRef" :rules="addRules">
|
<el-form-item label="策略名称" prop="groupStrategyName">
|
<el-input v-model="addRecord.groupStrategyName"> </el-input>
|
</el-form-item>
|
<el-form-item label="时间策略" prop="timeStrategyId">
|
<el-select v-model="addRecord.timeStrategyId">
|
<el-option v-for="(item, index) in timeList" :key="index" :label="item.name" :value="item.id" />
|
</el-select>
|
</el-form-item>
|
<el-form-item label="循环类型" prop="cycle">
|
<el-select v-model="addRecord.cycle">
|
<el-option v-for="(item, index) in cycleList" :key="index" :label="item.name" :value="item.value" />
|
</el-select>
|
</el-form-item>
|
<el-form-item label="班组选择" prop="groupIds">
|
<el-select v-model="addRecord.groupIds" multiple>
|
<el-option v-for="(item, index) in teamList" :key="index" :label="item.groupName" :value="item.id" />
|
</el-select>
|
</el-form-item>
|
<el-form-item label="排班开始时间" prop="cycleStartTime">
|
<el-date-picker v-model="addRecord.cycleStartTime" type="date" value-format="YYYY-MM-DD" />
|
</el-form-item>
|
<el-form-item label="描述信息" prop="groupStrategyInfo">
|
<el-input v-model="addRecord.groupStrategyInfo" type="textarea"> </el-input>
|
</el-form-item>
|
<el-form-item>
|
<el-button type="warning" @click="dialogAddRecord = false" size="default" plain>取消</el-button>
|
<el-button type="primary" @click="confirmAddRecord(addRef)" size="default">确认</el-button>
|
</el-form-item>
|
</el-form>
|
</el-dialog>
|
<el-dialog v-model="deleteDialog" title="提示" width="30%" center @close="indexClear">
|
<span>您确定要删除该条记录吗?</span>
|
<template #footer>
|
<span class="dialog-footer">
|
<el-button @click="deleteDialog = false" size="default">取消</el-button>
|
<el-button type="primary" @click="conFirmDelete" size="default">确认</el-button>
|
</span>
|
</template>
|
</el-dialog>
|
<el-dialog v-model="deleteSetDialog" title="提示" width="30%" center>
|
<span>您确定要删除这些记录吗?</span>
|
<template #footer>
|
<span class="dialog-footer">
|
<el-button @click="deleteSetDialog = false" size="default">取消</el-button>
|
<el-button type="primary" @click="conFirmDeleteBatch" size="default">确认</el-button>
|
</span>
|
</template>
|
</el-dialog>
|
</div>
|
</template>
|
|
<script lang="ts">
|
import { toRefs, reactive, ref, onMounted } from 'vue';
|
import { storeToRefs } from 'pinia';
|
import { initBackEndControlRoutes } from '/@/router/backEnd';
|
import { useUserInfo } from '/@/stores/userInfo';
|
import { Session } from '/@/utils/storage';
|
import { Edit, View, Plus, Delete, Refresh, Search, Download } from '@element-plus/icons-vue';
|
import { ElTable } from 'element-plus';
|
import { FormInstance, FormRules, ElMessage } from 'element-plus';
|
import { teamStrategyApi } from '/@/api/systemManage/basicDateManage/personShiftManage/teamStrategy';
|
import { timeStrategyApi } from '/@/api/systemManage/basicDateManage/personShiftManage/timeStrategy';
|
import { teamManageApi } from '/@/api/systemManage/basicDateManage/personShiftManage/teamManage';
|
|
// 定义接口来定义对象的类型
|
interface stateType {
|
tableData: Array<string>;
|
pageRecord: Array<string>;
|
timeList: Array<any>;
|
teamList: Array<any>;
|
cycleList: Array<any>;
|
multipleSelection: Array<any>;
|
deleteArr: Array<any>;
|
dialogDetails: boolean;
|
dialogAddRecord: boolean;
|
deleteDialog: boolean;
|
deleteSetDialog: boolean;
|
pageIndex: number;
|
pageSize: number;
|
chosenIndex: null | number;
|
deleteId: null | number;
|
searchWord: string;
|
totalSize: number;
|
addRecord: {
|
groupStrategyName: string;
|
timeStrategyId: number | null;
|
timeStrategy: string;
|
groupIds: Array<number>;
|
cycle: number | null;
|
cycleName: string;
|
cycleStartTime: string;
|
groupStrategyInfo: string;
|
groupStrategyId: number | null;
|
};
|
details: {
|
groupStrategyName: string;
|
timeStrategyId: number | null;
|
timeStrategy: string;
|
groups: Array<any>;
|
cycle: number | null;
|
cycleName: string;
|
cycleStartTime: string;
|
groupStrategyInfo: string;
|
};
|
}
|
|
export default {
|
name: 'teamStrategy',
|
components: {},
|
setup() {
|
const userInfo = useUserInfo();
|
const { userInfos } = storeToRefs(userInfo);
|
|
const state = reactive<stateType>({
|
pageIndex: 1,
|
pageSize: 10,
|
totalSize: 0,
|
chosenIndex: null,
|
searchWord: '',
|
tableData: [],
|
pageRecord: [],
|
timeList: [],
|
teamList: [],
|
cycleList: [
|
{
|
name: '周',
|
value: 3
|
},
|
{
|
name: '月',
|
value: 2
|
},
|
{
|
name: '年',
|
value: 1
|
}
|
],
|
multipleSelection: [],
|
dialogDetails: false,
|
dialogAddRecord: false,
|
deleteDialog: false,
|
deleteSetDialog: false,
|
addRecord: {
|
groupStrategyName: '',
|
timeStrategyId: null,
|
timeStrategy: '',
|
groupIds: [],
|
cycle: null,
|
cycleName: '',
|
cycleStartTime: '',
|
groupStrategyInfo: '',
|
groupStrategyId: null
|
},
|
details: {
|
groupStrategyName: '',
|
timeStrategyId: null,
|
timeStrategy: '',
|
groups: [],
|
cycle: null,
|
cycleName: '',
|
cycleStartTime: '',
|
groupStrategyInfo: ''
|
},
|
deleteId: null,
|
deleteArr: []
|
});
|
interface User {
|
groupStrategyName: string;
|
timeStrategyId: null | number;
|
timeStrategy: string;
|
groups: Array<any>;
|
cycle: null | number;
|
cycleName: string;
|
cycleStartTime: string;
|
groupStrategyInfo: string;
|
}
|
const multipleTableRef = ref<InstanceType<typeof ElTable>>();
|
const toggleSelection = (rows?: User[]) => {
|
if (rows) {
|
rows.forEach((row) => {
|
// TODO: improvement typing when refactor table
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
// @ts-expect-error
|
multipleTableRef.value!.toggleRowSelection(row, undefined);
|
});
|
} else {
|
multipleTableRef.value!.clearSelection();
|
}
|
};
|
|
// 多选
|
const handleSelectionChange = (val: User[]) => {
|
state.multipleSelection = JSON.parse(JSON.stringify(val));
|
state.deleteArr = state.multipleSelection.map((item) => {
|
item = item.id;
|
return item;
|
});
|
};
|
|
const addRef = ref<FormInstance>();
|
const addRules = reactive<FormRules>({
|
groupStrategyName: [{ required: true, message: '该内容不能为空', trigger: 'blur' }],
|
timeStrategyId: [{ required: true, message: '该内容不能为空', trigger: 'blur' }],
|
groupIds: [{ required: true, message: '该内容不能为空', trigger: 'blur' }],
|
cycle: [{ required: true, message: '该内容不能为空', trigger: 'blur' }],
|
cycleStartTime: [{ required: true, message: '该内容不能为空', trigger: 'blur' }]
|
});
|
|
// 页面载入时执行方法
|
onMounted(() => {
|
getListByPage();
|
getTimeList();
|
getTeamList();
|
});
|
|
// 分页获取班组策略列表
|
const getListByPage = async () => {
|
const data = { pageSize: state.pageSize, pageIndex: state.pageIndex, searchParams: { name: state.searchWord, containGroupEnable: true } };
|
let res = await teamStrategyApi().getRecordPage(data);
|
if (res.data.code === '200') {
|
state.pageRecord = res.data.data;
|
state.tableData = res.data.data.map((item) => {
|
item.cycleName = item.cycle == 1 ? '年' : item.cycle == 2 ? '月' : item.cycle == 3 ? '周' : '';
|
if (!item.groups || item.groups == null) {
|
item.groups = [];
|
} else {
|
item.groups = item.groups.map((i) => {
|
return Object.assign({}, { groupId: i.groupId, groupName: i.groupName });
|
});
|
item.groupIds = Array.from(item.groups, ({ groupId }) => groupId);
|
item.groupNames = Array.from(item.groups, ({ groupName }) => groupName);
|
}
|
return item;
|
});
|
state.tableData.map(async (item) => {
|
if (!item.timeStrategyId || item.timeStrategyId == null) {
|
item.timeStrategy = '';
|
} else {
|
let op = await timeStrategyApi().getRecordById({ id: item.timeStrategyId });
|
if (op.data.code && op.data.code === '200') {
|
if (op.data.data) {
|
item.timeStrategy = op.data.data.name;
|
} else {
|
item.timeStrategy = '';
|
}
|
} else {
|
ElMessage({
|
type: 'warning',
|
message: res.data.msg
|
});
|
}
|
}
|
return item;
|
});
|
console.log(state.tableData, 'state.tableData');
|
state.totalSize = res.data.total;
|
} else {
|
ElMessage({
|
type: 'warning',
|
message: res.data.msg
|
});
|
}
|
};
|
|
// 循环类型格式化
|
// const toNames =(row, column, cellValue, index) =>{
|
// return row.cycle == 1? '年':(row.type == 2? '月': '周')
|
// }
|
|
// 时间策略格式化
|
// const timeName = async (row, column, cellValue, index) =>{
|
// let res = await timeStrategyApi().getRecordById({id: row.timeStrategyId})
|
// if (res.data.code === '200') {
|
// return row.timeStrategyId = res.name
|
// } else {
|
// ElMessage({
|
// type: 'warning',
|
// message: res.data.msg
|
// });
|
// }
|
// }
|
|
// 获取时间策略列表
|
const getTimeList = async () => {
|
let res = await timeStrategyApi().getAllRecord();
|
if (res.data.code === '200') {
|
console.log(res.data.data, 'timestrategy');
|
state.timeList = res.data.data;
|
} else {
|
ElMessage({
|
type: 'warning',
|
message: res.data.msg
|
});
|
}
|
};
|
|
// 获取班组列表
|
const getTeamList = async () => {
|
let res = await teamManageApi().getRecord({ name: '' });
|
if (res.data.code === '200') {
|
state.teamList = res.data.data;
|
} else {
|
ElMessage({
|
type: 'warning',
|
message: res.data.msg
|
});
|
}
|
};
|
|
// 关键词查询记录
|
const searchRecord = async () => {
|
if (state.searchWord == '') {
|
ElMessage({
|
type: 'warning',
|
message: '请输入查询关键词'
|
});
|
} else {
|
getListByPage();
|
}
|
};
|
|
const clearSearch = async () => {
|
state.searchWord = '';
|
getListByPage();
|
};
|
|
// 添加班组策略方法
|
const addRecord = async (data: any) => {
|
let res = await teamStrategyApi().addRecord(data);
|
if (res.data.code === '200') {
|
ElMessage({
|
type: 'success',
|
message: '添加成功!'
|
});
|
getListByPage();
|
} else {
|
ElMessage({
|
type: 'warning',
|
message: res.data.msg
|
});
|
}
|
};
|
|
// 修改工作时段方法
|
const editRecord = async (data: any) => {
|
let res = await teamStrategyApi().updateRecord(data);
|
if (res.data.code === '200') {
|
ElMessage({
|
type: 'success',
|
message: '修改成功!'
|
});
|
getListByPage();
|
} else {
|
ElMessage({
|
type: 'warning',
|
message: res.data.msg
|
});
|
}
|
};
|
|
// 新增修改记录
|
const confirmAddRecord = async (formEl: FormInstance | undefined) => {
|
if (!formEl) return;
|
await formEl.validate(async (valid, fields) => {
|
if (valid) {
|
const data = {
|
groupStrategyName: state.addRecord.groupStrategyName,
|
groupStrategyInfo: state.addRecord.groupStrategyInfo,
|
groupStrategyCycleType: state.addRecord.cycle,
|
timeStrategyId: state.addRecord.timeStrategyId,
|
groupIds: state.addRecord.groupIds,
|
cycleStartTime: state.addRecord.cycleStartTime
|
};
|
if (state.chosenIndex == null) {
|
await addRecord(data);
|
} else {
|
data.groupStrategyId = JSON.stringify(state.addRecord.groupStrategyId);
|
await editRecord(data);
|
}
|
state.dialogAddRecord = false;
|
} else {
|
console.log('error submit!', fields);
|
}
|
});
|
};
|
|
// 删除班组策略方法
|
const deleteRecord = async (data: any) => {
|
let res = await teamStrategyApi().deleteRecord(data);
|
if (res.data.code === '200') {
|
ElMessage({
|
type: 'success',
|
message: '删除成功!'
|
});
|
getListByPage();
|
} else {
|
ElMessage({
|
type: 'warning',
|
message: res.data.msg
|
});
|
}
|
};
|
|
const deleteRecordBtn = (row) => {
|
state.deleteId = row.groupStrategyId;
|
state.deleteDialog = true;
|
};
|
|
const conFirmDelete = () => {
|
deleteRecord({ groupStrategyId: state.deleteId });
|
state.deleteDialog = false;
|
};
|
|
// 批量删除
|
// const deleteBatchBtn = async () => {
|
// ElMessage({
|
// type: 'warning',
|
// message: '抱歉,本页面暂不支持批量删除'
|
// });
|
// if (state.deleteArr.length > 0) {
|
// state.deleteSetDialog = true
|
// } else {
|
// ElMessage({
|
// type: 'warning',
|
// message: '请先选择要删除的记录'
|
// });
|
// }
|
// };
|
|
// const conFirmDeleteBatch = async () => {
|
// let res = await timeStrategyApi().deletBatchRecord({ids: state.deleteArr});
|
// if (res.data.code === '200') {
|
// state.deleteSetDialog = false
|
// ElMessage({
|
// type: 'success',
|
// message: res.data.msg
|
// });
|
// getListByPage()
|
// } else {
|
// ElMessage({
|
// type: 'warning',
|
// message: res.data.msg
|
// });
|
// state.deleteSetDialog = false
|
// }
|
// }
|
|
const handleSizeChange = (val: number) => {
|
state.pageSize = val;
|
getListByPage();
|
};
|
const handleCurrentChange = (val: number) => {
|
state.pageIndex = val;
|
getListByPage();
|
};
|
|
// 查看记录
|
const viewRecord = (row) => {
|
state.details = JSON.parse(JSON.stringify(row));
|
state.dialogDetails = true;
|
};
|
|
// 刷新
|
const reLoadData = async () => {
|
getListByPage();
|
};
|
// 点击修改
|
const editRecordBtn = (index, row) => {
|
state.dialogAddRecord = true;
|
state.chosenIndex = index;
|
state.addRecord = JSON.parse(JSON.stringify(row));
|
console.log(state.addRecord, 'state.addRecord');
|
};
|
const closeAdd = () => {
|
state.addRecord = {};
|
state.chosenIndex = null;
|
};
|
const openAdd = () => {
|
if (state.chosenIndex == null) {
|
state.addRecord.info = '';
|
}
|
};
|
const indexClear = () => {
|
state.deleteId = null;
|
};
|
|
// 折线图
|
const renderMenu = async (value: string) => {
|
Session.set('projectId', value);
|
userInfos.value.projectId = value;
|
await initBackEndControlRoutes();
|
};
|
return {
|
addRef,
|
addRules,
|
View,
|
Edit,
|
Delete,
|
Refresh,
|
Plus,
|
toggleSelection,
|
handleSelectionChange,
|
searchRecord,
|
clearSearch,
|
viewRecord,
|
deleteRecordBtn,
|
conFirmDelete,
|
getListByPage,
|
reLoadData,
|
deleteRecord,
|
handleSizeChange,
|
handleCurrentChange,
|
confirmAddRecord,
|
closeAdd,
|
openAdd,
|
indexClear,
|
editRecordBtn,
|
...toRefs(state)
|
};
|
}
|
};
|
</script>
|
|
<style scoped lang="scss">
|
$homeNavLengh: 8;
|
.home-container {
|
height: calc(100vh - 144px);
|
box-sizing: border-box;
|
overflow: hidden;
|
.homeCard {
|
width: 100%;
|
padding: 20px;
|
box-sizing: border-box;
|
background: #fff;
|
border-radius: 4px;
|
|
.main-card {
|
width: 100%;
|
height: 100%;
|
.cardTop {
|
display: flex;
|
align-items: center;
|
justify-content: space-between;
|
margin-bottom: 20px;
|
.mainCardBtn {
|
margin: 0;
|
}
|
}
|
.pageBtn {
|
height: 60px;
|
display: flex;
|
align-items: center;
|
justify-content: right;
|
|
.demo-pagination-block + .demo-pagination-block {
|
margin-top: 10px;
|
}
|
.demo-pagination-block .demonstration {
|
margin-bottom: 16px;
|
}
|
}
|
}
|
&:last-of-type {
|
height: calc(100% - 100px);
|
}
|
}
|
.el-row {
|
display: flex;
|
align-items: center;
|
margin-bottom: 20px;
|
&:last-child {
|
margin-bottom: 0;
|
}
|
.grid-content {
|
align-items: center;
|
min-height: 36px;
|
}
|
|
.topInfo {
|
display: flex;
|
align-items: center;
|
font-size: 16px;
|
font-weight: bold;
|
|
& > div {
|
white-space: nowrap;
|
margin-right: 20px;
|
}
|
}
|
}
|
}
|
.el-input {
|
width: 100% !important;
|
}
|
.el-date-editor::v-deep {
|
width: 100%;
|
}
|
.el-select {
|
width: 100%;
|
}
|
</style>
|