提交 1ceb7419 authored 作者: lidongxu's avatar lidongxu

refactor(post): 重构给岗位分配考勤规则

同上
上级 b7b16f3f
<template> <template>
<div> <div>
<el-form <el-form :model="form"
:model="form"
inline> inline>
<el-form-item v-for="(obj, key) in form" <el-form-item v-for="(obj, key) in form"
:key="key" :key="key"
...@@ -16,14 +15,15 @@ ...@@ -16,14 +15,15 @@
</el-form-item> </el-form-item>
</el-form> </el-form>
<!-- 添加表格和其他内容 --> <!-- 添加表格和其他内容 -->
<el-table ref="myTable" <el-table ref="tableRef"
:data="tableData" :data="tableData"
v-loading="tableLoading" v-loading="tableLoading"
highlight-selection-row highlight-selection-row
@select="selectFn" :row-key="nodeKey"
@select-all="selectAllFn"> :select-on-indeterminate="false"
<el-table-column v-if="tableData.length > 0" @select="select"
type="selection" @select-all="selectAll">
<el-table-column type="selection"
width="50"> width="50">
</el-table-column> </el-table-column>
<el-table-column v-for="obj in tableHeaderList" <el-table-column v-for="obj in tableHeaderList"
...@@ -40,6 +40,7 @@ ...@@ -40,6 +40,7 @@
<script setup> <script setup>
import { debounce } from '@/utils'; import { debounce } from '@/utils';
const tableRef = ref(null) // 表格实例
const form = ref({}); // 表单对象 const form = ref({}); // 表单对象
const tableHeaderList = ref([]); const tableHeaderList = ref([]);
const tableData = ref([]); const tableData = ref([]);
...@@ -48,20 +49,56 @@ const isOnlyLoadData = ref(false); // 仅加载数据(因为标签和数据是 ...@@ -48,20 +49,56 @@ const isOnlyLoadData = ref(false); // 仅加载数据(因为标签和数据是
const props = defineProps({ const props = defineProps({
// 结构+数据 // 结构+数据
modelValue: { structData: {
type: Object, type: Object,
required: true required: true
}, },
// 选择的数据(要和 structData 里的 rows 数据一致)
modelValue: {
type: Array,
default: () => [],
required: true
},
// 查询参数 // 查询参数
queryParams: { queryParams: {
type: Object, type: Object,
required: true default: () => ({})
},
// 关键数据的属性
nodeKey: {
type: String,
default: 'id'
},
// 是否单选
isRadio: {
type: Boolean,
default: false
} }
}); });
const emits = defineEmits(['sel', 'update:queryParams']); const emits = defineEmits(['update:modelValue', 'sel', 'update:queryParams']);
watch(() => props.modelValue, (newValue) => { // 更新表格行选中
const updateCheck = (newValue) => {
nextTick(() => {
if (newValue.length > 0) {
// 遍历对比,选中/取消选中
props.structData.rows.forEach(o => {
// 参数 2:决定选中与否
tableRef.value.toggleRowSelection(o, newValue.some(item => item[props.nodeKey] === o[props.nodeKey]), false)
})
} else {
tableRef.value.clearSelection()
}
})
}
watch(() => props.modelValue, updateCheck, {
deep: true,
immediate: true
})
watch(() => props.structData, (newValue) => {
// 加载结构 // 加载结构
if (!isOnlyLoadData.value) { if (!isOnlyLoadData.value) {
// 准备表单结构 // 准备表单结构
...@@ -73,6 +110,7 @@ watch(() => props.modelValue, (newValue) => { ...@@ -73,6 +110,7 @@ watch(() => props.modelValue, (newValue) => {
// 加载数据 // 加载数据
tableData.value = newValue.rows; tableData.value = newValue.rows;
tableLoading.value = false; tableLoading.value = false;
updateCheck(props.modelValue)
}, { }, {
deep: true, deep: true,
immediate: true immediate: true
...@@ -96,19 +134,25 @@ const sel = debounce(() => { ...@@ -96,19 +134,25 @@ const sel = debounce(() => {
emits('sel'); emits('sel');
}); });
const selectAllFn = (rows) => { // 全选
if (!props.isCheckBox) { const selectAll = (selection) => {
table.clearSelection(); if (props.isRadio) {
emits('input', []); // 实现单选
emits('update:modelValue', selection.length > 0 ? [selection[selection.length - 1]] : []);
} else {
// 实现多选
emits('update:modelValue', selection);
} }
}; };
// 手动选中
const selectFn = (rows) => { const select = (rows) => {
if (!props.isCheckBox) { if (props.isRadio) {
table.clearSelection(); // 实现单选
rows.length > 0 && table.toggleRowSelection(rows[rows.length - 1]); emits('update:modelValue', rows.length > 0 ? [rows[rows.length - 1]] : []);
} else {
// 实现多选
emits('update:modelValue', rows);
} }
emits('input', rows.length > 0 ? [rows[rows.length - 1]] : []);
}; };
</script> </script>
......
...@@ -169,17 +169,21 @@ ...@@ -169,17 +169,21 @@
<template #reference> <template #reference>
<el-input-tag v-model="form.ruleList" <el-input-tag v-model="form.ruleList"
tag-type="primary" tag-type="primary"
tag-effect="plain" tag-effect="light"
placeholder="选择考勤规则"> placeholder="选择考勤规则"
clearable>
<template #tag="{ value }"> <template #tag="{ value }">
<div class="flex items-center">> <div class="flex items-center" @click.stop>
<span>{{ value }}</span> <span>{{ value.ruleName }}</span>
</div> </div>
</template> </template>
</el-input-tag> </el-input-tag>
</template> </template>
<open-dialog v-model="attStruData" <open-dialog v-model="form.ruleList"
:structData="attStruData"
v-model:queryParams="attQuery" v-model:queryParams="attQuery"
nodeKey="ruleId"
isRadio
@sel="getAttOpenDialog" /> @sel="getAttOpenDialog" />
</el-popover> </el-popover>
</el-form-item> </el-form-item>
...@@ -230,7 +234,9 @@ ...@@ -230,7 +234,9 @@
const attStruData = ref({}); // 考勤开窗结构+对象 const attStruData = ref({}); // 考勤开窗结构+对象
const data = reactive({ const data = reactive({
form: {}, form: {
},
queryParams: { queryParams: {
pageNum: 1, pageNum: 1,
pageSize: 10, pageSize: 10,
...@@ -263,6 +269,10 @@ ...@@ -263,6 +269,10 @@
attStruData.value = data attStruData.value = data
} }
getAttOpenDialog() getAttOpenDialog()
// 考勤规则改变
const ruleChange = (val) => {
console.log(val)
}
/** 取消按钮 */ /** 取消按钮 */
function cancel() { function cancel() {
...@@ -315,6 +325,9 @@ ...@@ -315,6 +325,9 @@
const postId = row.postId || ids.value; const postId = row.postId || ids.value;
getPost(postId).then(response => { getPost(postId).then(response => {
form.value = response.data; form.value = response.data;
form.value.ruleList = [attStruData.value.rows.find(o => {
return o.ruleId === response.data.ruleId
})]
open.value = true; open.value = true;
title.value = "修改岗位"; title.value = "修改岗位";
}); });
...@@ -323,6 +336,8 @@ ...@@ -323,6 +336,8 @@
/** 提交按钮 */ /** 提交按钮 */
function submitForm() { function submitForm() {
proxy.$refs["postRef"].validate(valid => { proxy.$refs["postRef"].validate(valid => {
form.value.ruleId = form.value.ruleList[0].ruleId
form.value.ruleName = form.value.ruleList[0].ruleName
if (valid) { if (valid) {
if (form.value.postId != undefined) { if (form.value.postId != undefined) {
updatePost(form.value).then(response => { updatePost(form.value).then(response => {
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论