admin-vue3/src/views/hrm/attendrule/components/AttendShiftForm.vue

123 lines
3.9 KiB
Vue
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

<template>
<el-form
ref="formRef"
:model="formData"
:rules="formRules"
v-loading="formLoading"
label-width="0px"
:inline-message="true"
>
<el-table :data="formData" class="-mt-10px">
<el-table-column label="序号" type="index" width="100" />
<el-table-column label="班次名称" min-width="150">
<template #default="{ row, $index }">
<el-form-item :prop="`${$index}.name`" :rules="formRules.name" class="mb-0px!">
<el-input v-model="row.name" placeholder="请输入班次名称" />
</el-form-item>
</template>
</el-table-column>
<el-table-column label="班次类型1固定班次 2轮班制三班倒" min-width="150">
<template #default="{ row, $index }">
<el-form-item :prop="`${$index}.shiftType`" :rules="formRules.shiftType" class="mb-0px!">
<el-select v-model="row.shiftType" placeholder="请选择班次类型1固定班次 2轮班制三班倒">
<el-option
v-for="dict in getIntDictOptions(DICT_TYPE.HRM_SHIFT_TYPE)"
:key="dict.value"
:label="dict.label"
:value="dict.value"
/>
</el-select>
</el-form-item>
</template>
</el-table-column>
<el-table-column label="是否包含休息时段" min-width="150">
<template #default="{ row, $index }">
<el-form-item :prop="`${$index}.restIncluded`" :rules="formRules.restIncluded" class="mb-0px!">
<el-radio-group v-model="row.restIncluded">
<el-radio
v-for="dict in getBoolDictOptions(DICT_TYPE.INFRA_BOOLEAN_STRING)"
:key="dict.value"
:label="dict.value"
>
{{ dict.label }}
</el-radio>
</el-radio-group>
</el-form-item>
</template>
</el-table-column>
<el-table-column align="center" fixed="right" label="操作" width="60">
<template #default="{ $index }">
<el-button @click="handleDelete($index)" link>—</el-button>
</template>
</el-table-column>
</el-table>
</el-form>
<el-row justify="center" class="mt-3">
<el-button @click="handleAdd" round>+ 添加考勤班次</el-button>
</el-row>
</template>
<script setup lang="ts">
import { getIntDictOptions, getBoolDictOptions, DICT_TYPE } from '@/utils/dict'
import { AttendRuleApi } from '@/api/hrm/attendrule'
const props = defineProps<{
ruleId: undefined //
}>()
const formLoading = ref(false) // 表单的加载中
const formData = ref([])
const formRules = reactive({
ruleId: [{ required: true, message: '所属考勤规则不能为空', trigger: 'blur' }],
name: [{ required: true, message: '班次名称不能为空', trigger: 'blur' }]
})
const formRef = ref() // 表单 Ref
/** 监听主表的关联字段的变化,加载对应的子表数据 */
watch(
() => props.ruleId,
async (val) => {
// 1. 重置表单
formData.value = []
// 2. val 非空,则加载数据
if (!val) {
return;
}
try {
formLoading.value = true
formData.value = await AttendRuleApi.getAttendShiftListByRuleId(val)
} finally {
formLoading.value = false
}
},
{ immediate: true }
)
/** 新增按钮操作 */
const handleAdd = () => {
const row = {
id: undefined,
ruleId: undefined,
name: undefined,
shiftType: undefined,
restIncluded: undefined
}
row.ruleId = props.ruleId
formData.value.push(row)
}
/** 删除按钮操作 */
const handleDelete = (index) => {
formData.value.splice(index, 1)
}
/** 表单校验 */
const validate = () => {
return formRef.value.validate()
}
/** 表单值 */
const getData = () => {
return formData.value
}
defineExpose({ validate, getData })
</script>