| | |
| | | <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="deleteWorkTimePeriods">删除</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> |
| | |
| | | @selection-change="handleSelectionChange" |
| | | > |
| | | <el-table-column type="selection" width="100" /> |
| | | <el-table-column property="name" label="休息时间组名称"/> |
| | | <el-table-column property="content" label="关联休息时间"/> |
| | | <el-table-column property="name" label="工作时间组名称"/> |
| | | <el-table-column property="list" :formatter="toNames" label="关联工作时段"/> |
| | | <el-table-column property="info" 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="editRecord(scope.$index ,scope.row)">修改</el-button> |
| | | <el-button link type="danger" size="small" :icon="Delete" @click="deleteRecord(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> |
| | | </div> |
| | | </div> |
| | | <el-dialog v-model="dialogDetails" title="休息时间组"> |
| | | <el-dialog v-model="dialogDetails" title="工作时间组"> |
| | | <el-form :model="details" label-width="120px"> |
| | | <el-form-item label="时间组名称"> |
| | | <el-input |
| | |
| | | readonly |
| | | /> |
| | | </el-form-item> |
| | | <el-form-item label="关联休息时间" v-if="details.content.length>0"> |
| | | <el-form-item label="关联工作时段" v-if="details.list.length>0"> |
| | | <el-input |
| | | v-model="details.content" |
| | | v-model="details.list" |
| | | readonly |
| | | /> |
| | | </el-form-item> |
| | |
| | | </el-form-item> |
| | | </el-form> |
| | | </el-dialog> |
| | | <el-dialog v-model="dialogAddRecord" title="休息时间组编辑" @close="closeAdd" @open="openAdd"> |
| | | <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="name"> |
| | | <el-input |
| | |
| | | > |
| | | </el-input> |
| | | </el-form-item> |
| | | <el-form-item label="关联休息时间" prop="content"> |
| | | <el-select v-model="addRecord.content"> |
| | | <el-option label="周末休息" value="周末休息" /> |
| | | <el-option label="节假日休息" value="节假日休息" /> |
| | | <el-form-item label="关联工作时段" prop="list"> |
| | | <el-select v-model="addRecord.list" multiple> |
| | | <el-option v-for="(item,index) in workTimeList" :key="index" :label="item.name" :value="item.id" /> |
| | | </el-select> |
| | | </el-form-item> |
| | | <el-form-item label="描述信息" prop="info"> |
| | |
| | | </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> |
| | | |
| | |
| | | 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 { workingHoursSetApi } from '/@/api/basicDateManage/personShiftManage/workingHoursSet'; |
| | | import { workingHoursApi } from '/@/api/basicDateManage/personShiftManage/workingHours'; |
| | | |
| | | |
| | | |
| | | // 定义接口来定义对象的类型 |
| | | interface stateType { |
| | | tableData: Array<string>, |
| | | pageRecord: Array<string>, |
| | | workTimeList: Array<string>, |
| | | 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: { |
| | | name: string, |
| | | content: Array<any>, |
| | | list: Array<any>, |
| | | info: string |
| | | }, |
| | | details: { |
| | | name: string, |
| | | content: Array<any>, |
| | | list: Array<any>, |
| | | info: string |
| | | } |
| | | } |
| | |
| | | chosenIndex: null, |
| | | searchWord: '', |
| | | tableData: [], |
| | | pageRecord: [], |
| | | workTimeList: [], |
| | | multipleSelection: [], |
| | | dialogDetails: false, |
| | | dialogAddRecord: false, |
| | | deleteDialog: false, |
| | | deleteSetDialog: false, |
| | | addRecord: { |
| | | name: '', |
| | | content: [], |
| | | list: [], |
| | | info: '' |
| | | }, |
| | | details: { |
| | | name: '', |
| | | content: [], |
| | | list: [], |
| | | info: '' |
| | | }, |
| | | deleteId: null, |
| | |
| | | }) |
| | | interface User { |
| | | name: string, |
| | | content: [], |
| | | list: [], |
| | | info: string |
| | | } |
| | | const multipleTableRef = ref<InstanceType<typeof ElTable>>() |
| | |
| | | const addRef = ref<FormInstance>() |
| | | const addRules = reactive<FormRules>({ |
| | | name: [{required: true, message: '该内容不能为空', trigger: 'blur'}], |
| | | content: [{required: true, message: '该内容不能为空', trigger: 'blur'}] |
| | | list: [{required: true, message: '该内容不能为空', trigger: 'blur'}] |
| | | }) |
| | | |
| | | // 页面载入时执行方法 |
| | | onMounted(() => { |
| | | // getWorkTimePeriod() |
| | | getListByPage() |
| | | getWorkTimePeriod() |
| | | }) |
| | | |
| | | // 获取工作时段列表 |
| | | const getWorkTimePeriod = async () => { |
| | | let res = await workingHoursApi().getWorkTimePeriod({name: state.searchWord}); |
| | | // 分页获取工作时间组列表 |
| | | const getListByPage = async ()=>{ |
| | | const data = {pageSize: state.pageSize,pageIndex: state.pageIndex,searchParams:{name: state.searchWord}} |
| | | let res = await workingHoursSetApi().postWorkTimeGroupPage(data); |
| | | if (res.data.code === '200') { |
| | | state.pageRecord = res.data.data |
| | | state.tableData = res.data.data.map((item)=>{ |
| | | item.startHour = item.startHour==null?'00':(item.startHour.toString()[1]?item.startHour.toString():'0'+item.startHour.toString()) |
| | | item.startMin = item.startMin==null?'00':(item.startMin.toString()[1]?item.startMin.toString():'0'+item.startMin.toString()) |
| | | item.endHour = item.endHour==null?'00':(item.endHour.toString()[1]?item.endHour.toString():'0'+item.endHour.toString()) |
| | | item.endMin = item.endMin==null?'00':(item.endMin.toString()[1]?item.endMin.toString():'0'+item.endMin.toString()) |
| | | item.startTime = item.startHour + ':' + item.startMin |
| | | item.endTime = item.endHour + ':' + item.endMin |
| | | if(item.list == null){ |
| | | item.list = [] |
| | | }else{ |
| | | item.list= Array.from(item.list,({workTimePeriodId})=>workTimePeriodId) |
| | | } |
| | | return item |
| | | }) |
| | | state.totalSize = res.data.total |
| | | } else { |
| | | ElMessage({ |
| | | type: 'warning', |
| | |
| | | } |
| | | } |
| | | |
| | | // 分页获取工作时段列表 |
| | | const getListByPage = async ()=>{ |
| | | const data = {pageSize: state.pageSize,pageIndex: state.pageIndex,searchParams:{name: state.searchWord}} |
| | | let res = await workingHoursApi().postPeriodPage(data); |
| | | // 表格数据格式化 |
| | | const toNames =(row, column, cellValue, index) => { |
| | | if(row.list==[]){ |
| | | return [] |
| | | }else{ |
| | | const nameList = [] |
| | | for(let i=0;i<row.list.length;i++){ |
| | | for(let t=0;t<state.workTimeList.length;t++){ |
| | | if(row.list[i]==state.workTimeList[t].id){ |
| | | nameList.push(state.workTimeList[t].name) |
| | | } |
| | | } |
| | | } |
| | | return nameList.join() |
| | | } |
| | | } |
| | | |
| | | // 获取工作时段列表 |
| | | const getWorkTimePeriod = async () => { |
| | | let res = await workingHoursApi().getWorkTimePeriod(); |
| | | if (res.data.code === '200') { |
| | | state.tableData = res.data.data.map((item)=>{ |
| | | item.startHour = item.startHour==null?'00':(item.startHour.toString()[1]?item.startHour.toString():'0'+item.startHour.toString()) |
| | | item.startMin = item.startMin==null?'00':(item.startMin.toString()[1]?item.startMin.toString():'0'+item.startMin.toString()) |
| | | item.endHour = item.endHour==null?'00':(item.endHour.toString()[1]?item.endHour.toString():'0'+item.endHour.toString()) |
| | | item.endMin = item.endMin==null?'00':(item.endMin.toString()[1]?item.endMin.toString():'0'+item.endMin.toString()) |
| | | item.startTime = item.startHour + ':' + item.startMin |
| | | item.endTime = item.endHour + ':' + item.endMin |
| | | return item |
| | | }) |
| | | state.totalSize = res.data.total |
| | | state.workTimeList = res.data.data |
| | | console.log(state.workTimeList,'list') |
| | | } else { |
| | | ElMessage({ |
| | | type: 'warning', |
| | |
| | | getListByPage() |
| | | } |
| | | |
| | | // 添加工作时段 |
| | | const addWorkTimePeriod = async (data:any) => { |
| | | let res = await workingHoursApi().postWorkTimePeriod(data); |
| | | // 添加工作时段方法 |
| | | const addRecord = async (data:any) => { |
| | | let res = await workingHoursSetApi().addWorkTimeGroup(data); |
| | | if (res.data.code === '200') { |
| | | ElMessage({ |
| | | type: 'success', |
| | |
| | | } |
| | | }; |
| | | |
| | | // 修改工作时段 |
| | | const editWorkTimePeriod = async (data:any) => { |
| | | let res = await workingHoursApi().updateWorkTimePeriod(data); |
| | | // 修改工作时段方法 |
| | | const editRecord = async (data:any) => { |
| | | let res = await workingHoursSetApi().updateWorkTimeGroup(data); |
| | | if (res.data.code === '200') { |
| | | ElMessage({ |
| | | type: 'success', |
| | |
| | | } |
| | | } |
| | | |
| | | // 删除工作时段 |
| | | const deleteWorkTimePeriod = async (data:any) => { |
| | | let res = await workingHoursApi().deletWorkTimePeriod(data); |
| | | // 新增修改记录 |
| | | const confirmAddRecord = async (formEl: FormInstance | undefined) => { |
| | | if (!formEl) return |
| | | await formEl.validate(async (valid, fields) => { |
| | | if (valid) { |
| | | const data = { |
| | | name: state.addRecord.name, |
| | | info: state.addRecord.info, |
| | | workTimePeriodIds: state.addRecord.list |
| | | } |
| | | if (state.chosenIndex == null) { |
| | | await addRecord(data) |
| | | } else { |
| | | data.id = JSON.stringify(state.addRecord.id), |
| | | console.log(data,'修改参数') |
| | | await editRecord(data) |
| | | } |
| | | state.dialogAddRecord = false |
| | | } else { |
| | | console.log('error submit!', fields) |
| | | } |
| | | }) |
| | | |
| | | } |
| | | |
| | | // 删除工作时间组方法 |
| | | const deleteRecord = async (data:any) => { |
| | | let res = await workingHoursSetApi().deleteWorkTimeGroup(data); |
| | | if (res.data.code === '200') { |
| | | ElMessage({ |
| | | type: 'success', |
| | |
| | | } |
| | | } |
| | | |
| | | const deleteRecord = (row) => { |
| | | const deleteRecordBtn = (row) => { |
| | | state.deleteId = row.id |
| | | state.deleteDialog = true |
| | | } |
| | | |
| | | const conFirmDelete = () => { |
| | | deleteWorkTimePeriod({ id: state.deleteId }) |
| | | deleteRecord({ id: state.deleteId }) |
| | | state.deleteDialog = false |
| | | } |
| | | |
| | | // 批量删除 |
| | | const deleteWorkTimePeriods = async () => { |
| | | if(state.deleteArr.length>0){ |
| | | console.log(state.deleteArr) |
| | | let res = await workingHoursApi().deleteBatchWorkTimePeriod({ids: state.deleteArr}); |
| | | if (res.data.code === '200') { |
| | | ElMessage({ |
| | | type: 'success', |
| | | message: res.data.msg |
| | | }); |
| | | getListByPage() |
| | | } else { |
| | | ElMessage({ |
| | | type: 'warning', |
| | | message: res.data.msg |
| | | }); |
| | | } |
| | | }else{ |
| | | const deleteBatchBtn = async () => { |
| | | if (state.deleteArr.length > 0) { |
| | | state.deleteSetDialog = true |
| | | } else { |
| | | ElMessage({ |
| | | type: 'warning', |
| | | message: '请先选择要删除的记录' |
| | | }); |
| | | } |
| | | }; |
| | | |
| | | const conFirmDeleteBatch = async () => { |
| | | let res = await workingHoursSetApi().deletBatchWorkTimeGroup({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 viewRecord = (row) => { |
| | | state.details = row |
| | | state.details = JSON.parse(JSON.stringify(row)) |
| | | if(row.list==[]){ |
| | | state.details.list = [] |
| | | }else{ |
| | | state.details.list = [] |
| | | for(let i=0;i<row.list.length;i++){ |
| | | for(let t=0;t<state.workTimeList.length;t++){ |
| | | if(row.list[i]==state.workTimeList[t].id){ |
| | | state.details.list.push(state.workTimeList[t].name) |
| | | } |
| | | } |
| | | } |
| | | } |
| | | state.dialogDetails = true |
| | | } |
| | | |
| | |
| | | const reLoadData = async () =>{ |
| | | getListByPage() |
| | | } |
| | | const editRecord = (index, row) => { |
| | | // 点击修改 |
| | | const editRecordBtn = (index, row) => { |
| | | state.dialogAddRecord = true |
| | | state.chosenIndex = index |
| | | state.addRecord = JSON.parse(JSON.stringify(row)) |
| | | } |
| | | |
| | | // 新增修改记录 |
| | | const confirmAddRecord = async (formEl: FormInstance | undefined) => { |
| | | if (!formEl) return |
| | | await formEl.validate(async (valid, fields) => { |
| | | if (valid) { |
| | | const data = { |
| | | name: state.addRecord.name, |
| | | info: state.addRecord.info, |
| | | startHour: Number(state.addRecord.startTime.substring(0, 2)), |
| | | startMin: Number(state.addRecord.startTime.substring(3)), |
| | | endHour: Number(state.addRecord.endTime.substring(0, 2)), |
| | | endMin: Number(state.addRecord.endTime.substring(3)) |
| | | } |
| | | if (state.chosenIndex == null) { |
| | | // if (state.addRecord.startTime >= state.addRecord.endTime) { |
| | | // state.addRecord.endTime = '次日' + state.addRecord.endTime |
| | | // } |
| | | // state.tableData.unshift(data) |
| | | await addWorkTimePeriod(data) |
| | | } else { |
| | | // if (state.addRecord.startTime >= state.addRecord.endTime) { |
| | | // state.addRecord.endTime = '次日' + state.addRecord.endTime |
| | | // } |
| | | // state.tableData[state.chosenIndex] = state.addRecord |
| | | data.id = state.addRecord.id, |
| | | await editWorkTimePeriod(data) |
| | | } |
| | | state.dialogAddRecord = false |
| | | } else { |
| | | console.log('error submit!', fields) |
| | | } |
| | | }) |
| | | |
| | | } |
| | | const closeAdd = () => { |
| | | state.addRecord = {} |
| | |
| | | Delete, |
| | | Refresh, |
| | | Plus, |
| | | toNames, |
| | | toggleSelection, |
| | | handleSelectionChange, |
| | | deleteWorkTimePeriods, |
| | | searchRecord, |
| | | clearSearch, |
| | | viewRecord, |
| | | deleteRecord, |
| | | deleteRecordBtn, |
| | | conFirmDelete, |
| | | getWorkTimePeriod, |
| | | getListByPage, |
| | | getWorkTimePeriod, |
| | | reLoadData, |
| | | deleteWorkTimePeriod, |
| | | deleteRecord, |
| | | deleteBatchBtn, |
| | | conFirmDeleteBatch, |
| | | handleSizeChange, |
| | | handleCurrentChange, |
| | | confirmAddRecord, |
| | | closeAdd, |
| | | openAdd, |
| | | indexClear, |
| | | editRecord, |
| | | editRecordBtn, |
| | | ...toRefs(state) |
| | | }; |
| | | } |